private void txtCode_Leave(object sender, EventArgs e) { //判断编号是否已存在 if (!string.IsNullOrEmpty(this.txtCode.Text.Trim())) { BaseTaxAtionTable TaxAtionCode = new BaseTaxAtionTable(); TaxAtionCode = bTaxAtion.GetModel(txtCode.Text); if (TaxAtionCode != null) { txtCode.Focus(); txtCode.Text = ""; MessageBox.Show("编号已存在,请重新输入!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
/// <summary> /// 获得当前选中的数据 /// </summary> private void GetCurrentSelectedTable() { try { string code = dgvData.SelectedRows[0].Cells["CODE"].Value.ToString(); if (code != "") { _currentTaxAtionTable = bTaxAtion.GetModel(code); } } catch (Exception ex) { } if (_currentTaxAtionTable == null || _currentTaxAtionTable.CODE == null || "".Equals(_currentTaxAtionTable.CODE)) { _currentTaxAtionTable = null; } }
/// <summary> /// 打开新窗口 /// </summary> private void OpenDialogFrm(int mode) { if (mode == CConstant.MODE_NEW || _currentTaxAtionTable != null) { FrmTaxAtionDialog frm = new FrmTaxAtionDialog(); frm.UserInfo = _userInfo; frm.CurrentTaxAtionTable = _currentTaxAtionTable; 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); } _currentTaxAtionTable = null; }
private void btnSave_Click(object sender, EventArgs e) { if (CheckInput()) { if (_currentTaxAtionTable == null) { _currentTaxAtionTable = new BaseTaxAtionTable(); } _currentTaxAtionTable.CODE = txtCode.Text.Trim(); _currentTaxAtionTable.NAME = txtName.Text.Trim(); _currentTaxAtionTable.TAX_RATE = Convert.ToDecimal(txtTaxRate.Text.Trim()); _currentTaxAtionTable.LAST_UPDATE_USER = _userInfo.CODE; try { if (bTaxAtion.Exists(txtCode.Text.Trim())) { bTaxAtion.Update(_currentTaxAtionTable); } else { _currentTaxAtionTable.CREATE_USER = _userInfo.CODE; bTaxAtion.Add(_currentTaxAtionTable); } } catch (Exception ex) { //log.error MessageBox.Show(""); return; } result = DialogResult.OK; this.Close(); } }
/// <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 (_currentTaxAtionTable != null) { bTaxAtion.Delete(_currentTaxAtionTable.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); } _currentTaxAtionTable = null; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(BaseTaxAtionTable model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(BaseTaxAtionTable model) { return(dal.Add(model)); }
public override string[] doUpdateDB() { BaseTaxAtionTable TaxAtionTable = null; BTaxAtion bTaxAtion = new BTaxAtion(); 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, "CODE")))) { str.Append(CheckString(GetValue(dr, "CODE"), 20, "编号")); } else { str.Append("编号不能为空!"); } //名称 str.Append(CheckLenght(GetValue(dr, "NAME"), 100, "名称")); //税率(注:数据库值为17 时表示17%) str.Append(CheckDecimal(GetValue(dr, "TAX_RATE", 0), 3, 2, "税率")); //状态 str.Append(CheckInt(GetValue(dr, "STATUS_FLAG", CConstant.NORMAL), 9, "状态")); if (str.ToString().Trim().Length > 0) { strError.Append(GetStringBuilder(dr, str.ToString().Trim())); failureData++; continue; } try { TaxAtionTable = new BaseTaxAtionTable(); TaxAtionTable.CODE = CConvert.ToString(GetValue(dr, "CODE")); TaxAtionTable.NAME = CConvert.ToString(GetValue(dr, "NAME")); TaxAtionTable.TAX_RATE = CConvert.ToDecimal(GetValue(dr, "TAX_RATE", 0)); TaxAtionTable.STATUS_FLAG = CConvert.ToInt32(GetValue(dr, "STATUS_FLAG", CConstant.NORMAL)); TaxAtionTable.CREATE_USER = _userInfo.CODE; TaxAtionTable.LAST_UPDATE_USER = _userInfo.CODE; if (!bTaxAtion.Exists(TaxAtionTable.CODE)) { bTaxAtion.Add(TaxAtionTable); } else { bTaxAtion.Update(TaxAtionTable); } 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 }); }