private void txtMachineCode_Leave(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.txtMachineCode.Text.Trim())) { BaseMasterMachineTable MCode = new BaseMasterMachineTable(); MCode = bMasterMachine.GetModel(this.txtMachineCode.Text.Trim()); if (MCode != null) { txtMachineCode.Focus(); txtMachineCode.Text = ""; MessageBox.Show("编号已存在,请重新输入!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
/// <summary> /// 获得当前选中的数据 /// </summary> private void GetCurrentSelectedTable() { try { string code = dgvData.SelectedRows[0].Cells[0].Value.ToString(); if (code != "") { _currentMasterMachineTable = bMasterMachine.GetModel(code); } } catch (Exception ex) { } if (_currentMasterMachineTable == null || _currentMasterMachineTable.MACHINE_CODE == null || "".Equals(_currentMasterMachineTable.MACHINE_CODE)) { _currentMasterMachineTable = null; } }
private void btnSave_Click(object sender, EventArgs e) { if (CheckInput()) { if (_currentMasterMachineTable == null) { _currentMasterMachineTable = new BaseMasterMachineTable(); } _currentMasterMachineTable.MACHINE_CODE = txtMachineCode.Text; _currentMasterMachineTable.MACHINE_NAME = txtMachineName.Text; _currentMasterMachineTable.CUSTOMER_CODE = txtCustomerCode.Text; _currentMasterMachineTable.PRODUCT_CODE = txtProductCode.Text; _currentMasterMachineTable.PURCHASE_ORDER_SLIP_NUMBER = txtPurchaseOrderSlipNumber.Text; _currentMasterMachineTable.FANUC_SERIAL_NUMBER = txtFSerialNumber.Text; _currentMasterMachineTable.FANUC_SLIP_NUMBER = txtFSlipNUmber.Text; _currentMasterMachineTable.RECEIPT_DATE = txtReceiptDate.Value; _currentMasterMachineTable.MAINTENANCE_STATIONS = CConvert.ToString(cboMaintenanceStations.SelectedValue); _currentMasterMachineTable.LAST_UPDATE_USER = _userInfo.CODE; _currentMasterMachineTable.PURCHASE_SLIP_NUMBER = txtPurchaseSlipNumber.Text; if (txtSaleTime.Checked) { _currentMasterMachineTable.SALE_DATE_TIME = txtSaleTime.Value; } try { if (bMasterMachine.Exists(txtMachineCode.Text.Trim())) { bMasterMachine.Update(_currentMasterMachineTable); } else { _currentMasterMachineTable.CREATE_USER = _userInfo.CODE; bMasterMachine.Add(_currentMasterMachineTable); } } catch (Exception ex) { MessageBox.Show(ex.Message); } result = DialogResult.OK; this.Close(); } }
/// <summary> /// 打开新窗口 /// </summary> private void OpenDialogFrm(int mode) { if (mode == CConstant.MODE_NEW || _currentMasterMachineTable != null) { FrmMasterMachineDialog frm = new FrmMasterMachineDialog(); frm.UserInfo = _userInfo; frm.CurrentMasterMachineTable = _currentMasterMachineTable; frm.Mode = mode; DialogResult resule = frm.ShowDialog(this); if (resule == DialogResult.OK && isSearch) { Search(this.pgControl.GetCurrentPage()); } frm.Dispose(); } else { //MessageBox.Show("请选择正确的行!",this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning); } _currentMasterMachineTable = null; }
/// <summary> /// 删除 /// </summary> private void MasterToolBar_DoDelete_Click(object sender, EventArgs e) { if (MessageBox.Show("确定要删除吗?", this.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) == DialogResult.OK) { try { GetCurrentSelectedTable(); if (_currentMasterMachineTable != null) { bMasterMachine.Delete(_currentMasterMachineTable.MACHINE_CODE); Search(this.pgControl.GetCurrentPage()); } else { MessageBox.Show("请选择正确的行!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show("删除失败,请重试或与系统管理员联系。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } _currentMasterMachineTable = null; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(BaseMasterMachineTable model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(BaseMasterMachineTable model) { return(dal.Add(model)); }
public override string[] doUpdateDB() { BaseMasterMachineTable MachineTable = null; BMasterMachine bMasterMachine = new BMasterMachine(); StringBuilder strError = new StringBuilder(); int successData = 0; int failureData = 0; string errorFilePath = ""; string backupFilePath = ""; //数据导入处理 foreach (DataRow dr in _csvDataTable.Rows) { StringBuilder str = new StringBuilder(); //机械编号 if (!string.IsNullOrEmpty(CConvert.ToString(GetValue(dr, "MACHINE_CODE")))) { str.Append(CheckString(GetValue(dr, "MACHINE_CODE"), 20, "机械编号")); } else { str.Append("机械编号不能为空!"); } //机械名称 str.Append(CheckLenght(GetValue(dr, "MACHINE_NAME"), 100, "机械名称")); //需要家 str.Append(CheckLenght(GetValue(dr, "CUSTOMER_CODE"), 50, "需要家")); //商品编号 str.Append(CheckLenght(GetValue(dr, "PRODUCT_CODE"), 50, "商品编号")); //维修地点 str.Append(CheckLenght(GetValue(dr, "MAINTENANCE_STATIONS"), 50, "维修地点")); //采购编号 str.Append(CheckLenght(GetValue(dr, "PURCHASE_ORDER_SLIP_NUMBER"), 20, "采购编号")); //FANUC序列号 str.Append(CheckLenght(GetValue(dr, "FANUC_SERIAL_NUMBER"), 20, "FANUC序列号")); //FANUC编号 str.Append(CheckLenght(GetValue(dr, "FANUC_SLIP_NUMBER"), 20, "FANUC编号")); //采购日期 if (GetValue(dr, "RECEIPT_DATE") != null) { str.Append(CheckDateTime(GetValue(dr, "RECEIPT_DATE"), "采购日期")); } //状态 str.Append(CheckInt(GetValue(dr, "STATUS_FLAG", 1), 9, "状态")); if (str.ToString().Trim().Length > 0) { strError.Append(GetStringBuilder(dr, str.ToString().Trim())); failureData++; continue; } try { MachineTable = new BaseMasterMachineTable(); MachineTable.MACHINE_CODE = CConvert.ToString(GetValue(dr, "MACHINE_CODE")); MachineTable.MACHINE_NAME = CConvert.ToString(GetValue(dr, "MACHINE_NAME")); MachineTable.CUSTOMER_CODE = CConvert.ToString(GetValue(dr, "CUSTOMER_CODE")); MachineTable.PRODUCT_CODE = CConvert.ToString(GetValue(dr, "PRODUCT_CODE")); MachineTable.MAINTENANCE_STATIONS = CConvert.ToString(GetValue(dr, "MAINTENANCE_STATIONS")); MachineTable.PURCHASE_ORDER_SLIP_NUMBER = CConvert.ToString(GetValue(dr, "PURCHASE_ORDER_SLIP_NUMBER")); MachineTable.FANUC_SERIAL_NUMBER = CConvert.ToString(GetValue(dr, "FANUC_SERIAL_NUMBER")); MachineTable.FANUC_SLIP_NUMBER = CConvert.ToString(GetValue(dr, "FANUC_SLIP_NUMBER")); MachineTable.RECEIPT_DATE = CConvert.ToDateTime(GetValue(dr, "RECEIPT_DATE")); MachineTable.STATUS_FLAG = CConvert.ToInt32(GetValue(dr, "STATUS_FLAG", CConstant.NORMAL)); MachineTable.CREATE_USER = _userInfo.CODE; MachineTable.LAST_UPDATE_USER = _userInfo.CODE; if (!bMasterMachine.Exists(MachineTable.MACHINE_CODE)) { bMasterMachine.Add(MachineTable); } else { bMasterMachine.Update(MachineTable); } successData++; } catch { strError.Append(GetStringBuilder(dr, " 数据导入失败,请与系统管理员联系!").ToString()); failureData++; } } //错误记录处理 if (strError.Length > 0) { errorFilePath = WriteFile(strError.ToString()); } //备份处理 backupFilePath = BackupFile(); return(new string[] { successData.ToString(), failureData.ToString(), errorFilePath, backupFilePath }); }