/// <summary> /// 更新一条数据 /// </summary> public bool Update(BaseCurrencyTable model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update BASE_CURRENCY set "); strSql.Append("NAME=@NAME,"); strSql.Append("STATUS_FLAG=@STATUS_FLAG,"); strSql.Append("LAST_UPDATE_USER=@LAST_UPDATE_USER,"); strSql.Append("LAST_UPDATE_TIME=GETDATE()"); strSql.Append(" where CODE=@CODE "); SqlParameter[] parameters = { new SqlParameter("@CODE", SqlDbType.VarChar, 20), new SqlParameter("@NAME", SqlDbType.NVarChar, 100), new SqlParameter("@STATUS_FLAG", SqlDbType.Int, 4), new SqlParameter("@LAST_UPDATE_USER", SqlDbType.VarChar, 20) }; parameters[0].Value = model.CODE; parameters[1].Value = model.NAME; parameters[2].Value = model.STATUS_FLAG; parameters[3].Value = model.LAST_UPDATE_USER; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { CCacheData.Currency = null; return(true); } else { return(false); } }
private void btnSave_Click(object sender, EventArgs e) { if (CheckInput()) { if (_currentCurrencyTable == null) { _currentCurrencyTable = new BaseCurrencyTable(); } _currentCurrencyTable.CODE = txtCode.Text; _currentCurrencyTable.NAME = txtName.Text; _currentCurrencyTable.LAST_UPDATE_USER = _userInfo.CODE; try { if (bCurrency.Exists(txtCode.Text.Trim())) { bCurrency.Update(_currentCurrencyTable); } else { _currentCurrencyTable.CREATE_USER = _userInfo.CODE; bCurrency.Add(_currentCurrencyTable); } } catch (Exception ex) { //log.error MessageBox.Show(""); return; } result = DialogResult.OK; this.Close(); } }
private void txtCode_Leave(object sender, EventArgs e) { //判断编号是否已存在 if (_mode == CConstant.MODE_NEW || _mode == CConstant.MODE_COPY) { BaseCurrencyTable CurrencyCode = new BaseCurrencyTable(); CurrencyCode = bCurrency.GetModel(txtCode.Text); if (CurrencyCode != 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[0].Value.ToString(); if (code != "") { _currentCurrencyTable = bCurrency.GetModel(code); } } catch (Exception ex) { } if (_currentCurrencyTable == null || _currentCurrencyTable.CODE == null || "".Equals(_currentCurrencyTable.CODE)) { _currentCurrencyTable = null; } }
private void txtCurrencyCode_Leave(object sender, EventArgs e) { //判断编号是否已存在 if (!string.IsNullOrEmpty(this.txtCurrencyCode.Text.Trim())) { BaseCurrencyTable Currency = new BaseCurrencyTable(); BCurrency bCurrency = new BCurrency(); Currency = bCurrency.GetModel(txtCurrencyCode.Text); if (Currency == null) { txtCurrencyCode.Focus(); txtCurrencyCode.Text = ""; txtCurrencyName.Text = ""; MessageBox.Show("货币编号不存在,请重新输入!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { txtCurrencyName.Text = Currency.NAME; } } }
/// <summary> /// 打开新窗口 /// </summary> private void OpenDialogFrm(int mode) { if (mode == CConstant.MODE_NEW || _currentCurrencyTable != null) { FrmCurrencyDialog frm = new FrmCurrencyDialog(); frm.UserInfo = _userInfo; frm.CurrentCurrencyTable = _currentCurrencyTable; 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); } _currentCurrencyTable = 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 (_currentCurrencyTable != null) { bCurrency.Delete(_currentCurrencyTable.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); } _currentCurrencyTable = null; } }
public override string[] doUpdateDB() { BaseCurrencyTable CurrencyTable = null; BCurrency bCurrency = new BCurrency(); 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, "名称")); //状态 str.Append(CheckInt(GetValue(dr, "STATUS_FLAG", CConstant.NORMAL_STATUS), 9, "状态")); if (str.ToString().Trim().Length > 0) { strError.Append(GetStringBuilder(dr, str.ToString().Trim())); failureData++; continue; } try { CurrencyTable = new BaseCurrencyTable(); CurrencyTable.CODE = CConvert.ToString(GetValue(dr, "CODE")); CurrencyTable.NAME = CConvert.ToString(GetValue(dr, "NAME")); CurrencyTable.CREATE_USER = _userInfo.CODE; CurrencyTable.LAST_UPDATE_USER = _userInfo.CODE; CurrencyTable.STATUS_FLAG = CConvert.ToInt32(GetValue(dr, "STATUS_FLAG", CConstant.NORMAL_STATUS)); if (!bCurrency.Exists(CurrencyTable.CODE)) { bCurrency.Add(CurrencyTable); } else { bCurrency.Update(CurrencyTable); } 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 }); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(BaseCurrencyTable model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(BaseCurrencyTable model) { return(dal.Add(model)); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(BaseCurrencyTable model) { StringBuilder strSql = null; int rows = 0; if (Exists(model.CODE)) { #region 更新 strSql = new StringBuilder(); strSql.Append("update BASE_CURRENCY set "); strSql.Append("NAME=@NAME,"); strSql.Append("STATUS_FLAG=@STATUS_FLAG,"); strSql.Append("CREATE_USER=@CREATE_USER,"); strSql.Append("CREATE_DATE_TIME=GETDATE(),"); strSql.Append("LAST_UPDATE_USER=@LAST_UPDATE_USER,"); strSql.Append("LAST_UPDATE_TIME=GETDATE()"); strSql.Append(" where CODE=@CODE "); SqlParameter[] parameters = { new SqlParameter("@CODE", SqlDbType.VarChar, 20), new SqlParameter("@NAME", SqlDbType.NVarChar, 100), new SqlParameter("@STATUS_FLAG", SqlDbType.Int, 4), new SqlParameter("@CREATE_USER", SqlDbType.VarChar, 20), new SqlParameter("@LAST_UPDATE_USER", SqlDbType.VarChar, 20) }; parameters[0].Value = model.CODE; parameters[1].Value = model.NAME; parameters[2].Value = model.STATUS_FLAG; parameters[3].Value = model.CREATE_USER; parameters[4].Value = model.LAST_UPDATE_USER; rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); #endregion } else { #region 增加 strSql = new StringBuilder(); strSql.Append("insert into BASE_CURRENCY("); strSql.Append("CODE,NAME,STATUS_FLAG,CREATE_USER,CREATE_DATE_TIME,LAST_UPDATE_USER,LAST_UPDATE_TIME)"); strSql.Append(" values ("); strSql.Append("@CODE,@NAME,@STATUS_FLAG,@CREATE_USER,GETDATE(),@LAST_UPDATE_USER,GETDATE())"); SqlParameter[] parameters = { new SqlParameter("@CODE", SqlDbType.VarChar, 20), new SqlParameter("@NAME", SqlDbType.NVarChar, 100), new SqlParameter("@STATUS_FLAG", SqlDbType.Int, 4), new SqlParameter("@CREATE_USER", SqlDbType.VarChar, 20), new SqlParameter("@LAST_UPDATE_USER", SqlDbType.VarChar, 20) }; parameters[0].Value = model.CODE; parameters[1].Value = model.NAME; parameters[2].Value = CConstant.NORMAL_STATUS; parameters[3].Value = model.CREATE_USER; parameters[4].Value = model.LAST_UPDATE_USER; rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); #endregion } if (rows > 0) { CCacheData.Currency = null; return(true); } else { return(false); } }