protected void btnCreate_Click(object sender, EventArgs e) { string ctName = Request.Form[txtName.ID].Trim(); if (string.IsNullOrEmpty(ctName) || Validator.IsMatchLessThanChineseCharacter(ctName, CONST_NAME_LENGTH)) { lblMsg.Text = "结算方式名称不能为空,并且长度不能超过 " + CONST_NAME_LENGTH + " 个字符!"; return; } CalculateType ct = new CalculateType(); ct.Name = ctName; if (CalculateTypeOperation.CreateCalculateType(ct)) { lblMsg.Text = "添加成功!"; } else { lblMsg.Text = "此结算方式名称已经存在!"; return; } RpCalculateTypeDataBind(); tbCalculateTypeCreate.Visible = false; lbtnCreate.Visible = true; }
public void CreateCalculateType(CalculateType ct) { SqlParameter[] param = new SqlParameter[] { SqlUtilities.GenerateInputNVarcharParameter("@name", 50, ct.Name) }; string sql = "INSERT INTO calculate_types(name) VALUES(@name)"; SqlHelper.ExecuteNonQuery(CommandType.Text, sql, param); }
public static bool CreateCalculateType(CalculateType ct) { if (dal.GetCalculateTypeByName(ct.Name) != null) { return false; } dal.CreateCalculateType(ct); return true; }
public List<CalculateType> GetCalculateType() { List<CalculateType> result = new List<CalculateType>(); string sql = "SELECT id, name FROM calculate_types"; using (SqlDataReader dr = SqlHelper.ExecuteReader(CommandType.Text, sql, null)) { while (dr.Read()) { CalculateType ct = new CalculateType(); ct.Id = dr.GetInt32(0); ct.Name = dr.GetString(1); result.Add(ct); } } return result; }
public CalculateType GetCalculateTypeByName(string name) { CalculateType ct = null; SqlParameter[] param = new SqlParameter[] { SqlUtilities.GenerateInputNVarcharParameter("@name", 50, name) }; string sql = "SELECT id, name FROM calculate_types WHERE name = @name"; using (SqlDataReader dr = SqlHelper.ExecuteReader(CommandType.Text, sql, param)) { while (dr.Read()) { ct = new CalculateType(); ct.Id = dr.GetInt32(0); ct.Name = dr.GetString(1); } } return ct; }
public void UpdateCalculateType(CalculateType ct) { SqlParameter[] param = new SqlParameter[] { SqlUtilities.GenerateInputIntParameter("@id", ct.Id), SqlUtilities.GenerateInputNVarcharParameter("@name", 50, ct.Name) }; string sql = "UPDATE calculate_types SET name = @name WHERE id = @id"; SqlHelper.ExecuteNonQuery(CommandType.Text, sql, param); }
public static void UpdateCalculateType(CalculateType ct) { dal.UpdateCalculateType(ct); }