/// <summary> /// 增加一条数据 /// </summary> public void Add(GSSModel.GameConfig model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into T_GameConfig("); strSql.Append("F_ID,F_ParentID,F_Name,F_Value,F_Value1,F_ValueGame,F_IsUsed,F_Sort)"); strSql.Append(" values ("); strSql.Append("@F_ID,@F_ParentID,@F_Name,@F_Value,@F_Value1,@F_ValueGame,@F_IsUsed,@F_Sort)"); SqlParameter[] parameters = { new SqlParameter("@F_ID", SqlDbType.Int, 4), new SqlParameter("@F_ParentID", SqlDbType.Int, 4), new SqlParameter("@F_Name", SqlDbType.NVarChar, 30), new SqlParameter("@F_Value", SqlDbType.NVarChar, 200), new SqlParameter("@F_Value1", SqlDbType.NVarChar, 200), new SqlParameter("@F_ValueGame", SqlDbType.NVarChar, 100), new SqlParameter("@F_IsUsed", SqlDbType.Bit, 1), new SqlParameter("@F_Sort", SqlDbType.Int, 4) }; parameters[0].Value = model.F_ID; parameters[1].Value = model.F_ParentID; parameters[2].Value = model.F_Name; parameters[3].Value = model.F_Value; parameters[4].Value = model.F_Value1; parameters[5].Value = model.F_ValueGame; parameters[6].Value = model.F_IsUsed; parameters[7].Value = model.F_Sort; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }
/// <summary> /// 保存数据 /// </summary> private void SaveData() { //验证数据项 string msg = CheckData(); if (msg.Length > 0) { MessageBox.Show(msg, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //数据准备 GSSModel.GameConfig model = new GSSModel.GameConfig(); model.F_ID = Convert.ToInt32(f_IDTextBox.Text); model.F_Name = f_NameTextBox.Text; model.F_ValueGame = f_ValueGamerichTextBox.Text; model.F_ParentID = Convert.ToInt32(f_ParentIDTextBox.Text); model.F_Value = f_ValueTextBox.Text; model.F_Value1 = f_Value1TextBox.Text; model.F_Sort = Convert.ToInt32(f_SortTextBox.Text); model.F_IsUsed = f_IsUsedCheckBox.Checked; //数据提交 GSSBLL.GameConfig bll = new GSSBLL.GameConfig(); bool isok = false; //检测是否已经存在 if (_id > 0) { isok = bll.Update(model); } else { if (model.F_ID == 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 bool Update(GSSModel.GameConfig model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_GameConfig set "); strSql.Append("F_ParentID=@F_ParentID,"); strSql.Append("F_Name=@F_Name,"); strSql.Append("F_Value=@F_Value,"); strSql.Append("F_Value1=@F_Value1,"); strSql.Append("F_ValueGame=@F_ValueGame,"); strSql.Append("F_IsUsed=@F_IsUsed,"); strSql.Append("F_Sort=@F_Sort"); strSql.Append(" where F_ID=@F_ID "); SqlParameter[] parameters = { new SqlParameter("@F_ParentID", SqlDbType.Int, 4), new SqlParameter("@F_Name", SqlDbType.NVarChar, 30), new SqlParameter("@F_Value", SqlDbType.NVarChar, 200), new SqlParameter("@F_Value1", SqlDbType.NVarChar, 200), new SqlParameter("@F_ValueGame", SqlDbType.NVarChar, 100), new SqlParameter("@F_IsUsed", SqlDbType.Bit, 1), new SqlParameter("@F_Sort", SqlDbType.Int, 4), new SqlParameter("@F_ID", SqlDbType.Int, 4) }; parameters[0].Value = model.F_ParentID; parameters[1].Value = model.F_Name; parameters[2].Value = model.F_Value; parameters[3].Value = model.F_Value1; parameters[4].Value = model.F_ValueGame; parameters[5].Value = model.F_IsUsed; parameters[6].Value = model.F_Sort; parameters[7].Value = model.F_ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 初始化窗体 /// </summary> private void InitForm() { if (_id > 0) { this.Text = "游戏配置修改"; f_IDTextBox.Enabled = true; if (_id > 0) { f_IDTextBox.Enabled = false; } GSSBLL.GameConfig bll = new GSSBLL.GameConfig(); GSSModel.GameConfig model = bll.GetModel(_id); f_IDTextBox.Text = model.F_ID.ToString(); f_ParentIDTextBox.Text = model.F_ParentID.ToString(); f_NameTextBox.Text = model.F_Name; f_ValueTextBox.Text = model.F_Value; f_Value1TextBox.Text = model.F_Value1; f_ValueGamerichTextBox.Text = model.F_ValueGame; f_SortTextBox.Text = model.F_Sort.ToString(); f_IsUsedCheckBox.Checked = model.F_IsUsed; } }
/// <summary> /// 得到一个对象实体 /// </summary> public GSSModel.GameConfig GetModel(int F_ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 F_ID,F_ParentID,F_Name,F_Value,F_Value1,F_ValueGame,F_IsUsed,F_Sort from T_GameConfig "); strSql.Append(" where F_ID=@F_ID "); SqlParameter[] parameters = { new SqlParameter("@F_ID", SqlDbType.Int, 4) }; parameters[0].Value = F_ID; GSSModel.GameConfig model = new GSSModel.GameConfig(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["F_ID"].ToString() != "") { model.F_ID = int.Parse(ds.Tables[0].Rows[0]["F_ID"].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_Name"] != null) { model.F_Name = ds.Tables[0].Rows[0]["F_Name"].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_Value1"] != null) { model.F_Value1 = ds.Tables[0].Rows[0]["F_Value1"].ToString(); } if (ds.Tables[0].Rows[0]["F_ValueGame"] != null) { model.F_ValueGame = ds.Tables[0].Rows[0]["F_ValueGame"].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); } }