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

using ABC.KetNoi;
using System.Net;

namespace ABC.Toa
{
    class Toa_Class
    {
        #region XML
        public static int Ni,No;
        public static double lechtinh;
        public static double[] Gi;
        public static float[] Si;
        public static string ngay_in_toa,tenlai_in_toa;
        public static int Ngay_chon_toa;
        public static DataSet Table_Data, Table_Data_gop;
        public static DataTable Table_deleted;
        Xml_control _Xml_control = new Xml_control();

        public static int STT_Them;
        public static float SL_Them;
        public static double Gia_Them;
        public static string Nhom_ID_Them;
        public static string Nhom_Ten_Them;
       public static string _xmlfile;
        public void load_xml_Toa()
        {
            //Get_CauHinh.Ngay_DN
            
            string _xml_temp = Path.GetDirectoryName(Application.ExecutablePath) + @"\Toa\DataToa\Temp_Toa.xml";
            _xmlfile = Path.GetDirectoryName(Application.ExecutablePath) + @"\Toa\DataToa\" + Ngay_chon_toa + ".xml";
            if (!System.IO.File.Exists(_xmlfile))
            {
                System.IO.File.Copy(_xml_temp, _xmlfile);
                DuLieu.DS_Toa_XML = _Xml_control.read_xml(_xmlfile);
                if (DuLieu.DS_Toa_XML.Tables[0].Rows.Count > 0 && DuLieu.DS_Toa_XML.Tables[0].Rows[0]["ID"].ToString() == "Null")
                {
                    DataRow dr = DuLieu.DS_Toa_XML.Tables[0].Rows[0];
                    _Xml_control.delete_xml_node(_xmlfile, dr["ID"].ToString());
                    DuLieu.DS_Toa_XML.Tables[0].Rows.Remove(dr);
                    DuLieu.DS_Toa_XML.Tables[0].AcceptChanges();
                }
                DuLieu.DS_Toa_XML.Tables[0].Columns.Add("Select", typeof(bool));

            }
            else
            {
                DuLieu.DS_Toa_XML = _Xml_control.read_xml_toa(_xmlfile);
                DuLieu.DS_Toa_XML.Tables[0].Columns.Add("Select", typeof(bool));
            }

            //Connect_file.Dt_SuKien = ds.Tables[0];
        }
        public string load_xml_kytu()
        {
            string _xml_temp_kytu = Path.GetDirectoryName(Application.ExecutablePath) + @"\Toa\DataToa\KyTu.xml";
            DataSet ds = new DataSet();
            ds = _Xml_control.read_xml(_xml_temp_kytu);
            return  ds.Tables[0].Rows[0]["ID"].ToString();
        }
        #endregion

        #region dieu kien
        Class_KetNoi db = new Class_KetNoi();
        public void load_dieukien()
        {
           
        }
        #endregion

        #region tao mau nhap them
        public void taomau_them()
        {
            //if (DuLieu.T_DL_MoiNhap == null)
            //{
            //    #region
            //    string sql = "select * from T_TatCa_Ca_3 where 0=1";
            //    DuLieu.T_DL_MoiNhap = db.T_open(sql);
                
            //    DataColumn column = new DataColumn();
            //    column.DataType = System.Type.GetType("System.Int32");
            //    column.ColumnName = "STT_Them";
            //    column.AutoIncrement = true;
            //    column.AutoIncrementSeed = 1;
            //    column.AutoIncrementStep = 1;
            //    DuLieu.T_DL_MoiNhap.Tables[0].Columns.Add(column);
            //    DuLieu.T_DL_MoiNhap.Tables[0].Columns.Add("Select", typeof(bool));
                
            //    #endregion
            //}
            
        }
        #endregion

        #region ten may 
        public static string tenmaytinh;
        public void get_ip_may()
        {
            #region
            tenmaytinh =  System.Environment.MachineName;
            #endregion
        }
        #endregion

        #region chiphi
        public void fu_tinhchiphi()
        {
            #region

            
            DuLieu.TongchiPhi =  DuLieu.TKHIEN + DuLieu.TNUOC;
            DuLieu.ChiPhikhac =  DuLieu.TUNG + DuLieu.TXE + DuLieu.TKY + DuLieu.TTHEM1 + DuLieu.TTHEM2 + DuLieu.TTHEM3;
            DuLieu.PhaiTra = DuLieu._DST - DuLieu.T_HH - DuLieu.TongchiPhi - DuLieu.ChiPhikhac;
            if (DuLieu._SLT > 0)
            {
                DuLieu._GiaT_cophi = (DuLieu._DST - DuLieu.TongchiPhi - DuLieu.T_HH) / DuLieu._SLT;
            }
            else
            {
                DuLieu._GiaT_cophi = 0;
            }
            //tinh do chenh lech
            DuLieu._DSLech = DuLieu._DSG - DuLieu._DST;
            DuLieu._SLLech = DuLieu._SLG - DuLieu._SLT;
            DuLieu._GiaLech = DuLieu._GiaG - DuLieu._GiaT;

            #endregion
        }
        public void fu_xoa_nhatky()
        {
          
        }
        #endregion
    }
}
