/// <summary> /// 增加一条数据 /// </summary> public decimal Add(Maticsoft.Model.SMT_VER_FORMAT model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into SMT_VER_FORMAT("); strSql.Append("VER_TYPE,VER_NAME,VER_FORMAT)"); strSql.Append(" values ("); strSql.Append("@VER_TYPE,@VER_NAME,@VER_FORMAT)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@VER_TYPE", SqlDbType.SmallInt, 2), new SqlParameter("@VER_NAME", SqlDbType.NVarChar, 40), new SqlParameter("@VER_FORMAT", SqlDbType.NVarChar, 300) }; parameters[0].Value = model.VER_TYPE; parameters[1].Value = model.VER_NAME; parameters[2].Value = model.VER_FORMAT; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToDecimal(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.SMT_VER_FORMAT model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update SMT_VER_FORMAT set "); strSql.Append("VER_TYPE=@VER_TYPE,"); strSql.Append("VER_NAME=@VER_NAME,"); strSql.Append("VER_FORMAT=@VER_FORMAT"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@VER_TYPE", SqlDbType.SmallInt, 2), new SqlParameter("@VER_NAME", SqlDbType.NVarChar, 40), new SqlParameter("@VER_FORMAT", SqlDbType.NVarChar, 300), new SqlParameter("@ID", SqlDbType.Decimal, 9) }; parameters[0].Value = model.VER_TYPE; parameters[1].Value = model.VER_NAME; parameters[2].Value = model.VER_FORMAT; parameters[3].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
private void dgvData_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex >= 0 && e.RowIndex >= 0) { if (dgvData.Columns[e.ColumnIndex].Name == "ColDelete") { Maticsoft.BLL.SMT_VER_FORMAT verBll = new Maticsoft.BLL.SMT_VER_FORMAT(); DataGridViewRow row = dgvData.Rows[e.RowIndex]; Maticsoft.Model.SMT_VER_FORMAT verModel = (Maticsoft.Model.SMT_VER_FORMAT)row.Tag; if (MessageBox.Show("确定删除该证件编码?", "提示", MessageBoxButtons.OKCancel) != DialogResult.OK) { return; } CtrlWaiting waiting = new CtrlWaiting(() => { try { verBll.Delete(verModel.ID); this.Invoke(new Action(() => { dgvData.Rows.Remove(row); })); } catch (Exception ex) { log.Error("删除证件编码异常!", ex); WinInfoHelper.ShowInfoWindow(this, "删除证件编码异常:" + ex.Message); } }); waiting.Show(this); } } }
private void btnAdd_Click(object sender, EventArgs e) { if (tbVerName.Text.Trim() == "") { WinInfoHelper.ShowInfoWindow(this, "证件名称不能为空!"); tbVerName.Focus(); return; } if (cboVerType.SelectedIndex < 0) { WinInfoHelper.ShowInfoWindow(this, "证件类型不能为空!"); cboVerType.Focus(); return; } if (tbVerFormat.Text.Trim() == "") { WinInfoHelper.ShowInfoWindow(this, "编码格式不能为空!"); tbVerFormat.Focus(); return; } Maticsoft.Model.SMT_VER_FORMAT format = new Maticsoft.Model.SMT_VER_FORMAT() { VER_FORMAT = tbVerFormat.Text.Trim(), VER_NAME = tbVerName.Text.Trim(), VER_TYPE = cboVerType.SelectedIndex }; CtrlWaiting waiting = new CtrlWaiting(() => { try { Maticsoft.BLL.SMT_VER_FORMAT verformat = new Maticsoft.BLL.SMT_VER_FORMAT(); format.ID = verformat.Add(format); this.Invoke(new Action(() => { DoAddToGrid(format); })); } catch (System.Exception ex) { WinInfoHelper.ShowInfoWindow(this, "添加失败:" + ex.Message); log.Error("添加失败:", ex); } }); waiting.Show(this); }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.SMT_VER_FORMAT DataRowToModel(DataRow row) { Maticsoft.Model.SMT_VER_FORMAT model = new Maticsoft.Model.SMT_VER_FORMAT(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = decimal.Parse(row["ID"].ToString()); } if (row["VER_TYPE"] != null && row["VER_TYPE"].ToString() != "") { model.VER_TYPE = int.Parse(row["VER_TYPE"].ToString()); } if (row["VER_NAME"] != null) { model.VER_NAME = row["VER_NAME"].ToString(); } if (row["VER_FORMAT"] != null) { model.VER_FORMAT = row["VER_FORMAT"].ToString(); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.SMT_VER_FORMAT GetModel(decimal ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,VER_TYPE,VER_NAME,VER_FORMAT from SMT_VER_FORMAT "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Decimal) }; parameters[0].Value = ID; Maticsoft.Model.SMT_VER_FORMAT model = new Maticsoft.Model.SMT_VER_FORMAT(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
private void DoAddToGrid(Maticsoft.Model.SMT_VER_FORMAT format) { DataGridViewRow dgvr = new DataGridViewRow(); string strType = "其他"; switch (format.VER_TYPE) { case 0: strType = "工作证"; break; case 1: strType = "身份证"; break; case 2: strType = "驾驶证"; break; case 3: strType = "施工证"; break; default: break; } dgvr.CreateCells(dgvData, format.VER_NAME, strType, format.VER_FORMAT, "删除" ); dgvr.Tag = format; dgvData.Rows.Add(dgvr); }