public class BioCrmCustomerBLL { /// /// 添加一个客户资料 /// /// BioCrmCustomer /// int public int CustomerAdd(BioCrmCustomer customer) { SqlParameter[] parameters = { new SqlParameter("@CustomerName", SqlDbType.NVarChar,100), new SqlParameter("@JuridicalPerson", SqlDbType.NVarChar,100), new SqlParameter("@Address", SqlDbType.NVarChar,100), new SqlParameter("@Tel1", SqlDbType.NVarChar,20), new SqlParameter("@Tel2", SqlDbType.NVarChar,20), new SqlParameter("@Fax", SqlDbType.NVarChar,20), new SqlParameter("@Email", SqlDbType.NVarChar,100), new SqlParameter("@WebSite", SqlDbType.NVarChar,100), new SqlParameter("@RegisterTime", SqlDbType.DateTime), new SqlParameter("@UserID", SqlDbType.Int,4), new SqlParameter("@CustomerLevel", SqlDbType.NVarChar,50), new SqlParameter("@NextTime", SqlDbType.DateTime), new SqlParameter("@Source", SqlDbType.NVarChar,100), new SqlParameter("@Type", SqlDbType.NVarChar,100), new SqlParameter("@Vocation", SqlDbType.NVarChar,100), new SqlParameter("@State", SqlDbType.NVarChar,50), new SqlParameter("@Property", SqlDbType.NVarChar,100), new SqlParameter("@Area", SqlDbType.NVarChar,100), new SqlParameter("@Province", SqlDbType.NVarChar,20), new SqlParameter("@City", SqlDbType.NVarChar,100), new SqlParameter("@Bank", SqlDbType.NVarChar,50), new SqlParameter("@Accounts", SqlDbType.NVarChar,100), new SqlParameter("@TaxNumber", SqlDbType.NVarChar,100), new SqlParameter("@Credit", SqlDbType.NVarChar,100), new SqlParameter("@Integral", SqlDbType.Int,4), new SqlParameter("@Remark", SqlDbType.NVarChar,200), }; parameters[0].Value = customer.CustomerName; parameters[1].Value = customer.JuridicalPerson; parameters[2].Value = customer.Address; parameters[3].Value = customer.Tel1; parameters[4].Value = customer.Tel2; parameters[5].Value = customer.Fax; parameters[6].Value = customer.Email; parameters[7].Value = customer.WebSite; parameters[8].Value = customer.RegisterTime; parameters[9].Value = customer.UserID; parameters[10].Value = customer.CustomerLevel; parameters[11].Value = customer.NextTime; parameters[12].Value = customer.Source; parameters[13].Value = customer.Type; parameters[14].Value = customer.Vocation; parameters[15].Value = customer.State; parameters[16].Value = customer.Property; parameters[17].Value = customer.Area; parameters[18].Value = customer.Province; parameters[19].Value = customer.City; parameters[20].Value = customer.Bank; parameters[21].Value = customer.Accounts; parameters[22].Value = customer.TaxNumber; parameters[23].Value = customer.Credit; parameters[24].Value = customer.Integral; parameters[25].Value = customer.Remark; return DataBaseHelper.ExcuteSqlReturnInt("BioCrmCustomer_ADD", CommandType.StoredProcedure, parameters); } /// /// 修改客户资料 /// /// /// public int CustomerUpdate(BioCrmCustomer model) { SqlParameter[] parameters = { new SqlParameter("@CustomerID", SqlDbType.Int,4), new SqlParameter("@CustomerNumber", SqlDbType.NVarChar,80), new SqlParameter("@CustomerName", SqlDbType.NVarChar,100), new SqlParameter("@JuridicalPerson", SqlDbType.NVarChar,100), new SqlParameter("@Address", SqlDbType.NVarChar,100), new SqlParameter("@Tel1", SqlDbType.NVarChar,20), new SqlParameter("@Tel2", SqlDbType.NVarChar,20), new SqlParameter("@Fax", SqlDbType.NVarChar,20), new SqlParameter("@Email", SqlDbType.NVarChar,100), new SqlParameter("@WebSite", SqlDbType.NVarChar,100), new SqlParameter("@RegisterTime", SqlDbType.DateTime), new SqlParameter("@UserID", SqlDbType.Int,4), new SqlParameter("@CustomerLevel", SqlDbType.NVarChar,50), new SqlParameter("@NextTime", SqlDbType.DateTime), new SqlParameter("@Source", SqlDbType.NVarChar,100), new SqlParameter("@Type", SqlDbType.NVarChar,100), new SqlParameter("@Vocation", SqlDbType.NVarChar,100), new SqlParameter("@State", SqlDbType.NVarChar,50), new SqlParameter("@Property", SqlDbType.NVarChar,100), new SqlParameter("@Area", SqlDbType.NVarChar,100), new SqlParameter("@Province", SqlDbType.NVarChar,20), new SqlParameter("@City", SqlDbType.NVarChar,100), new SqlParameter("@Bank", SqlDbType.NVarChar,50), new SqlParameter("@Accounts", SqlDbType.NVarChar,100), new SqlParameter("@TaxNumber", SqlDbType.NVarChar,100), new SqlParameter("@Credit", SqlDbType.NVarChar,100), new SqlParameter("@Integral", SqlDbType.Int,4), new SqlParameter("@Remark", SqlDbType.NVarChar,200), new SqlParameter("@DeleteState", SqlDbType.Bit,1)}; parameters[0].Value = model.CustomerID; parameters[1].Value = model.CustomerNumber; parameters[2].Value = model.CustomerName; parameters[3].Value = model.JuridicalPerson; parameters[4].Value = model.Address; parameters[5].Value = model.Tel1; parameters[6].Value = model.Tel2; parameters[7].Value = model.Fax; parameters[8].Value = model.Email; parameters[9].Value = model.WebSite; parameters[10].Value = model.RegisterTime; parameters[11].Value = model.UserID; parameters[12].Value = model.CustomerLevel; parameters[13].Value = model.NextTime; parameters[14].Value = model.Source; parameters[15].Value = model.Type; parameters[16].Value = model.Vocation; parameters[17].Value = model.State; parameters[18].Value = model.Property; parameters[19].Value = model.Area; parameters[20].Value = model.Province; parameters[21].Value = model.City; parameters[22].Value = model.Bank; parameters[23].Value = model.Accounts; parameters[24].Value = model.TaxNumber; parameters[25].Value = model.Credit; parameters[26].Value = model.Integral; parameters[27].Value = model.Remark; parameters[28].Value = model.DeleteState; return DataBaseHelper.ExcuteSqlReturnInt("BioCrmCustomer_Update", CommandType.StoredProcedure, parameters); } /// /// 根据客户id获取客户信息 /// /// id /// BioCrmCustomer public BioCrmCustomer GetCustomerByID(string id) { SqlDataReader reader= SqlComm.GetDataReaderByCondition("BioCrmCustomer", "*", " CustomerID=" + id); BioCrmCustomer customer = new BioCrmCustomer(); while (reader.Read()) { customer.CustomerID = int.Parse(reader["CustomerID"].ToString()); customer.CustomerNumber = reader["CustomerNumber"].ToString(); customer.CustomerName= reader["CustomerNumber"].ToString(); customer.JuridicalPerson = reader["JuridicalPerson"].ToString(); customer.Address = reader["Address"].ToString(); customer.Tel1 = reader["Tel1"].ToString(); customer.Tel2 = reader["Tel2"].ToString(); customer.Fax = reader["Fax"].ToString(); customer.Email = reader["Email"].ToString(); customer.WebSite = reader["WebSite"].ToString(); customer.RegisterTime =Convert.ToDateTime(reader["RegisterTime"].ToString()); customer.UserID = int.Parse(reader["UserID"].ToString()); customer.CustomerLevel = reader["CustomerLevel"].ToString(); customer.NextTime =Convert.ToDateTime(reader["NextTime"].ToString()); customer.Source = reader["Source"].ToString(); customer.Type = reader["Type"].ToString(); customer.Vocation = reader["Vocation"].ToString(); customer.State = reader["State"].ToString(); customer.Property = reader["Property"].ToString(); customer.Area = reader["Area"].ToString(); customer.Province = reader["Province"].ToString(); customer.City = reader["City"].ToString(); customer.Bank = reader["Bank"].ToString(); customer.Accounts = reader["Accounts"].ToString(); customer.TaxNumber = reader["TaxNumber"].ToString(); customer.Credit = reader["Credit"].ToString(); customer.Integral =int.Parse( reader["Integral"].ToString()); customer.Remark = reader["Remark"].ToString(); customer.DeleteState =Convert.ToBoolean(reader["DeleteState"].ToString()); } reader.Close(); return customer; } }
获取省份的代码:
/// /// 获取省份列表 /// /// public static DataTable getProvinceInfoList() { SqlParameter[] pars = new SqlParameter[]{ new SqlParameter("@tableName","tbProvinceInfo"), new SqlParameter("@columns","*") }; return DataBaseHelper.SelectSQLReturnDataSet("getDataByTableNameValue", CommandType.StoredProcedure, pars).Tables[0]; } /// /// 根据省份ID获取对应的城市 /// /// /// public static DataTable getCityListByProvinceID(string ProvinceID) { SqlParameter[] pars = new SqlParameter[]{ new SqlParameter("@tableName","tbCityInfo"), new SqlParameter("@columns"," * "), new SqlParameter("@condition"," ProvinceInfoID ="+ProvinceID) }; return DataBaseHelper.SelectSQLReturnDataSet("GetDataByCondition", CommandType.StoredProcedure, pars).Tables[0]; }
存储过程:
ALTER PROCEDURE [dbo].[getDataByTableNameValue] @tableName nvarchar(500), @columns nvarchar(2000)ASBEGIN SET NOCOUNT ON; DECLARE @Sql nvarchar(4000) SET @Sql='select '+@columns+' from '+@tableName EXEC(@Sql)END----根据指定列,指定条件,指定表查询数据ALTER PROCEDURE [dbo].[GetDataByCondition] @tableName nvarchar(200), @columns nvarchar(500), @condition nvarchar(500)=' 1=1' ASBEGIN SET NOCOUNT ON; DECLARE @sqlStr nvarchar(2000) SET @sqlStr='select '+@columns+' from '+@tableName+' where '+@condition EXEC(@sqlStr) END
SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER TRIGGER [dbo].[CreateCustomerNoByCustomerID] ON [dbo].[BioCrmCustomer] AFTER INSERTAS BEGIN DECLARE @str nvarchar(10) DECLARE @CustomerNo nvarchar(50) DECLARE @CustomerID nvarchar(50) SET @str='0000000' SELECT @CustomerID=MAX(CustomerID) FROM dbo.BioCrmCustomer SET @CustomerNo=RIGHT(@str+@CustomerID,7) UPDATE dbo.BioCrmCustomer SET CustomerNumber=@CustomerNo WHERE CustomerID=@CustomerIDend