private void CreateExcel(string path) { DataTable dt = new DataTable(); clsBuiness.CaiDan cd = new clsBuiness.CaiDan(); cd.STYLE = txt_Style.Text; cd.LABEL = txt_Label.Text; cd.DESC = this.txt_desc.Text; cd.FABRIC = this.txt_fabric.Text; cd.Jacket = this.txt_jacket.Text; cd.Pant = this.txt_pant.Text; cd.LABEL = this.txt_Label.Text; cd.shuoming = this.txt_shuoming.Text; cd.JiaGongchang = this.cb_jgc.Text; cd.MianLiao = this.txt_mianlioa.Text; cd.CaiDanHao = this.txt_CaidanNo.Text; cd.ZhiDanRiqi = this.txt_zhidan.Text; cd.JiaoHuoRiqi = this.txt_jiaohuo.Text; cd.RN_NO = this.txt_RN.Text; //dt.Columns.Add("id", typeof(int)); for (int i = 0; i < dataGridView1.Columns.Count; i++) { dt.Columns.Add(dataGridView1.Columns[i].HeaderCell.Value.ToString(), typeof(String)); } for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Cells[1].Value != null) { dt.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, dataGridView1.Rows[i].Cells[16].Value, dataGridView1.Rows[i].Cells[17].Value, dataGridView1.Rows[i].Cells[18].Value, dataGridView1.Rows[i].Cells[19].Value, dataGridView1.Rows[i].Cells[20].Value, dataGridView1.Rows[i].Cells[21].Value, dataGridView1.Rows[i].Cells[22].Value, dataGridView1.Rows[i].Cells[23].Value, dataGridView1.Rows[i].Cells[24].Value, dataGridView1.Rows[i].Cells[25].Value, dataGridView1.Rows[i].Cells[26].Value, dataGridView1.Rows[i].Cells[27].Value, dataGridView1.Rows[i].Cells[28].Value, dataGridView1.Rows[i].Cells[29].Value, dataGridView1.Rows[i].Cells[30].Value, dataGridView1.Rows[i].Cells[31].Value, dataGridView1.Rows[i].Cells[32].Value, dataGridView1.Rows[i].Cells[33].Value, dataGridView1.Rows[i].Cells[34].Value, dataGridView1.Rows[i].Cells[35].Value, dataGridView1.Rows[i].Cells[36].Value, dataGridView1.Rows[i].Cells[37].Value, dataGridView1.Rows[i].Cells[38].Value, dataGridView1.Rows[i].Cells[39].Value, dataGridView1.Rows[i].Cells[40].Value, dataGridView1.Rows[i].Cells[41].Value, dataGridView1.Rows[i].Cells[42].Value, dataGridView1.Rows[i].Cells[43].Value); } } gn2.CDEXCEL(dt, cd, path); foldPath = path + "\\裁单表-" + cd.CaiDanHao + ".xls"; }
private void CaiDan_Load(object sender, EventArgs e) { this.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.None; try { DataTable dt = new DataTable(); dt.Columns.Add("Id", typeof(int)); dt.Columns.Add("面料", typeof(string)); dt.Columns.Add("款式", typeof(string)); dt.Columns["款式"].ReadOnly = true; dt.Columns.Add("货号", typeof(string)); dt.Columns.Add("颜色", typeof(string)); dt.Columns.Add("颜色编号", typeof(string)); dt.Columns.Add("裤子", typeof(string)); dt.Columns.Add("28", typeof(string)); dt.Columns.Add("30", typeof(string)); dt.Columns.Add("32", typeof(string)); dt.Columns.Add("34", typeof(string)); dt.Columns.Add("36", typeof(string)); dt.Columns.Add("39", typeof(string)); dt.Columns.Add("41", typeof(string)); dt.Columns.Add("43", typeof(string)); dt.Columns.Add("46", typeof(string)); dt.Columns.Add("48", typeof(string)); dt.Columns.Add("50", typeof(string)); dt.Columns.Add("52", typeof(string)); dt.Columns.Add("54", typeof(string)); dt.Columns.Add("56", typeof(string)); dt.Columns.Add("58", typeof(string)); dt.Columns.Add(" 30", typeof(string)); dt.Columns.Add(" 32", typeof(string)); dt.Columns.Add(" 34", typeof(string)); dt.Columns.Add(" 36", typeof(string)); dt.Columns.Add(" 39", typeof(string)); dt.Columns.Add(" 41", typeof(string)); dt.Columns.Add(" 43", typeof(string)); dt.Columns.Add(" 46", typeof(string)); dt.Columns.Add(" 48", typeof(string)); dt.Columns.Add(" 50", typeof(string)); dt.Columns.Add(" 52", typeof(string)); dt.Columns.Add(" 54", typeof(string)); dt.Columns.Add(" 56", typeof(string)); dt.Columns.Add(" 58", typeof(string)); dt.Columns.Add("28 ", typeof(string)); dt.Columns.Add("30 ", typeof(string)); dt.Columns.Add("32 ", typeof(string)); dt.Columns.Add("34 ", typeof(string)); dt.Columns.Add("36 ", typeof(string)); dt.Columns.Add("39 ", typeof(string)); dt.Columns.Add("41 ", typeof(string)); dt.Columns.Add("Sub Total: ", typeof(string)); dataGridView1.DataSource = dt; dataGridView1.Columns["Id"].Visible = false; dataGridView1.Columns["面料"].Width = 3; DataGridViewHelper rowMergeView = new DataGridViewHelper(dataGridView1); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(1, 1, "LOT#")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(2, 1, "STYLE")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(3, 1, "ART")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(4, 1, "COLOR")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(5, 1, "COLOR#")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(6, 1, "上衣")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(7, 1, "34R")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(8, 1, "36R")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(9, 1, "38R")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(10, 1, "40R")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(11, 1, "42R")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(12, 1, "44R")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(13, 1, "46R")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(14, 1, "48R")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(15, 1, "50R")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(16, 1, "52R")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(17, 1, "54R")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(18, 1, "56R")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(19, 1, "58R")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(20, 1, "60R")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(21, 1, "62R")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(22, 1, "36L")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(23, 1, "38L")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(24, 1, "40L")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(25, 1, "42L")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(26, 1, "44L")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(27, 1, "46L")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(28, 1, "48L")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(29, 1, "50L")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(30, 1, "52L")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(31, 1, "54L")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(32, 1, "56L")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(33, 1, "58L")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(34, 1, "60L")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(35, 1, "62L")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(36, 1, "34S")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(37, 1, "36S")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(38, 1, "38S")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(39, 1, "40S")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(40, 1, "42S")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(41, 1, "44S")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(42, 1, "46S")); rowMergeView.Headers.Add(new DataGridViewHelper.TopHeader(43, 1, "订单合计")); dataGridView1.CellValueChanged -= dataGridView1_CellValueChanged; txt_Style.Text = StyleId; txt_Label.Text = chima; txt_CaidanNo.SelectedIndexChanged -= txt_CaidanNo_SelectedIndexChanged; this.txt_desc.Text = cd[0].DESC.ToString(); this.txt_fabric.Text = cd[0].FABRIC.ToString(); this.txt_jacket.Text = cd[0].Jacket.ToString(); this.txt_pant.Text = cd[0].Pant.ToString(); this.txt_shuoming.Text = cd[0].shuoming.ToString(); dataGridView1.ColumnHeadersHeight = 35; //this.dataGridView1.Width = //this.dataGridView1.Columns[0].HeaderCell.Size.Width * 43; //this.dataGridView1.DataSource = dt; //int width = this.dataGridView1.Width; //int avgWidth = width / dt.Columns.Count;//求出每一列的header宽度 //for (int i = 0; i < this.dataGridView1.Columns.Count; i++) //{ // this.dataGridView1.Columns[i].Width = avgWidth;//设置每一列的宽度 //} txt_CaidanNo.SelectedIndexChanged += txt_CaidanNo_SelectedIndexChanged; cb_jgc.DataSource = jgc; cb_jgc.DisplayMember = "Name"; cb_jgc.ValueMember = "id"; txt_zhidan.Text = DateTime.Now.ToLongDateString().ToString(); List <clsBuiness.CaiDan> caidan = gn2.selectCaiDan("").GroupBy(g => g.CaiDanHao).Select(s => s.First()).ToList <clsBuiness.CaiDan>(); clsBuiness.CaiDan c = new clsBuiness.CaiDan() { CaiDanHao = " " }; caidan.Add(c); txt_CaidanNo.DataSource = caidan; txt_CaidanNo.DisplayMember = "CaiDanHao"; txt_CaidanNo.ValueMember = "id"; if (txt_CaidanNo.FindString(" ") >= 0) { txt_CaidanNo.SelectedIndex = txt_CaidanNo.FindString(" "); } dataGridView1.CellValueChanged += dataGridView1_CellValueChanged; } catch (Exception ex) { //throw ex; MessageBox.Show(ex.Message); } resizedava_cloumn(dataGridView1); //设置Dave 宽度 resizedava_row(dataGridView1); }