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.File;
using ABC.GiaoDich;
using ABC.KetNoi;
using DevExpress.XtraEditors;

namespace ABC.Toa
{
    public partial class Toa_QuanLyDuLieu :XtraUserControl
    {
        public Toa_QuanLyDuLieu()
        {
            InitializeComponent();
            event_click();
            txtngay.Text = Get_CauHinh.ngay_text;
            Look_tenlai.Properties.DataSource = DuLieu.List_NCC.Tables[0];
            lool_nhomLai.Properties.DataSource = DuLieu.List_Nhom_NCC.Tables[0];
            this.Load += new EventHandler(Toa_QuanLyDuLieu_Load);
        }

        void Toa_QuanLyDuLieu_Load(object sender, EventArgs e)
        {
            tailai();
        }
        #region lệnh dùng chung
        void _BaoCao_SoBaoCao_Si_Bien_Edit_FormClosed(object sender, FormClosedEventArgs e)
        {
            tailai();
        }
        public void chon()
        {
   
        }
        public void bochon()
        {
     
        }
        NhapSi_Class _NhapSi_Class = new NhapSi_Class();
        public void tailai()
        {
            #region
            string filter_string = "select * from View_DuLieu_TongHop_Si_Le_Them_group_theo_NCC_Ngay_extend where Date_Num_Final_UpDate >0 ";
            if (check_ngay.Checked == true)
            {
                int ng = (int)(Convert.ToDateTime(txtngay.Text) - new DateTime(1900, 1, 1)).TotalDays;
                filter_string += "AND Date_Num_Final_UpDate = " + ng + "";
                if (check_ten_thuonglai.Checked == true && Look_tenlai.EditValue != null)
                {
                    filter_string += " And ID_NCC = '" + Look_tenlai.EditValue.ToString().ToUpper() + "'";
                }

                if (check_nhom_lai.Checked == true && lool_nhomLai.EditValue != null && lool_nhomLai.EditValue != "")
                {
                    filter_string += " And NHOM_NCC_ID = '" + lool_nhomLai.EditValue.ToString().ToUpper() + "'";
                }
            }
            else
            {
                filter_string += "AND Date_Num_Final_UpDate = " + Get_CauHinh.Ngay_DN + "";
                if (check_ten_thuonglai.Checked == true && Look_tenlai.EditValue != null)
                {
                    filter_string += " And ID_NCC = '" + Look_tenlai.EditValue.ToString().ToUpper() + "'";
                }

                if (check_nhom_lai.Checked == true && lool_nhomLai.EditValue != null && lool_nhomLai.EditValue != "")
                {
                    filter_string += " And NHOM_NCC_ID = '" + lool_nhomLai.EditValue.ToString().ToUpper() + "'";
                }
            }
            DuLieu.QuanLyduLieu = _NhapSi_Class.get_dataset(filter_string);

            DuLieu.QuanLyduLieu.Tables[0].Columns.Add("Select", typeof(bool));
            data();
            #endregion
        }
        public void print()
        {
            if (Pow.kiemtra("Toa_QuanLyDuLieu", "Inan", Get_CauHinh.Dt_Login.Rows[0]["ID"].ToString().ToUpper()) == true)
            {
                #region
                #endregion
            }
        }
        public void print_bill()// in tong hop
        {
            if (Pow.kiemtra("Toa_QuanLyDuLieu", "Inan", Get_CauHinh.Dt_Login.Rows[0]["ID"].ToString().ToUpper()) == true)
            {
                #region
 
                #endregion
            }
        }
        #endregion

        #region menu click
        public void event_click()
        {
           // btn_close.Click += new EventHandler(btn_close_Click);
            btn_load.Click += new EventHandler(btn_load_Click);
           // btn_new.Click += new EventHandler(btn_new_Click);
        }
        Toa_New _Toa_New;
        void btn_new_Click(object sender, EventArgs e)
        {
            taotoa();
        }
        public void taotoa()
        {
            
        }
        Class_KetNoi db = new Class_KetNoi();
        void _Toa_New_FormClosed(object sender, FormClosedEventArgs e)
        {
         
                    _Toa_Class.fu_xoa_nhatky();

                    tailai();
            
        }
        Toa_Class _Toa_Class = new Toa_Class();
        void btn_sua_Click(object sender, EventArgs e)
        {
            print_bill();
        }



        void btn_in_Click(object sender, EventArgs e)
        {
            print();
        }

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

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

        void btn_none_Click(object sender, EventArgs e)
        {
            bochon();
        }

        void btn_all_Click(object sender, EventArgs e)
        {
            chon();
        }

      




        #endregion

        #region data
        public void data()
        {
            gc_daluu.DataSource = DuLieu.QuanLyduLieu.Tables[0];
            gv_daluu.ExpandAllGroups();
            gv_daluu.ExpandAllGroups();

            tksl1.Text = csl1.SummaryText + " (kg)";
            tksl2.Text = csl2.SummaryText + " (kg)";
            tksl3.Text = csl3.SummaryText + " (kg)";

            tkds1.Text = cds1.SummaryText + " (vnđ)";
            tkds2.Text = cds2.SummaryText + " (vnđ)";
            tkds3.Text = cds3.SummaryText + " (vnđ)";

            decimal sl1, sl2, sl3, ds1, ds2, ds3, gia1, gia2, gia3;
            try { sl1 = decimal.Parse(csl1.SummaryText); }
            catch { sl1 = 0; }
            try { sl2 = decimal.Parse(csl2.SummaryText); }
            catch { sl2 = 0; }
            try { sl3 = decimal.Parse(csl3.SummaryText); }
            catch { sl3 = 0; }
            //ds
            try { ds1 = decimal.Parse(cds1.SummaryText); }
            catch { ds1 = 0; }
            try { ds2 = decimal.Parse(cds2.SummaryText); }
            catch { ds2 = 0; }
            try { ds3 = decimal.Parse(cds3.SummaryText); }
            catch { ds3 = 0; }
            //gia 
            try { gia1 = ds1 / sl1; }
            catch { gia1 = 0; }
            try { gia2 = ds2 / sl2; }
            catch { gia2 = 0; }
            try { gia3 = ds3 / sl3; }
            catch { gia3 = 0; }

            tkgia1.Text = String.Format("{0:#,#}", gia1);
            tkgia2.Text = String.Format("{0:#,#}", gia2);
            tkgia3.Text = String.Format("{0:#,#}", gia3);

        }
        #endregion

    }
}
