//textBoxID //private void textBoxID_TextChanged(object sender, EventArgs e) //{ // if (textBoxID.Text.Length > 22)//==23 // { // textBoxID.ReadOnly = true; // textSn1.ReadOnly = false; // textSn1.Focus(); // textSn1.SelectAll(); // textLog.Text = ""; // textLog.BackColor = Color.White; // } //} private void btnChangeSnCount_Click(object sender, EventArgs e) { string smallBoxCount = textSmalBoxCount.Text.Trim(); if (btnChangeSnCount.Text == "更改") { btnChangeSnCount.Text = "确定"; btnChangeSnCount.ForeColor = Color.Red; textSmalBoxCount.ReadOnly = false; textSmalBoxCount.Focus(); textSmalBoxCount.SelectAll(); return; } if (btnChangeSnCount.Text == "确定") { if (string.IsNullOrEmpty(smallBoxCount)) { XtraMessageBox.Show("请输入一箱装 几盒!"); textSmalBoxCount.Focus(); textSmalBoxCount.SelectAll(); return; } //数量的正整数规范 ClassMyRegex regex = new ClassMyRegex(); if (regex.RegexIsPosIntMatch(smallBoxCount) == false) { XtraMessageBox.Show("请输入正整数!"); textSmalBoxCount.Focus(); textSmalBoxCount.SelectAll(); return; } btnChangeSnCount.Text = "更改"; btnChangeSnCount.ForeColor = Color.Black; Win32API.WritePrivateProfileString("Set", "smallBoxCount", smallBoxCount, strCurrentDirectory); XtraMessageBox.Show("修改成功"); textSmalBoxCount.ReadOnly = true; } }
private void btnSureInput_Click(object sender, EventArgs e) { #region 是否填写判断 bool planCodeIsNull = string.IsNullOrEmpty(textPlancode.Text); bool quantityIsNull = string.IsNullOrEmpty(textQuantity.Text); bool excelPathIsNull = string.IsNullOrEmpty(textExcelPath.Text); bool textSnFormatNull = string.IsNullOrEmpty(textSnFormat.Text); if (planCodeIsNull == false && quantityIsNull == false && excelPathIsNull == false && textSnFormatNull == false) { string order = textPlancode.Text.Trim(); //订单 string data = textSnFormat.Text.Trim(); //日期 labPlanCodeErrorTip.Text = ""; labQuantityErrorTip.Text = ""; labExcelPathErrorTip.Text = ""; labSnFormatErrorTip.Text = ""; labTips.Text = ""; //此处加入数据库查询与插入 //ClassMySqlHelp mySql = new ClassMySqlHelp(); //从MySql中读取数据显示from MySqldataBase to show //DataTable dt = mySql.Test(); //Excel excel = new Excel(dt); //excel.ShowDialog(); //订单信息(测试数据)导入MySql Inport to MySqldataBase //mySql.Import(); //订单号位数 if (order.Length != 10) { labTips.Text = totalErrorTip; labPlanCodeErrorTip.Text = "请输入10位订单号"; return; } //数量的正整数规范 ClassMyRegex regex = new ClassMyRegex(); if (regex.RegexIsPosIntMatch(textQuantity.Text) == false) { labTips.Text = totalErrorTip; labQuantityErrorTip.Text = "请输入正整数"; return; } //SN规则中日期的长度 if (data.Length != 4) { labTips.Text = totalErrorTip; labSnFormatErrorTip.Text = "请输入4位日期(年月),如:1804"; return; } //SN规则中日期的正整数规范 if (regex.RegexIsPosIntMatch(data) == false) { labTips.Text = totalErrorTip; labSnFormatErrorTip.Text = "请输入正整数的4位日期(年月),如:1804"; return; } //textSnFormat日期通过,就记忆 Win32API.WritePrivateProfileString("Info", "SnData", data, strCurrentDirectory); //从excel读取数据到ds try { ClassExcelAndDt excelAndDt = new ClassExcelAndDt(); DataSet dsFromExcel = new DataSet(); DataTable dbFromExcel = new DataTable(); dbFromExcel = excelAndDt.ExcelToDS(textExcelPath.Text, order); if (dbFromExcel == null) { XtraMessageBox.Show("Excel中未找到订单号的表\r\n提示:请检查订单号和Excel及其路径"); return; } //dbFromExcel = dsFromExcel.Tables[0]; //数量比较 int quantity = Convert.ToInt32(textQuantity.Text);//int.Parse(textQuantity.Text); if (quantity != dbFromExcel.Rows.Count) { labQuantityErrorTip.Text = "数量与Excel表格不一致"; return; } //显示等待进度条; splashScreenManager1.ShowWaitForm(); //开始操作mySql ClassMySqlHelp mySql = new ClassMySqlHelp(); string returnSn = ""; int ret = mySql.Import(dbFromExcel, order, data, out returnSn); if (ret == -1)//插入失败了 { if (string.IsNullOrEmpty(returnSn)) { Thread.Sleep(3000); splashScreenManager1.CloseWaitForm(); XtraMessageBox.Show("数据库操作失败"); return; } Thread.Sleep(3000); splashScreenManager1.CloseWaitForm(); XtraMessageBox.Show(string.Format("导入失败,检测到SN:{0}已存在", returnSn)); return; } Thread.Sleep(3000); splashScreenManager1.CloseWaitForm(); XtraMessageBox.Show("导入完成"); } catch (Exception ex) { XtraMessageBox.Show(ex.Message); return; } return; } if (planCodeIsNull || quantityIsNull || excelPathIsNull || textSnFormatNull) { labTips.Text = Tip; } if (planCodeIsNull) { labPlanCodeErrorTip.Text = eachErrorTip; } else { labPlanCodeErrorTip.Text = ""; } if (quantityIsNull) { labQuantityErrorTip.Text = eachErrorTip; } else { labQuantityErrorTip.Text = ""; } if (textSnFormatNull) { labSnFormatErrorTip.Text = eachErrorTip; } else { labSnFormatErrorTip.Text = ""; } if (excelPathIsNull) { labExcelPathErrorTip.Text = eachErrorTip; } else { labExcelPathErrorTip.Text = ""; } #endregion }