using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using ABC.KetNoi;
using System.IO;
using System.Windows.Forms;
using ABC.File;

namespace ABC.GiaoDich
{
  public  class NhapSi_Class
    {
         public static string _xmlfile;
        Class_KetNoi db = new Class_KetNoi();
        public static int _Ngay = 0;
        public void get_store(string sql)
        {
            #region           
            DuLieu.List_NhapSi_DaLuu = db.T_open_store(sql);
           // DuLieu.List_NhapSi_DaLuu.Tables[0].Columns.Add("Select", typeof(bool));

            #endregion
        }
        public DataSet get_dataset(string sql)
        {
            #region
            DuLieu.List_NhapSi_DaLuu = db.T_opendataset(sql);
           // DuLieu.List_NhapSi_DaLuu.Tables[0].Columns.Add("Select", typeof(bool));
            return DuLieu.List_NhapSi_DaLuu;
            
            #endregion
        }
        public DataSet get_store(string sql,string[]name,object[]value,int para)
        {
            #region
            //DuLieu.List_NhapSi_DaLuu.Clear();
            DuLieu.List_NhapSi_DaLuu = db.T_opendataset_store(sql, name, value, para);
            if (DuLieu.List_NhapSi_DaLuu != null)
                DuLieu.List_NhapSi_DaLuu.Tables[0].Columns.Add("Select", typeof(bool));
            return DuLieu.List_NhapSi_DaLuu;

            #endregion
        }
        public  void set(string sql)
        {
            db.T_exc(sql);
        }
        Xml_control _Xml_control = new Xml_control();

        public void load_null_data_chualuu()
        {
            try
            {
                string fileTemp = "";
                DataTable dt = Main_Form._dtCauHinh;
                if (dt.Rows.Count > 0)
                {
                    DataRow row = dt.Rows[0];
                    fileTemp = row["ThuMucFileTemp"].ToString();
                }
                string _xml_temp = Path.GetDirectoryName(Application.ExecutablePath) + @"\GiaoDich\TempData\TempData_NhapSi.xml";
                _xmlfile = fileTemp + @"\BanSi\" + Get_CauHinh.Ngay_DN + ".xml";
                if(!System.IO.Directory.Exists(fileTemp + @"\BanSi\"))
                    System.IO.Directory.CreateDirectory(fileTemp + @"\BanSi\");
                if (!System.IO.File.Exists(_xmlfile))
                {
                    System.IO.File.Copy(_xml_temp, _xmlfile);
                    DuLieu.List_NhapSi_ChuaLuu = _Xml_control.read_xml(_xmlfile);
                    if (DuLieu.List_NhapSi_ChuaLuu.Tables[0].Rows.Count > 0 && DuLieu.List_NhapSi_ChuaLuu.Tables[0].Rows[0]["ID"].ToString() == "Null")
                    {
                        DataRow dr = DuLieu.List_NhapSi_ChuaLuu.Tables[0].Rows[0];
                        _Xml_control.delete_xml_node(_xmlfile, dr["ID"].ToString());
                        DuLieu.List_NhapSi_ChuaLuu.Tables[0].Rows.Remove(dr);
                        DuLieu.List_NhapSi_ChuaLuu.Tables[0].AcceptChanges();
                    }
                    if (DuLieu.List_NhapSi_ChuaLuu.Tables[0].Columns.Count <= 12)
                    {
                        DuLieu.List_NhapSi_ChuaLuu.Tables[0].Columns.Add("tk_Can");
                        DuLieu.List_NhapSi_ChuaLuu.Tables[0].Columns.Add("tk_Login");
                    }
                    DuLieu.List_NhapSi_ChuaLuu.Tables[0].Columns.Add("Select", typeof(bool));
                }
                else
                {
                    DuLieu.List_NhapSi_ChuaLuu = _Xml_control.read_xml(_xmlfile);
                    if(DuLieu.List_NhapSi_ChuaLuu.Tables[0].Columns.Count<=12)
                    {
                        DuLieu.List_NhapSi_ChuaLuu.Tables[0].Columns.Add("tk_Can");
                        DuLieu.List_NhapSi_ChuaLuu.Tables[0].Columns.Add("tk_Login");
                    }
                    DuLieu.List_NhapSi_ChuaLuu.Tables[0].Columns.Add("Select", typeof(bool));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
           
        }
       
      
    }
}
