Esempio n. 1
0
        private void toolStripLabel2_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult queren = MessageBox.Show("确认提交?", "系统提示", MessageBoxButtons.YesNo);
                if (queren == DialogResult.Yes)
                {
                    DataTable newDataTable = new DataTable();
                    newDataTable.Columns.Add("Id", typeof(int));
                    for (int i = 0; i < dataGridView1.Columns.Count; i++)
                    {
                        if (!dataGridView1.Columns[i].HeaderCell.Value.ToString().Equals("Id"))
                        {
                            newDataTable.Columns.Add(dataGridView1.Columns[i].HeaderCell.Value.ToString(), typeof(String));
                        }
                    }
                    for (int i = 0; i < dataGridView1.Rows.Count; i++)
                    {
                        if (dataGridView1.Rows[i].Cells[6].Value != null)
                        {
                            newDataTable.Rows.Add(dataGridView1.Rows[i].Cells[0].Value, dataGridView1.Rows[i].Cells[1].Value, dataGridView1.Rows[i].Cells[2].Value, dataGridView1.Rows[i].Cells[3].Value, dataGridView1.Rows[i].Cells[4].Value, dataGridView1.Rows[i].Cells[5].Value, dataGridView1.Rows[i].Cells[6].Value, dataGridView1.Rows[i].Cells[7].Value, dataGridView1.Rows[i].Cells[8].Value, dataGridView1.Rows[i].Cells[9].Value, dataGridView1.Rows[i].Cells[10].Value, dataGridView1.Rows[i].Cells[11].Value, dataGridView1.Rows[i].Cells[12].Value, dataGridView1.Rows[i].Cells[13].Value, dataGridView1.Rows[i].Cells[14].Value, dataGridView1.Rows[i].Cells[15].Value, "面料");
                        }
                    }

                    for (int i = 0; i < dataGridView2.Rows.Count; i++)
                    {
                        if (dataGridView2.Rows[i].Cells[6].Value != null)
                        {
                            newDataTable.Rows.Add(dataGridView2.Rows[i].Cells[0].Value, dataGridView2.Rows[i].Cells[1].Value, dataGridView2.Rows[i].Cells[2].Value, dataGridView2.Rows[i].Cells[3].Value, dataGridView2.Rows[i].Cells[4].Value, dataGridView2.Rows[i].Cells[5].Value, dataGridView2.Rows[i].Cells[6].Value, dataGridView2.Rows[i].Cells[7].Value, dataGridView2.Rows[i].Cells[8].Value, dataGridView2.Rows[i].Cells[9].Value, dataGridView2.Rows[i].Cells[10].Value, dataGridView2.Rows[i].Cells[11].Value, dataGridView2.Rows[i].Cells[12].Value, dataGridView2.Rows[i].Cells[13].Value, dataGridView2.Rows[i].Cells[14].Value, dataGridView2.Rows[i].Cells[15].Value, "辅料");
                        }
                    }
                    foreach (DataRow dr in newDataTable.Rows)
                    {
                        //if (dr[1] is DBNull || dr[1].Equals(string.Empty))
                        //{
                        dr[1] = comboBox1.Text;
                        //}
                        //if (dr[2] is DBNull || dr[2].Equals(string.Empty))
                        //{
                        dr[2] = txt_STYLE.Text;
                        //}
                        //if (dr[3] is DBNull || dr[3].Equals(string.Empty))
                        //{
                        dr[3] = txt_mfcf.Text;
                        //}
                        //if (dr[4] is DBNull || dr[4].Equals(string.Empty))
                        //{
                        dr[4] = dateTimePicker1.Text;
                        //}
                        //if (dr[5] is DBNull || dr[5].Equals(string.Empty))
                        //{
                        dr[5] = txt_JGC.Text;
                        //}
                    }
                    this.backgroundWorker1.RunWorkerAsync();                 // 运行 backgroundWorker 组件
                    JingDu form = new JingDu(this.backgroundWorker1, "提交中"); // 显示进度条窗体
                    form.ShowDialog(this);
                    form.Close();
                    cal.insertDanhao(newDataTable);
                    MessageBox.Show("提交成功!");
                    string comboboxtext = comboBox1.Text;
                    DanHaoFrm_Load(sender, e);
                    comboBox1.Text = comboboxtext;
                }
            }
            catch (Exception ex)
            {
                //throw ex;
                MessageBox.Show(ex.Message);
            }
        }