/// <summary> /// 更新一条数据 /// </summary> public bool Update(GSSModel.Dictionary model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_Dictionary set "); strSql.Append("F_ParentID=@F_ParentID,"); strSql.Append("F_Value=@F_Value,"); strSql.Append("F_IsUsed=@F_IsUsed,"); strSql.Append("F_Sort=@F_Sort"); strSql.Append(" where F_DicID=@F_DicID "); SqlParameter[] parameters = { new SqlParameter("@F_ParentID", SqlDbType.Int, 4), new SqlParameter("@F_Value", SqlDbType.NVarChar, 50), new SqlParameter("@F_IsUsed", SqlDbType.Bit, 1), new SqlParameter("@F_Sort", SqlDbType.Int, 4), new SqlParameter("@F_DicID", SqlDbType.Int, 4) }; parameters[0].Value = model.F_ParentID; parameters[1].Value = model.F_Value; parameters[2].Value = model.F_IsUsed; parameters[3].Value = model.F_Sort; parameters[4].Value = model.F_DicID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public GSSModel.Dictionary GetModel(int F_DicID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 F_DicID,F_ParentID,F_Value,F_IsUsed,F_Sort from T_Dictionary "); strSql.Append(" where F_DicID=@F_DicID "); SqlParameter[] parameters = { new SqlParameter("@F_DicID", SqlDbType.Int, 4) }; parameters[0].Value = F_DicID; GSSModel.Dictionary model = new GSSModel.Dictionary(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["F_DicID"].ToString() != "") { model.F_DicID = int.Parse(ds.Tables[0].Rows[0]["F_DicID"].ToString()); } if (ds.Tables[0].Rows[0]["F_ParentID"].ToString() != "") { model.F_ParentID = int.Parse(ds.Tables[0].Rows[0]["F_ParentID"].ToString()); } if (ds.Tables[0].Rows[0]["F_Value"] != null) { model.F_Value = ds.Tables[0].Rows[0]["F_Value"].ToString(); } if (ds.Tables[0].Rows[0]["F_IsUsed"].ToString() != "") { if ((ds.Tables[0].Rows[0]["F_IsUsed"].ToString() == "1") || (ds.Tables[0].Rows[0]["F_IsUsed"].ToString().ToLower() == "true")) { model.F_IsUsed = true; } else { model.F_IsUsed = false; } } if (ds.Tables[0].Rows[0]["F_Sort"].ToString() != "") { model.F_Sort = int.Parse(ds.Tables[0].Rows[0]["F_Sort"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 初始化窗体 /// </summary> private void InitForm() { if (_id > 0) { this.Text = "字典修改"; f_DicIDTextBox.Enabled = false; GSSBLL.Dictionary bll = new GSSBLL.Dictionary(); GSSModel.Dictionary model = bll.GetModel(_id); f_DicIDTextBox.Text = model.F_DicID.ToString(); f_ParentIDTextBox.Text = model.F_ParentID.ToString(); f_ValueTextBox.Text = model.F_Value; f_SortTextBox.Text = model.F_Sort.ToString(); f_IsUsedCheckBox.Checked = model.F_IsUsed; } }
/// <summary> /// 保存数据 /// </summary> private void SaveData() { //验证数据项 string msg = CheckData(); if (msg.Length > 0) { MessageBox.Show(msg, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //数据准备 GSSModel.Dictionary model = new GSSModel.Dictionary(); model.F_DicID = Convert.ToInt32(f_DicIDTextBox.Text); model.F_ParentID = Convert.ToInt32(f_ParentIDTextBox.Text); model.F_Value = f_ValueTextBox.Text; model.F_Sort = Convert.ToInt32(f_SortTextBox.Text); model.F_IsUsed = f_IsUsedCheckBox.Checked; //数据提交 GSSBLL.Dictionary bll = new GSSBLL.Dictionary(); bool isok = false; if (_id > 0) { isok = bll.Update(model); } else { if (model.F_DicID == 0) { MessageBox.Show(LanguageResource.Language.Tip_IDShouldGatherThan0); return; } isok = bll.Add(model); } if (isok) { MessageBox.Show("数据保存成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("数据保存失败!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// 增加一条数据 /// </summary> public void Add(GSSModel.Dictionary model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into T_Dictionary("); strSql.Append("F_DicID,F_ParentID,F_Value,F_IsUsed,F_Sort)"); strSql.Append(" values ("); strSql.Append("@F_DicID,@F_ParentID,@F_Value,@F_IsUsed,@F_Sort)"); SqlParameter[] parameters = { new SqlParameter("@F_DicID", SqlDbType.Int, 4), new SqlParameter("@F_ParentID", SqlDbType.Int, 4), new SqlParameter("@F_Value", SqlDbType.NVarChar, 50), new SqlParameter("@F_IsUsed", SqlDbType.Bit, 1), new SqlParameter("@F_Sort", SqlDbType.Int, 4) }; parameters[0].Value = model.F_DicID; parameters[1].Value = model.F_ParentID; parameters[2].Value = model.F_Value; parameters[3].Value = model.F_IsUsed; parameters[4].Value = model.F_Sort; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }