using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

using DevExpress.XtraReports.UI;
using ABC.KetNoi;
using DevExpress.XtraSplashScreen;
using ABC.File;

namespace ABC.CongNo
{
    public partial class T_KhaiBaoCongNo_Ket2021 : DevExpress.XtraEditors.XtraForm
    {
        Class_KetNoi db = new Class_KetNoi();
        public T_KhaiBaoCongNo_Ket2021()
        {
            InitializeComponent();
            simpleButton1.Click += new EventHandler(simpleButton1_Click);
            simpleButton2.Click += new EventHandler(simpleButton2_Click);
            gv.CellValueChanged += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(gv_CellValueChanged);
            tailai();
        }

        void gv_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            DataRow dr = gv.GetDataRow(gv.FocusedRowHandle);
            dr[e.Column.FieldName] = e.Value;
            dt_main.Tables[0].AcceptChanges();
            gv.RefreshData();
            thongkenodau.Text = clum_tienno.SummaryText;
         
        }

        void simpleButton2_Click(object sender, EventArgs e)
        {
          
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        void simpleButton1_Click(object sender, EventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            DataView dtv = new DataView(dt_main.Tables[0]);
            dtv.RowFilter = "TienNo > 0";
            for (int i = 0; i < dtv.Count; i++)
            {


                DateTime select_date = Convert.ToDateTime(dtv[i]["NgayTinhNo"].ToString());
                int ng = Get_CauHinh.Ngay_DN;
                string sql = "Update_CongNoDau_Ket '" + dtv[i]["ID"].ToString() + "','" + ng + "','" + dtv[i]["TienNo"].ToString() + "'";
                db.T_exc(sql);


            }
            SplashScreenManager.CloseForm();
            this.DialogResult = DialogResult.OK;
            this.Close();
        }



        public DataSet dt_main;
    
        #region load_bandau

        public DataTable dt_kh;
        public void tailai()
        {
            string sql = "select * from CongNoDau_Ket";
            dt_main = db.T_opendataset(sql);
            DataTable dtCongNo_old = db.T_opendataset("sp_CongNoSP_Chot").Tables[0];
            DataView view = dtCongNo_old.Copy().DefaultView;
            for (int i = 0; i < dt_main.Tables[0].Rows.Count; i++)
            {
                view.RowFilter = "ID_KhachHang='" + dt_main.Tables[0].Rows[i]["ID"].ToString().Trim() + "'";
                if (view.ToTable().Rows.Count > 0)
                    dt_main.Tables[0].Rows[i]["TienNo"] = double.Parse(dt_main.Tables[0].Rows[i]["TienNo"].ToString()) + double.Parse(view.ToTable().Rows[0]["Ton_ket"].ToString());
            }
            dt_main.Tables[0].Columns.Add("Select", typeof(int));
            data();
        }
        public void data()
        {
            gc.DataSource = dt_main.Tables[0];
            thongkenodau.Text = clum_tienno.SummaryText;
        }
      
        #endregion
      
        private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            //string col = e.Column.FieldName.ToString();
            //DataRow dtv = gridView1.GetDataRow(gridView1.FocusedRowHandle);
            //string idcapnhat = dtv["ID"].ToString();
            //string tencapnhat = dtv["Ten"].ToString();
            //string KhachHang_INDEX = dtv["KhachHang_INDEX"].ToString();
            //    string text = e.Value.ToString();
            //    string TTF = String.Format("{0:N2}", text).Replace(",", "");
            //    T_Class_form_congno cn = new T_Class_form_congno();
            //    cn.updatecongnodau(T_Remember_sys.Ngay_DN, idcapnhat, tencapnhat, KhachHang_INDEX, text);
                
            //    initview();
            
          
        }

   
      
      
      
    }
}