protected void btnCreate_Click(object sender, EventArgs e) { string costName = Request.Form[txtName.ID].Trim(); if (string.IsNullOrEmpty(costName) || Validator.IsMatchLessThanChineseCharacter(costName, CONST_NAME_LENGTH)) { lblMsg.Text = "费用名称不能为空,并且长度不能超过 " + CONST_NAME_LENGTH + " 个字符!"; return; } CostType ct = new CostType(); ct.Name = costName; ct.IsManageCosts = chkManageCosts.Checked; ct.IsSalorCosts = chkSalorCosts.Checked; if (CostTypeOperation.CreateCostType(ct)) { lblMsg.Text = "添加成功!"; } else { lblMsg.Text = "此费用名称已经存在!"; return; } RpCostTypeDataBind(); tbCostTypeCreate.Visible = false; lbtnCreate.Visible = true; }
public static bool CreateCostType(CostType ct) { if (dal.GetCostTypeByName(ct.Name) != null) { return false; } dal.CreateCostType(ct); return true; }
public void CreateCostType(CostType ct) { SqlParameter[] param = new SqlParameter[] { SqlUtilities.GenerateInputNVarcharParameter("@name", 50, ct.Name), SqlUtilities.GenerateInputParameter("@is_manage_costs", SqlDbType.Bit, ct.IsManageCosts), SqlUtilities.GenerateInputParameter("@is_salor_costs", SqlDbType.Bit, ct.IsSalorCosts) }; string sql = "INSERT INTO cost_types(name, is_manage_costs, is_salor_costs) VALUES(@name, @is_manage_costs, @is_salor_costs)"; SqlHelper.ExecuteNonQuery(CommandType.Text, sql, param); }
public List<CostType> GetCostType() { List<CostType> result = new List<CostType>(); string sql = "SELECT id, name, is_manage_costs, is_salor_costs FROM cost_types"; using (SqlDataReader dr = SqlHelper.ExecuteReader(CommandType.Text, sql, null)) { while (dr.Read()) { CostType ct = new CostType(); ct.Id = dr.GetInt32(0); ct.Name = dr.GetString(1); ct.IsManageCosts = dr.GetBoolean(2); ct.IsSalorCosts = dr.GetBoolean(3); result.Add(ct); } } return result; }
public CostType GetCostTypeById(int id) { CostType ct = null; SqlParameter[] param = new SqlParameter[] { SqlUtilities.GenerateInputIntParameter("@id", id) }; string sql = "SELECT id, name, is_manage_costs, is_salor_costs FROM cost_types WHERE id = @id"; using (SqlDataReader dr = SqlHelper.ExecuteReader(CommandType.Text, sql, param)) { while (dr.Read()) { ct = new CostType(); ct.Id = dr.GetInt32(0); ct.Name = dr.GetString(1); ct.IsManageCosts = dr.GetBoolean(2); ct.IsSalorCosts = dr.GetBoolean(3); } } return ct; }
public void UpdateCostType(CostType ct) { SqlParameter[] param = new SqlParameter[] { SqlUtilities.GenerateInputIntParameter("@id", ct.Id), SqlUtilities.GenerateInputNVarcharParameter("@name", 50, ct.Name), SqlUtilities.GenerateInputParameter("@is_manage_costs", SqlDbType.Bit, ct.IsManageCosts), SqlUtilities.GenerateInputParameter("@is_salor_costs", SqlDbType.Bit, ct.IsSalorCosts) }; string sql = "UPDATE cost_types SET name = @name, is_manage_costs = @is_manage_costs, is_salor_costs = @is_salor_costs WHERE id = @id"; SqlHelper.ExecuteNonQuery(CommandType.Text, sql, param); }
public static void UpdateCostType(CostType ct) { dal.UpdateCostType(ct); }