protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtPN.Text.Trim().Length == 0) { strErr += "PN不能为空!\\n"; } if (this.txtname.Text.Trim().Length == 0) { strErr += "name不能为空!\\n"; } if (this.txtjobnum.Text.Trim().Length == 0) { strErr += "jobnum不能为空!\\n"; } if (this.txtARef.Text.Trim().Length == 0) { strErr += "ARef不能为空!\\n"; } if (this.txtsize.Text.Trim().Length == 0) { strErr += "size不能为空!\\n"; } if (this.txtsm.Text.Trim().Length == 0) { strErr += "sm不能为空!\\n"; } if (this.txtBarcode.Text.Trim().Length == 0) { strErr += "Barcode不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } string PN = this.txtPN.Text; string name = this.txtname.Text; string jobnum = this.txtjobnum.Text; string ARef = this.txtARef.Text; string size = this.txtsize.Text; string sm = this.txtsm.Text; string Barcode = this.txtBarcode.Text; Maticsoft.Model.parts model = new Maticsoft.Model.parts(); model.PN = PN; model.name = name; model.jobnum = jobnum; model.ARef = ARef; model.size = size; model.sm = sm; model.Barcode = Barcode; Maticsoft.BLL.parts bll = new Maticsoft.BLL.parts(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }
private void send_bt_Click(object sender, EventArgs e) { Maticsoft.BLL.parts use = new Maticsoft.BLL.parts(); Maticsoft.Model.parts us = new parts() { PN = bom_no_tb.Text, //name = bomname_tb.Text, //jobnum = gdno_tb.Text, //ARef = scbh_tb.Text, //size= cicun_tb.Text, //sm= sandsm_tb.Text, Barcode = tm_tb.Text, }; use.Add(us); MessageBox.Show("保存成功"); foreach (Control Ctrol in this.Controls) { if (Ctrol is TextBox) { Ctrol.Text = ""; } } this.Close(); }
private void import_bt_Click(object sender, EventArgs e) { //string filepath = ""; //OpenFileDialog opf = new OpenFileDialog(); //if (opf.ShowDialog() == DialogResult.OK) //{ // filepath = opf.FileName; //} DataSet ds = new DataSet(); System.Data.DataTable dt = null; OpenFileDialog sflg = new OpenFileDialog(); sflg.Filter = "Excel(*.xls)|*.xls|Excel(*.xlsx)|*.xlsx"; if (sflg.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) { return; } FileStream fs = new FileStream(sflg.FileName, FileMode.Open, FileAccess.Read); NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(fs); int sheetCount = book.NumberOfSheets; for (int sheetIndex = 0; sheetIndex < sheetCount; sheetIndex++) { string st_name = book.GetSheetName(sheetIndex); NPOI.SS.UserModel.ISheet sheet = book.GetSheetAt(sheetIndex); if (sheet == null) { continue; } NPOI.SS.UserModel.IRow row = sheet.GetRow(0); if (row == null) { continue; } int firstCellNum = row.FirstCellNum; int lastCellNum = row.LastCellNum; if (firstCellNum == lastCellNum) { continue; } dt = new System.Data.DataTable(sheet.SheetName); dt.Columns.Add("PN", typeof(string)); //MessageBox.Show(dt.Columns["bushe_xianshu"].DataType.ToString()); //dt.Columns.Add("", typeof(int)); dt.Columns.Add("name", typeof(string)); dt.Columns.Add("jobnum", typeof(string)); dt.Columns.Add("ARef", typeof(string)); dt.Columns.Add("size", typeof(string)); dt.Columns.Add("sm", typeof(string)); dt.Columns.Add("Barcode", typeof(string)); lastCellNum = 7; for (int i = firstCellNum; i < lastCellNum; i++) { dt.Columns.Add(row.GetCell(i).StringCellValue, typeof(string)); } for (int i = 1; i <= sheet.LastRowNum; i++) { DataRow newRow = dt.Rows.Add(); for (int j = firstCellNum; j < lastCellNum; j++) { newRow[j] = sheet.GetRow(i).GetCell(j).StringCellValue; } } NPOI.SS.UserModel.IRow row0 = sheet.GetRow(0); ds.Tables.Add(dt); main_gc.DataSource = ds.Tables[0]; } for (int i = 0; i < gridView1.RowCount; i++) { string LJH = gridView1.GetRowCellValue(i, "PN").ToString(); string mc = gridView1.GetRowCellValue(i, "name").ToString(); string gdh = gridView1.GetRowCellValue(i, "jobnum").ToString(); string BH = gridView1.GetRowCellValue(i, "ARef").ToString(); string cc = gridView1.GetRowCellValue(i, "size").ToString(); string dsm = gridView1.GetRowCellValue(i, "sm").ToString(); string tm = gridView1.GetRowCellValue(i, "Barcode").ToString(); Maticsoft.BLL.parts use = new Maticsoft.BLL.parts(); Maticsoft.Model.parts us = new parts() { PN = LJH, //name = mc, //jobnum = gdh, //ARef = BH, //size = cc, //sm = dsm, Barcode = tm, }; use.Add(us); } DevExpress.XtraEditors.XtraMessageBox.Show("导入成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //MessageBox.Show("已成功导入"); Maticsoft.BLL.parts pr = new Maticsoft.BLL.parts(); DataSet ds2 = pr.GetAllList(); main_gc.DataSource = ds2.Tables[0]; }
private void button1_Click(object sender, EventArgs e) { try { if (textBox_ljh.Text == "") { MessageBox.Show("零件号为空"); return; } if (textBox_lxm.Text == "") { MessageBox.Show("序列号为空"); return; } if (textbox_gongdan.Text == "") { MessageBox.Show("工单号为空"); return; } if (comboBox1.SelectedIndex < 0) { MessageBox.Show("请选择正确的类型"); return; } Maticsoft.BLL.parts part_bll = new Maticsoft.BLL.parts(); List <Maticsoft.Model.parts> parts_list = part_bll.GetModelList(string.Format(" PN = '{0}'", textBox_ljh.Text)); if (parts_list.Count > 0) { Maticsoft.Model.parts parts_exmode = parts_list[0]; parts_exmode.Barcode = textBox_lxm.Text; parts_exmode.PN = textBox_ljh.Text; parts_exmode.remark = "管理"; parts_exmode.gongdan = textbox_gongdan.Text; parts_exmode.componentId = this.comp_list[comboBox1.SelectedIndex].componentId; if (part_bll.Update(parts_exmode)) { MessageBox.Show("更新成功"); } else { MessageBox.Show("更新失败"); } } else { Maticsoft.Model.parts parts_mode = new Maticsoft.Model.parts() { Barcode = textBox_lxm.Text, PN = textBox_ljh.Text, remark = "管理", gongdan = textbox_gongdan.Text, componentId = this.comp_list[comboBox1.SelectedIndex].componentId, }; if (part_bll.Add(parts_mode)) { MessageBox.Show("添加成功"); } else { MessageBox.Show("添加失败"); } } } catch (Exception err) { MessageBox.Show(err.Message); } finally { this.DialogResult = DialogResult.OK; } }