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;




namespace ABC.CongNo
{
    public partial class T_KhaiBaoCongNo_BomM : DevExpress.XtraEditors.XtraForm
    {
        Class_KetNoi db = new Class_KetNoi();
        public int ngayxem;
        public T_KhaiBaoCongNo_BomM()
        {
            InitializeComponent();
            simpleButton1.Click += new EventHandler(simpleButton1_Click);
            simpleButton2.Click += new EventHandler(simpleButton2_Click);
            gv.CellValueChanged += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(gv_CellValueChanged);
            this.Load += new EventHandler(T_KhaiBaoCongNo_SotM_Load);
            link_xoa.Click += new EventHandler(link_xoa_Click);
        }

        void link_xoa_Click(object sender, EventArgs e)
        {
            DataRow dr = gv.GetDataRow(gv.FocusedRowHandle);
            if (msgbox.dialog_yes_no("Xóa bom mượn?") == DialogResult.Yes)
            {
                string sql = "Delete from Tbl_BomNo where NgayPhatSinhNo = '" + ngayxem + "' and NguonPhatSinh = 'Muon' and ID_KhachHang = '" + dr["ID_KhachHang"].ToString().ToUpper() + "'";
                db.T_exc(sql);
                //
                string ndCu = "";
                for (int j = 0; j < gv.Columns.Count; j++)
                {
                    ndCu += gv.Columns[j].FieldName + "(" + gv.GetRowCellValue(gv.FocusedRowHandle, gv.Columns[j].FieldName).ToString().Trim() + ") ";
                }
                DuLieu.LuuLuocSu(Main_Form._tk, this.Name, ndCu, "", "Xoá");
                tailai();
            }
        }

        void T_KhaiBaoCongNo_SotM_Load(object sender, EventArgs e)
        {
            tailai();
        }

        void gv_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            DataRow dr = gv.GetDataRow(gv.FocusedRowHandle);
            if (e.Column.FieldName == "TongMuon")
            {
                string sql = "Delete from Tbl_BomNo where NgayPhatSinhNo = '" + ngayxem + "' and NguonPhatSinh = 'Muon' and ID_KhachHang = '" + dr["ID_KhachHang"].ToString().ToUpper() + "'";
                db.T_exc(sql);
                string sql2 = "Tbl_BomNo_insert '" + dr["ID_KhachHang"].ToString().ToUpper() + "','" + Guid.NewGuid().ToString().ToUpper() + "','Muon'," + ngayxem + ",'" + e.Value + "'";
                db.T_exc(sql2);
                DuLieu.LuuLuocSu(Main_Form._tk, this.Name, dr["ID_KhachHang"].ToString().ToUpper(), "NgayPhatSinhNo=" + ngayxem + "-Tiền nợ=" + e.Value, "Công nợ đầu ID khách");
                tailai();
            }
         
        }

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

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



        public DataSet dt_main;
    
        #region load_bandau

        public DataTable dt_kh;
        public void tailai()
        {
            string sql = "sp_Bom_muon " + ngayxem;
            dt_main = db.T_opendataset(sql);
            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();
            
          
        }

   
      
      
      
    }
}