private void btnSelect_Click(object sender, EventArgs e) { string paramName = this.txtName.Text.Trim(); DataTable myDt = new DataTable(); myDt = myBUPruduct.GetProductInfoByName(paramName, string.Empty); this.gdCItem.DataSource = myDt; }
private void btnSearch_Click(object sender, EventArgs e) { string paramProductName = this.txtBoxProductName.Text.ToString(); string paramProductCode = this.txtBoxProductCode.Text.ToString(); DataTable dt = new DataTable(); BUProductList myBUProductList = new BUProductList(); dt = myBUProductList.GetProductInfoByName(paramProductName, paramProductCode); if (dt.Rows.Count > 0) { this.gdcInfo.DataSource = dt; } else { MessageBox.Show("查无记录"); } }
private void btnBatchAdd_Click(object sender, EventArgs e) { string paramProductName = string.Empty; string paramProductCode = string.Empty; if (comBProductClass.Text.Length == 0) { MessageBox.Show("产品类别不能为空!"); return; } OpenFileDialog theDlg = new OpenFileDialog(); theDlg.Title = "请选择文件"; theDlg.Filter = "数据(*.xlsx)|*.xlsx|数据(*.xls)|*.xls"; theDlg.DefaultExt = ".xlsx"; if (theDlg.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } string theFile = theDlg.FileName; string strCom = string.Empty; WaitDialogForm wdf = null; List <string> thelstCom = new List <string>(); string strError = string.Empty; string IndexCount = "0"; try { wdf = new WaitDialogForm("正在导入数据,请稍后....", "温馨提示"); DataTable dtData = null; if (Environment.Is64BitOperatingSystem) { dtData = CreateXmlForData.ExecleToDataSet(theFile, 1).Copy(); } else { dtData = KSRCommonUtils.GetExcelData(theFile, "Sheet1").Tables[0]; } if (dtData.Rows.Count > 0) { IndexCount = "0"; wdf.Caption = "共" + dtData.Rows.Count.ToString() + "条数据,正在导入第" + IndexCount + "条数据,请稍后...."; DataTable dtTemp = myBUProductListAdd.GetProductInfoByName(string.Empty, string.Empty); for (int i = 0; i < dtData.Rows.Count; i++) { if (!myBUProductListAdd.IsExistsProduct(dtData.Rows[i][0].ToString())) { dtTemp.Clear(); DataRow dr = dtTemp.NewRow(); IndexCount = (i + 1).ToString(); wdf.Caption = "共" + dtData.Rows.Count.ToString() + "条数据,正在导入第" + IndexCount + "条数据,请稍后...."; try { int ResultRow = 0; dr["product_id"] = "'" + dtData.Rows[i][0].ToString() + "'"; dr["product_name"] = "'" + dtData.Rows[i][1].ToString() + "'"; dr["product_spec"] = "'" + dtData.Rows[i][2].ToString() + "'"; BUProductClass bUProductClass = new BUProductClass(); dr["product_class_id"] = bUProductClass.GetProductClassByName(dtData.Rows[i][3].ToString()).Rows[0]["product_class_id"].ToString();; BUProductUnit bUBUProductUnit = new BUProductUnit(); dr["product_unit_id"] = bUBUProductUnit.GetUnitInfo(dtData.Rows[i][4].ToString()).Rows[0]["product_unit_id"].ToString(); dr["createby"] = "'" + txtEmployeeName.Text.ToString() + "'"; dr["create_date"] = "'" + DateTime.Now.ToString("yyyy-MM-dd") + "'"; dr["remark"] = "'" + dtData.Rows[i][5].ToString() + "'"; dtTemp.Rows.Add(dr); ResultRow = myBUProductListAdd.Excel_InsertProductList(dtTemp, i, dtData.Rows.Count); MessageBox.Show("导入成功"); this.DialogResult = DialogResult.OK; } catch (Exception ex) { MessageBox.Show(dtData.Rows[i][0].ToString() + dtData.Rows[i][1].ToString() + ":" + ex.Message); wdf.Close(); return; } } } } else { wdf.Close(); MessageBox.Show("记录为空");; } } finally { if (wdf != null) { wdf.Close(); } } }