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

using ABC.GiaoDich;
using ABC.Report;
using ABC.KetNoi;
using DevExpress.XtraGrid.Columns;
using DevExpress.Data.Filtering;
using ABC.BaoCao;
using DevExpress.XtraSplashScreen;
using DevExpress.XtraReports.UI;
using DevExpress.XtraGrid.Views.Base;
using ABC.File;

namespace ABC.CongNo
{
    public partial class frmCongNo_SoThuTien_KetChuyen : DevExpress.XtraEditors.XtraForm
    {
        
        public frmCongNo_SoThuTien_KetChuyen()
        {
            InitializeComponent();
            Get_CauHinh.NgayTinhNo = Get_CauHinh.Ngay_DN;
           
          
            dtKH = DuLieu.List_KhachHang.Tables[0];
           // Look_khachhang.Properties.DataSource = dtKH;
            
            gv_daluu.CellValueChanged+=new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(gv_daluu_CellValueChanged);
            gv_daluu.RowCellClick += new DevExpress.XtraGrid.Views.Grid.RowCellClickEventHandler(gv_daluu_RowCellClick);
          //  txtngay.Text = Get_CauHinh.ngay_text;

            this.Load += new EventHandler(CongNo_SoThuTien_Load);
            //khai bai report truoc
           
        }
        DataTable dtKH;
        void CongNo_SoThuTien_Load(object sender, EventArgs e)
        {
            
            tailai();

            
        }

        void gv_daluu_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
          
        }
#pragma warning disable CS0414 // The field 'frmCongNo_SoThuTien_KetChuyen.kh_ten_choos' is assigned but its value is never used
        string kh_ten_choos = "";
#pragma warning restore CS0414 // The field 'frmCongNo_SoThuTien_KetChuyen.kh_ten_choos' is assigned but its value is never used
#pragma warning disable CS0414 // The field 'frmCongNo_SoThuTien_KetChuyen.kh_id_choos' is assigned but its value is never used
        string kh_id_choos = "";        
#pragma warning restore CS0414 // The field 'frmCongNo_SoThuTien_KetChuyen.kh_id_choos' is assigned but its value is never used
#pragma warning disable CS0414 // The field 'frmCongNo_SoThuTien_KetChuyen.ngay' is assigned but its value is never used
        int ngay = 0;
#pragma warning restore CS0414 // The field 'frmCongNo_SoThuTien_KetChuyen.ngay' is assigned but its value is never used
        
      
      
      
        #region gv_daluu
        void gv_daluu_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
           

        }
        #endregion

        #region lệnh dùng chung
        public void excel()
        {
        }
       

        #region cap nhat tien tra
        TienTra _TienTra;
        public void btn_capnhat()
        {
            if (Pow.kiemtra("CongNo_SoThuTien", "Sua", Get_CauHinh.Dt_Login.Rows[0]["ID"].ToString().ToUpper()) == true)
            {
                _TienTra = new TienTra();
               
                _TienTra.FormClosed += new FormClosedEventHandler(_TienTra_FormClosed);
                _TienTra.TextChanged += new EventHandler(_TienTra_TextChanged);
                _TienTra.ShowDialog();
            }
            
        }
        string select_khachhang_name;
        
        void _TienTra_TextChanged(object sender, EventArgs e)
        {
            select_khachhang_name = _TienTra.select_khachhang_name;
           // msgbox.dialog_OK_info(select_khachhang_name);
           // gv_daluu.Columns["gridColumn1"].FilterInfo = new ColumnFilterInfo("[gridColumn1] LIKE '" + select_khachhang_name + "'");
           gv_daluu.ActiveFilterString = "[Tbl_KhachHang_Name] = '" + select_khachhang_name + "'";

      

            
        }

        void _TienTra_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (_TienTra.DialogResult == DialogResult.OK)
            {

                data();

               
            }
            gv_daluu.ClearColumnsFilter();
            //CriteriaOperator expr0 = null;
            //gv_daluu.ActiveFilterCriteria = GroupOperator.And(new CriteriaOperator[] { expr0 });
            //_TienTra = new TienTra();
        }
#endregion

        #region
        public void khaibao_nodau()
        {
            if (Pow.kiemtra("CongNo_SoThuTien", "Sua", Get_CauHinh.Dt_Login.Rows[0]["ID"].ToString().ToUpper()) == true)
            {
                #region
                _T_KhaiBaoCongNo = new T_KhaiBaoCongNo();
                _T_KhaiBaoCongNo.FormClosed += new FormClosedEventHandler(_T_KhaiBaoCongNo_FormClosed);
                _T_KhaiBaoCongNo.ShowDialog();
                #endregion
            }
            else
            {
                msgbox.dialog_OK_warning("Bạn không có quyền cập nhật");
            }
        }
        T_KhaiBaoCongNo _T_KhaiBaoCongNo;
        void _T_KhaiBaoCongNo_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (_T_KhaiBaoCongNo.DialogResult == DialogResult.OK)
            {
                tailai();
            }
        }
        #endregion

        public void sua()
        {
            if (Pow.kiemtra("CongNo_SoThuTien", "Sua", Get_CauHinh.Dt_Login.Rows[0]["ID"].ToString().ToUpper()) == true)
            {
               
            }
        }

        
      
        Class_KetNoi db = new Class_KetNoi();
        int ngaydetru;
        public void tailai()
        {
                Get_CauHinh.NgayTinhNo = Get_CauHinh.Ngay_DN;
                Get_CauHinh.NgayTinhNo_text = Get_CauHinh.ngay_text;
                ngaydetru = Get_CauHinh.Ngay_DN;
            DuLieu.CongNo_1Ngay = db.T_opendataset("sp_CongNo_ChotDuong");
            data();
        }
#pragma warning disable CS0169 // The field 'frmCongNo_SoThuTien_KetChuyen.dts' is never used
        DataSet dts;
#pragma warning restore CS0169 // The field 'frmCongNo_SoThuTien_KetChuyen.dts' is never used
        #endregion

        #region menu click
       

        void btn_ghichu_Click(object sender, EventArgs e)
        {
            xemghichu();
            data();
        }
        public void xemghichu()
        {
           
        }

      


        void btn_close_Click(object sender, EventArgs e)
        {
           // this.Close();
        }

        void btn_del_Click(object sender, EventArgs e)
        {
            btn_capnhat();
        }

       


        #endregion

        #region data       
#pragma warning disable CS0169 // The field 'frmCongNo_SoThuTien_KetChuyen.dtv_songay' is never used
        DataView dtv_songay;
#pragma warning restore CS0169 // The field 'frmCongNo_SoThuTien_KetChuyen.dtv_songay' is never used
        DataTable dtGrid;
        public void data()
        {
            gv_daluu.ClearColumnsFilter();
            dtGrid = DuLieu.CongNo_1Ngay.Tables[0];
            gc_daluu.DataSource = dtGrid;
                gv_daluu.ExpandAllGroups();
                gv_daluu.ExpandAllGroups();
                gv_daluu.RefreshData();

            //lbnocu.Text = cnocu.SummaryText + "____Nợ củ";
            //lbnomoi.Text = cnomoi.SummaryText + "____Nợ Mới";
            //lbtongno.Text = ctongno.SummaryText + "____Tổng nợ";
            //lbtongtra.Text = ctongtra.SummaryText + "____Tổng trả";
            //lbton.Text = cton.SummaryText + "____Tồn";
        }
        #endregion

        private void BaoCao_ToaSi_Load(object sender, EventArgs e)
        {
            
           // data();
        }

        private void gv_daluu_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
        {
            //try
            //{
            //    string _vuot = gv_daluu.GetRowCellValue(e.RowHandle, "VuotHanMuc").ToString().Trim();
            //    if (_vuot == "x")
            //    {
            //        e.Appearance.BackColor = Color.Red;
            //        e.Appearance.ForeColor = Color.White;
            //    }
            //}
            //catch (Exception)
            //{
                
                
            //}
        }

        private void gv_daluu_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            try
            {
                double _hanmuc = double.Parse(gv_daluu.GetRowCellValue(e.RowHandle, "HanMuc").ToString().Trim());
                double _ton = double.Parse(gv_daluu.GetRowCellValue(e.RowHandle, "Ton").ToString().Trim());
                if (_hanmuc < _ton&&_hanmuc>0)
                {
                    e.Appearance.BackColor = Color.LightGray;
                    e.Appearance.ForeColor = Color.Black;
                    //gv_daluu.SetRowCellValue(e.RowHandle, "VuotHanMuc", "x");
                }
            }
            catch (Exception)
            {
                
               
            }
          
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            DataView dv = dtGrid.Copy().DefaultView;
            dv.RowFilter = "VuotHanMuc='x'";
            frmVuot_DM_CongNo_SoThuTien frm = new frmVuot_DM_CongNo_SoThuTien(dv.ToTable());
            frm.ShowDialog();
            //ColumnView view = gv_daluu;
            //view.ActiveFilter.Clear();
            //ViewColumnFilterInfo viewFilterInfo = new ViewColumnFilterInfo(view.Columns["VuotHanMuc"],
            //  new ColumnFilterInfo("[VuotHanMuc] = 'x'", ""));
            //view.ActiveFilter.Add(viewFilterInfo);
        }

        private void simpleButton1_Click_1(object sender, EventArgs e)
        {
            //ColumnView view = gv_daluu;
            //view.ActiveFilter.Clear();
            //ViewColumnFilterInfo viewFilterInfo = new ViewColumnFilterInfo(view.Columns["VuotHanMuc"],
            //  new ColumnFilterInfo("[VuotHanMuc] == 'k'", ""));
            //view.ActiveFilter.Add(viewFilterInfo);
            
        }

       



     

    }
}
