Esempio n. 1
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog o = new OpenFileDialog();
                o.ShowDialog();

                string sFile = o.FileName;


                if (radio发票.Checked)
                {
                    gridControl回款.Visible = false;
                    gridControl发票.Visible = true;

                    TH.BaseClass.ClsExcel clsExcel = TH.BaseClass.ClsExcel.Instance();

                    string    sSQL = @"
select *
from [发票$]                    
";
                    DataTable dt   = clsExcel.ExcelToDT(sFile, sSQL, true);

                    for (int i = 0; i < dt.Columns.Count; i++)
                    {
                        dt.Columns[i].ColumnName = dt.Columns[i].ColumnName.ToString().Trim();
                    }
                    gridControl发票.DataSource = dt;

                    gridView发票.BestFitColumns();
                }
                if (radio回款.Checked)
                {
                    gridControl发票.Visible = false;
                    gridControl回款.Visible = true;

                    TH.BaseClass.ClsExcel clsExcel = TH.BaseClass.ClsExcel.Instance();

                    string    sSQL = @"
select *
from [回款$]                    
";
                    DataTable dt   = clsExcel.ExcelToDT(sFile, sSQL, true);

                    for (int i = 0; i < dt.Columns.Count; i++)
                    {
                        dt.Columns[i].ColumnName = dt.Columns[i].ColumnName.ToString().Trim();
                    }

                    gridControl回款.DataSource = dt;

                    gridView回款.BestFitColumns();
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show("加载数据失败:" + ee.Message);
            }
        }
Esempio n. 2
0
 public static ClsExcel Instance()
 {
     if (clsExcel == null)
     {
         lock (lockHelper)
         {
             if (clsExcel == null)
             {
                 clsExcel = new ClsExcel();
             }
         }
     }
     return(clsExcel);
 }
Esempio n. 3
0
        private void btnLoadExcel_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog o = new OpenFileDialog();
                o.ShowDialog();

                chkAll.Checked = false;

                string sFile = o.FileName;

                TH.BaseClass.ClsExcel clsExcel = TH.BaseClass.ClsExcel.Instance();

                string     sSQL = @"
select *
from [Sheet1$]                    
";
                DataTable  dt   = clsExcel.ExcelToDT(sFile, sSQL, true);
                DataColumn dc   = new DataColumn();
                dc.ColumnName   = "choose";
                dc.DataType     = System.Type.GetType("System.Boolean");
                dc.DefaultValue = false;
                dt.Columns.Add(dc);

                dc              = new DataColumn();
                dc.ColumnName   = "已使用";
                dc.DataType     = System.Type.GetType("System.Boolean");
                dc.DefaultValue = false;
                dt.Columns.Add(dc);

                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    dt.Columns[i].ColumnName = dt.Columns[i].ColumnName.ToString().Trim();
                }
                gridControl1.DataSource = dt;

                gridView1.BestFitColumns();

                b编辑 = false;
            }
            catch (Exception ee)
            {
                MessageBox.Show("加载数据失败:" + ee.Message);
            }
        }
Esempio n. 4
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    gridView1.FocusedRowHandle -= 1;
                    gridView1.FocusedRowHandle += 1;
                }
                catch { }
                string sSTCode = "";
                if (radioWC.Checked)
                {
                    sSTCode = "WC";
                }
                if (radioWP.Checked)
                {
                    sSTCode = "WP";
                }
                if (radioPP.Checked)
                {
                    sSTCode = "PP";
                }
                if (radioIC.Checked)
                {
                    sSTCode = "";
                }


                SaveFileDialog sF = new SaveFileDialog();
                sF.DefaultExt = "csv";
                if (radioWC.Checked)
                {
                    sF.FileName = "EPJWCDO_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".csv";
                }
                if (radioWP.Checked)
                {
                    sF.FileName = "EPJMPDO_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".csv";
                }
                if (radioIC.Checked)
                {
                    sF.FileName = "SEP3DO_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".csv";
                }
                if (radioPP.Checked)
                {
                    sF.FileName = "EPJPPDO_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".csv";
                }
                sF.Filter = "CSV文件(*.csv)|*.csv|All(*.*)|*.*";
                DialogResult dRes = sF.ShowDialog();
                if (DialogResult.OK != dRes)
                {
                    return;
                }
                string sPath = sF.FileName;

                TH.BaseClass.ClsExcel clsExcel = TH.BaseClass.ClsExcel.Instance();
                if (radioIC.Checked)
                {
                    DataTable dt = ((DataTable)gridControl2.DataSource).Copy();
                    dt.Columns.RemoveAt(6);
                    if (SaveCSV(dt, sPath, false))
                    {
                        MessageBox.Show("OK");
                    }
                }
                else
                {
                    DataTable dt = ((DataTable)gridControl1.DataSource).Copy();
                    dt.Columns.RemoveAt(21);
                    dt.Columns.RemoveAt(20);
                    dt.Columns.RemoveAt(19);
                    if (SaveCSV(dt, sPath, false))
                    {
                        MessageBox.Show("OK");
                    }
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show("Error:" + ee.Message);
            }
        }