Esempio n. 1
0
        private void button4_Click(object sender, EventArgs e)
        {
            //string sql = "select  Po_Itm, Xm_Id, Item_Desc, Shipping_Address, Qty_Shipping, Available_Qty_Serial_Id, Manufacturer_Id, Serial_Id, AQID, PurType_Id, Qty_Po, Planning_Shipping_Date, Already_Shipping_Id, Shipping_Date, Planning_Arrive_Date, Carrier_Id, Lading_Shipping_Id, BarCode_Print_Qty, ItemPrpty_Id_Before, ItemSerial_Id_Before, AQID_Before, CsvPo_Id, ItemPrpty_Id from [RMOTest].[dbo].[ShippingInfoConfirmBody1]";
            //DataTable dt = SqlHelper.ExecuteDataTable(sql);

            DataTable dt1 = GetDgvToTable(dataGridView1);

            for (int i = 0; i < dt1.Rows.Count; i++)
            {
                if (dt1.Rows[i][1].ToString() == "")
                {
                    dt1.Rows.RemoveAt(i);
                }
            }
            dt1.Columns.RemoveAt(0);


            for (int i = 0; i < dt1.Rows.Count; i++)
            {
                string[] test;
                test = dt1.Rows[i][11].ToString().Split('-');
                if (test[3] == "R")
                {
                    if (dt1.Rows[i][dt1.Columns.Count - 3].ToString() == "")
                    {
                        MessageBox.Show("设备型号 (改机前一次)未输入");
                        return;
                    }
                    if (dt1.Rows[i][dt1.Columns.Count - 2].ToString() == "")
                    {
                        MessageBox.Show("设备序列号 (改机前一次)未输入");
                        return;
                    }
                    if (dt1.Rows[i][dt1.Columns.Count - 1].ToString() == "")
                    {
                        MessageBox.Show("AQID (改机前一次)未输入");
                        return;
                    }
                }
                if (dt1.Rows[i][13].ToString() == "")
                {
                    MessageBox.Show("送货地址未输入");
                    return;
                }
            }



            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Title    = "请选择导出路径";
            sfd.Filter   = "csv文件|*.csv";
            sfd.FileName = textBox1.Text + DateTime.Now.ToString("-yyyyMMdd-HHmm");
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                string path = sfd.FileName;
                CsvHelper.SaveCSV(dt1, path);
            }
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            DataTable      dt     = new DataTable();
            OpenFileDialog myDLG1 = new OpenFileDialog();

            if (myDLG1.ShowDialog() == DialogResult.OK)
            {
                dt = CsvHelper.GetExcelData(myDLG1.FileName);
                int index = 0;
                //if (dt.Rows.Count - 1 != (Convert.ToInt32(textBox2.Text) * 2))
                //{
                //    MessageBox.Show("导入错误,可能是文件不匹配");
                //    return;
                //}
                if (dt == null || dt.Rows.Count < 1)
                {
                    MessageBox.Show("输入错误");
                    return;
                }
                int number = 0;

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i][2].ToString() == textBox1.Text)
                    {
                        string    sql2 = "select count(*) from ShippingInfoConfirmBody2 where CsvPo_Id = '" + textBox1.Text + "' and Serial_Id = '" + dt.Rows[i][1] + "' ";
                        DataTable dt2  = SqlHelper.ExecuteDataTable(sql2);
                        if (Convert.ToInt32(dt2.Rows[0][0].ToString()) > 1)
                        {
                            continue;
                        }
                        string    v     = (dt.Rows[i][4].ToString().Split(';')[0]).Split(':')[1];
                        string    model = dt.Rows[i][3].ToString();
                        string    sql1  = "select count(*) from ShippingInfoConfirmBody2 where CsvPo_Id = '" + textBox1.Text + "' and Item_Spec = '" + model + "' ";
                        DataTable dt1   = SqlHelper.ExecuteDataTable(sql1);
                        index = Convert.ToInt32(dt1.Rows[0][0].ToString());
                        int    item = index + 1;
                        string bar  = dt.Rows[i][1].ToString() + i;
                        string sql  = "insert into ShippingInfoConfirmBody2 (Company_Id, Shipping_Id, Itm_Full_Id, Scan_Ewm_Id, Itm2, AQID, APO, Serial_Id, Item_Spec, V, Bar_Code, CsvPo_Id, Print_Times) values ('" + DateTime.Now.ToString() + "', '" + SHIP + "asdsa', '" + DateTime.Now.ToString() + "','" + DateTime.Now.ToString() + "','" + item + "','" + dt.Rows[i][0] + "','" + dt.Rows[i][2] + "', '" + dt.Rows[i][1] + "', '" + model + "', '" + v + "', '" + dt.Rows[i][4].ToString() + "', '" + textBox1.Text + "', '" + 0 + "') ";

                        int rst = SqlHelper.ExecuteQuery(sql);
                        number++;
                    }
                }
                MessageBox.Show("导入" + number + "条记录");
            }
            load();
        }
Esempio n. 3
0
        private void button3_Click(object sender, EventArgs e)
        {
            DataTable      dt1    = new DataTable();
            OpenFileDialog myDLG1 = new OpenFileDialog();

            myDLG1.Title  = "请选择导入csv文件";
            myDLG1.Filter = "csv文件|*.csv";
            if (myDLG1.ShowDialog() == DialogResult.OK)
            {
                string fileName = myDLG1.FileName;
                try
                {
                    dt1 = CsvHelper.OpenCSV(fileName);
                }
                catch (InvalidOperationException ee)
                {
                    MessageBox.Show(ee.ToString());
                }

                for (int i = 2; i < dt1.Rows.Count; i++)
                {
                    //string[] str = list[i].Split('\t');
                }
                //if (textBox2.Text != dt1.Rows[2][11] || textBox1.Text != dt1.Rows[2][0])
                //{
                //    MessageBox.Show("型号不对");
                //    return;
                //}
                string sql1 = "";
                try
                {
                    sql1 = "select Count(*) from ShippingInfoConfirmBody1 where CsvPo_Id = '" + dt1.Rows[2][0].ToString() + "'";
                }
                catch
                {
                    MessageBox.Show("导入错误");
                    return;
                }
                DataTable d = SqlHelper.ExecuteDataTable(sql1);
                //int qty = Convert.ToInt32(textBox3.Text) - Convert.ToInt32(d.Rows[0][0].ToString());
                //if (qty <= 0)
                //{
                //    MessageBox.Show("数量不对啊");
                //    return;
                //}
                if (Convert.ToInt32(textBox3.Text) > dt1.Rows.Count - 2)
                {
                    //qty = dt1.rows.count - 2;
                    MessageBox.Show("数量不对啊");
                    return;
                }

                int index = Convert.ToInt32(d.Rows[0][0].ToString());
                int num   = Convert.ToInt32(textBox3.Text) - index;
                if (num < 1)
                {
                    MessageBox.Show("不允许导入");
                    return;
                }
                //int index = dataGridView1.Rows.Count  ;
                //if (index  >= Convert.ToInt32(textBox3.Text))
                //{
                //    MessageBox.Show("数量不对啊");
                //    return;
                //}

                //if (Convert.ToInt32(d.Rows[0][0].ToString()) != 0)
                //{
                //    string sql3 = "select MAX(Serial_Id) from ShippingInfoConfirmBody1";
                //    DataTable dt3 = SqlHelper.ExecuteDataTable(sql3);
                //    string[] ser = (dt1.Rows[0][0].ToString()).Split('-');
                //    string MAX = ser[ser.Length - 1 ];
                //    char[] c = MAX.ToCharArray();
                //    serial = Convert.ToInt32(c[0]) * 1000 + Convert.ToInt32(c[1]) * 100 + Convert.ToInt32(c[2]) * 100 + Convert.ToInt32(c[3]);
                //}

                string    serial = "select Count(*) from serial_item where serial = '" + textBox2.Text + "'";
                DataTable dt4    = SqlHelper.ExecuteDataTable(serial);
                int       ser    = Convert.ToInt32(dt4.Rows[0][0].ToString());

                string Ser = textBox2.Text;

                string    csv_ser = "Select Req_Csv_Id From PlanningOrderInfoInput Where Company_Id='CYGIA' And Input_Id='" + input + "'";
                DataTable dt_ser  = SqlHelper.ExecuteDataTable(csv_ser);
                string    req_csv = dt_ser.Rows[0][0].ToString();

                string    baseon   = "Select Serial_Id_Based_On From Csv Where Company_Id='CYGIA' And Csv_Id='" + req_csv + "'";
                DataTable dt_bas   = SqlHelper.ExecuteDataTable(baseon);
                string    Src_base = dt_bas.Rows[0][0].ToString();
                if (Src_base != "")
                {
                    string    project = "Select ProjectPrpty_Id  ProjectPrpty_Id From PlanningOrderInfoInputBody Where Company_Id='CYGIA' And Input_Id='" + input + "' And Itm_Full_Id='sadas'";
                    DataTable dt_pro  = SqlHelper.ExecuteDataTable(project);
                    Ser = req_csv + dt_pro.Rows[0][0].ToString();
                }

                int j;
                int ij;
                int jj = 0;
                for (int i = 2; i < dt1.Rows.Count; i++)
                {
                    //if (textBox2.Text != (dt1.Rows[i][11].ToString()) || textBox1.Text != dt1.Rows[i][0].ToString())
                    //{
                    //    return;
                    //}

                    if (jj == num)
                    {
                        return;
                    }
                    jj++;
                    if (textBox2.Text != dt1.Rows[i][11].ToString() || textBox1.Text != dt1.Rows[i][0].ToString())
                    {
                        continue;;
                    }
                    ij = i - 2;

                    this.dataGridView1.Rows.Add();



                    j = index + i - 2;
                    dataGridView1.Rows[j].Cells[0].Value = j + 1;

                    dataGridView1.Rows[j].Cells[1].Value  = dt1.Rows[i][0];
                    dataGridView1.Rows[j].Cells[2].Value  = dt1.Rows[i][1];
                    dataGridView1.Rows[j].Cells[3].Value  = dt1.Rows[i][2];
                    dataGridView1.Rows[j].Cells[4].Value  = dt1.Rows[i][3];
                    dataGridView1.Rows[j].Cells[5].Value  = dt1.Rows[i][4];
                    dataGridView1.Rows[j].Cells[6].Value  = dt1.Rows[i][5];
                    dataGridView1.Rows[j].Cells[7].Value  = dt1.Rows[i][6];
                    dataGridView1.Rows[j].Cells[8].Value  = dt1.Rows[i][7];
                    dataGridView1.Rows[j].Cells[9].Value  = "CYGIA";
                    dataGridView1.Rows[j].Cells[10].Value = Ser + "-" + String.Format("{0:0000}", ser + jj);
                    dataGridView1.Rows[j].Cells[11].Value = dt1.Rows[i][10];
                    dataGridView1.Rows[j].Cells[12].Value = dt1.Rows[i][11];
                    dataGridView1.Rows[j].Cells[13].Value = dt1.Rows[i][12];
                    dataGridView1.Rows[j].Cells[14].Value = dt1.Rows[i][13];
                    dataGridView1.Rows[j].Cells[15].Value = dt1.Rows[i][14];
                    dataGridView1.Rows[j].Cells[16].Value = dt1.Rows[i][15];
                    dataGridView1.Rows[j].Cells[17].Value = dt1.Rows[i][16];
                    dataGridView1.Rows[j].Cells[18].Value = dt1.Rows[i][17];
                    dataGridView1.Rows[j].Cells[19].Value = dt1.Rows[i][18];
                    dataGridView1.Rows[j].Cells[20].Value = dt1.Rows[i][19];
                    dataGridView1.Rows[j].Cells[21].Value = dt1.Rows[i][20];
                    dataGridView1.Rows[j].Cells[22].Value = dt1.Rows[i][21];
                    dataGridView1.Rows[j].Cells[23].Value = dt1.Rows[i][22];

                    if (i > 2)
                    {
                        dataGridView1.Rows[j].Cells[6].Value = "";
                        dataGridView1.Rows[j].Cells[7].Value = "";
                    }
                }
                //load();
            }
        }