/// <summary> /// 修改数据的方法 /// </summary> public int UpdateConfigEntity(ConfigEntity config) { int resultRow = 0; string sqlStr = "update TF_Config set configname=@configname,configvalue=@configvalue,configtype=@configtype,remark=@remark,extension=@extension,flag=@flag where ID=@ID"; SqlParameter[] parms = { new SqlParameter("@configname", config.configname) , new SqlParameter("@configvalue", config.configvalue) , new SqlParameter("@configtype", config.configtype) , new SqlParameter("@remark", config.remark) , new SqlParameter("@extension", config.extension) , new SqlParameter("@flag", config.flag) , new SqlParameter("@ID", config.id) }; resultRow = sqlHelper.ExecuteSql(sqlStr, false, parms); return(resultRow); }
private List <ConfigEntity> CovertToConfigEntity(DataTable dt) { List <ConfigEntity> configs = new List <ConfigEntity>(); if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { ConfigEntity config = new ConfigEntity(); config.id = Convert.ToInt32(dt.Rows[i]["ID"]); config.configname = dt.Rows[i]["ConfigName"].ToString(); config.configvalue = dt.Rows[i]["ConfigValue"].ToString(); config.remark = dt.Rows[i]["Remark"].ToString(); config.extension = Convert.ToInt32(dt.Rows[i]["Extension"]); config.flag = Convert.ToInt32(dt.Rows[i]["Flag"]); configs.Add(config); } } return(configs); }
internal List <ConfigEntity> CovertToConfigEntity(DataTable dt) { List <ConfigEntity> configs = new List <ConfigEntity>(); if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { ConfigEntity config = new ConfigEntity(); config.id = Convert.ToInt32(dt.Rows[i]["序号"]); config.configname = dt.Rows[i]["配置项"].ToString(); config.configvalue = dt.Rows[i]["配置值"].ToString(); config.configtype = Convert.ToInt32(dt.Rows[i]["类型"]); config.remark = dt.Rows[i]["备注"].ToString(); config.extension = Convert.ToInt32(dt.Rows[i]["扩展值"]); config.flag = Convert.ToInt32(dt.Rows[i]["状态"]); configs.Add(config); } } return(configs); }
/// <summary> /// 增加数据的方法 /// </summary> public int InsertConfigEntity(ConfigEntity config) { string sqlStr = "insert into TF_Config(configname,configvalue,configtype,remark,extension,flag) values (@ConfigName,@ConfigValue,@ConfigType,@Remark,@Extension,@Flag); select SCOPE_IDENTITY()"; SqlParameter[] parms = { new SqlParameter("@configname", config.configname) , new SqlParameter("@configvalue", config.configvalue) , new SqlParameter("@configtype", config.configtype) , new SqlParameter("@remark", config.remark) , new SqlParameter("@extension", config.extension) , new SqlParameter("@flag", config.flag) }; object obj = sqlHelper.ExecuteSqlReturn(sqlStr, false, parms); int R; if (obj != null && obj != DBNull.Value && int.TryParse(obj.ToString(), out R)) { return(R); } else { return(0); } }
private static List <ConfigEntity> GetRemoteConfig() { List <ConfigEntity> configs = new List <ConfigEntity>(); SQLDBHelper sqlHelper = new SQLDBHelper(); DataTable dt = sqlHelper.Query("select * from TF_Config"); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { ConfigEntity config = new ConfigEntity(); config.id = Convert.ToInt32(dt.Rows[i]["ID"]); config.configname = dt.Rows[i]["ConfigName"].ToString(); config.configvalue = dt.Rows[i]["ConfigValue"].ToString(); config.remark = dt.Rows[i]["Remark"].ToString(); config.extension = Convert.ToInt32(dt.Rows[i]["Extension"]); config.flag = Convert.ToInt32(dt.Rows[i]["Flag"]); configs.Add(config); } } return(configs); }
/// <summary> /// 查询单个数据的方法 /// </summary> public ConfigEntity GetOneConfig(int id) { ConfigEntity config = null; string sqlStr = "select configname,configvalue,configtype,remark,extension,flag from TF_Config where ID=@ID"; SqlParameter[] parms = { new SqlParameter("@ID", id) }; DataTable dtResult = sqlHelper.Query(sqlStr, false, parms); if (dtResult != null && dtResult.Rows.Count > 0) { config = new ConfigEntity(); foreach (DataRow dr in dtResult.Rows) { config.id = Convert.ToInt32(dr["id"].ToString()); config.configname = dr["configname"].ToString(); config.configvalue = dr["configvalue"].ToString(); config.configtype = Convert.ToInt32(dr["configtype"].ToString()); config.remark = dr["remark"].ToString(); config.extension = Convert.ToInt32(dr["extension"].ToString()); config.flag = Convert.ToInt32(dr["flag"].ToString()); } } return(config); }
private void btn_User_Click(object sender, EventArgs e) { if (comboBox1.SelectedIndex > -1) { User user = new User(); user.ID = data[comboBox1.SelectedIndex].ID; user.Username = textBox1.Text.Trim(); user.Remark = textBox2.Text; user.Password = textBox3.Text; Department dep = comboBox2.SelectedItem as Department; if (dep != null) { user.Departments.Clear(); user.Departments.Add(dep); } user.Flag = 0; ConfigEntity ce = comboBox3.SelectedItem as ConfigEntity; if (ce != null) { user.Flag = ce.extension; } UserLogic ul = UserLogic.GetInstance(); if (ul.ExistsNameOther(user.Username, user.ID)) { if (MessageBox.Show("系统中已经存在该名称,确定还要继续保存么?", "重名提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) { if (ul.UpdateUser(user)) { data[comboBox1.SelectedIndex].Username = user.Username; data[comboBox1.SelectedIndex].Password = user.Password; data[comboBox1.SelectedIndex].Flag = user.Flag; data[comboBox1.SelectedIndex].Departments = user.Departments; data[comboBox1.SelectedIndex].Remark = user.Remark; RefreshInfo(); MessageBox.Show("修改成功!"); } } else { textBox1.Focus(); textBox1.SelectAll(); } } else { if (ul.UpdateUser(user)) { data[comboBox1.SelectedIndex].Username = user.Username; data[comboBox1.SelectedIndex].Password = user.Password; data[comboBox1.SelectedIndex].Flag = user.Flag; data[comboBox1.SelectedIndex].Departments = user.Departments; data[comboBox1.SelectedIndex].Remark = user.Remark; RefreshInfo(); MessageBox.Show("修改成功!"); } } } else { MessageBox.Show("先选定要修改的项目!"); } }