using CallCenterApi.DB; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CallCenterApi.DAL { /// /// 数据访问类:T_Sys_Customer /// public partial class T_Sys_Customer { public T_Sys_Customer() { } #region BasicMethod /// /// 得到最大ID /// public int GetMaxId() { return DbHelperSQL.GetMaxID("F_ID", "T_Sys_Customer"); } /// /// 是否存在该记录 /// public bool Exists(int F_ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select count(1) from T_Sys_Customer"); strSql.Append(" where F_ID=@F_ID"); SqlParameter[] parameters = { new SqlParameter("@F_ID", SqlDbType.Int,4) }; parameters[0].Value = F_ID; return DbHelperSQL.Exists(strSql.ToString(), parameters); } /// /// 增加一条数据 /// public int Add(CallCenterApi.Model.T_Sys_Customer model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into T_Sys_Customer("); strSql.Append("customer_no,customer_name,identify_no,customer_sex,customer_birthday,customer_phone,customer_mobile,customer_number,ambulance_enter,live_condition,children_condition,remarks,customer_ukey,spouse_name,spouse_identifyNo,spouse_sex,spouse_birthday,account_address,customer_address,post_code,waiter_name,customer_belongs,neighborhood_phone,machine_no,owned_property,property_phone,police_belongs,police_phone,use_status,charge_kind,F_IsDelete,F_CreateTime,F_UpdateTime,icon)"); strSql.Append(" values ("); strSql.Append("@customer_no,@customer_name,@identify_no,@customer_sex,@customer_birthday,@customer_phone,@customer_mobile,@customer_number,@ambulance_enter,@live_condition,@children_condition,@remarks,@customer_ukey,@spouse_name,@spouse_identifyNo,@spouse_sex,@spouse_birthday,@account_address,@customer_address,@post_code,@waiter_name,@customer_belongs,@neighborhood_phone,@machine_no,@owned_property,@property_phone,@police_belongs,@police_phone,@use_status,@charge_kind,@F_IsDelete,@F_CreateTime,@F_UpdateTime,icon)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@customer_no", SqlDbType.NVarChar,100), new SqlParameter("@customer_name", SqlDbType.NVarChar,100), new SqlParameter("@identify_no", SqlDbType.NVarChar,50), new SqlParameter("@customer_sex", SqlDbType.NVarChar,50), new SqlParameter("@customer_birthday", SqlDbType.NVarChar,50), new SqlParameter("@customer_phone", SqlDbType.NVarChar,50), new SqlParameter("@customer_mobile", SqlDbType.NVarChar,50), new SqlParameter("@customer_number", SqlDbType.NVarChar,50), new SqlParameter("@ambulance_enter", SqlDbType.NVarChar,50), new SqlParameter("@live_condition", SqlDbType.NVarChar,50), new SqlParameter("@children_condition", SqlDbType.NVarChar,50), new SqlParameter("@remarks", SqlDbType.NVarChar,-1), new SqlParameter("@customer_ukey", SqlDbType.NVarChar,100), new SqlParameter("@spouse_name", SqlDbType.NVarChar,50), new SqlParameter("@spouse_identifyNo", SqlDbType.NVarChar,50), new SqlParameter("@spouse_sex", SqlDbType.NVarChar,50), new SqlParameter("@spouse_birthday", SqlDbType.NVarChar,50), new SqlParameter("@account_address", SqlDbType.NVarChar,500), new SqlParameter("@customer_address", SqlDbType.NVarChar,500), new SqlParameter("@post_code", SqlDbType.NVarChar,50), new SqlParameter("@waiter_name", SqlDbType.NVarChar,50), new SqlParameter("@customer_belongs", SqlDbType.NVarChar,500), new SqlParameter("@neighborhood_phone", SqlDbType.NVarChar,50), new SqlParameter("@machine_no", SqlDbType.NVarChar,50), new SqlParameter("@owned_property", SqlDbType.NVarChar,500), new SqlParameter("@property_phone", SqlDbType.NVarChar,50), new SqlParameter("@police_belongs", SqlDbType.NVarChar,50), new SqlParameter("@police_phone", SqlDbType.NVarChar,50), new SqlParameter("@use_status", SqlDbType.NVarChar,50), new SqlParameter("@charge_kind", SqlDbType.NVarChar,50), new SqlParameter("@F_IsDelete", SqlDbType.Int,4), new SqlParameter("@F_CreateTime", SqlDbType.DateTime), new SqlParameter("@F_UpdateTime", SqlDbType.DateTime), new SqlParameter("@icon", SqlDbType.NVarChar,500), }; parameters[0].Value = model.customer_no; parameters[1].Value = model.customer_name; parameters[2].Value = model.identify_no; parameters[3].Value = model.customer_sex; parameters[4].Value = model.customer_birthday; parameters[5].Value = model.customer_phone; parameters[6].Value = model.customer_mobile; parameters[7].Value = model.customer_number; parameters[8].Value = model.ambulance_enter; parameters[9].Value = model.live_condition; parameters[10].Value = model.children_condition; parameters[11].Value = model.remarks; parameters[12].Value = model.customer_ukey; parameters[13].Value = model.spouse_name; parameters[14].Value = model.spouse_identifyNo; parameters[15].Value = model.spouse_sex; parameters[16].Value = model.spouse_birthday; parameters[17].Value = model.account_address; parameters[18].Value = model.customer_address; parameters[19].Value = model.post_code; parameters[20].Value = model.waiter_name; parameters[21].Value = model.customer_belongs; parameters[22].Value = model.neighborhood_phone; parameters[23].Value = model.machine_no; parameters[24].Value = model.owned_property; parameters[25].Value = model.property_phone; parameters[26].Value = model.police_belongs; parameters[27].Value = model.police_phone; parameters[28].Value = model.use_status; parameters[29].Value = model.charge_kind; parameters[30].Value = model.F_IsDelete; parameters[31].Value = model.F_CreateTime; parameters[32].Value = model.F_UpdateTime; parameters[33].Value = model.icon; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return 0; } else { return Convert.ToInt32(obj); } } /// /// 更新一条数据 /// public bool Update(CallCenterApi.Model.T_Sys_Customer model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_Sys_Customer set "); strSql.Append("customer_no=@customer_no,"); strSql.Append("customer_name=@customer_name,"); strSql.Append("identify_no=@identify_no,"); strSql.Append("customer_sex=@customer_sex,"); strSql.Append("customer_birthday=@customer_birthday,"); strSql.Append("customer_phone=@customer_phone,"); strSql.Append("customer_mobile=@customer_mobile,"); strSql.Append("customer_number=@customer_number,"); strSql.Append("ambulance_enter=@ambulance_enter,"); strSql.Append("live_condition=@live_condition,"); strSql.Append("children_condition=@children_condition,"); strSql.Append("remarks=@remarks,"); strSql.Append("customer_ukey=@customer_ukey,"); strSql.Append("spouse_name=@spouse_name,"); strSql.Append("spouse_identifyNo=@spouse_identifyNo,"); strSql.Append("spouse_sex=@spouse_sex,"); strSql.Append("spouse_birthday=@spouse_birthday,"); strSql.Append("account_address=@account_address,"); strSql.Append("customer_address=@customer_address,"); strSql.Append("post_code=@post_code,"); strSql.Append("waiter_name=@waiter_name,"); strSql.Append("customer_belongs=@customer_belongs,"); strSql.Append("neighborhood_phone=@neighborhood_phone,"); strSql.Append("machine_no=@machine_no,"); strSql.Append("owned_property=@owned_property,"); strSql.Append("property_phone=@property_phone,"); strSql.Append("police_belongs=@police_belongs,"); strSql.Append("police_phone=@police_phone,"); strSql.Append("use_status=@use_status,"); strSql.Append("charge_kind=@charge_kind,"); strSql.Append("F_IsDelete=@F_IsDelete,"); strSql.Append("F_CreateTime=@F_CreateTime,"); strSql.Append("icon=@icon,"); strSql.Append("F_UpdateTime=@F_UpdateTime"); strSql.Append(" where F_ID=@F_ID"); SqlParameter[] parameters = { new SqlParameter("@customer_no", SqlDbType.NVarChar,100), new SqlParameter("@customer_name", SqlDbType.NVarChar,100), new SqlParameter("@identify_no", SqlDbType.NVarChar,50), new SqlParameter("@customer_sex", SqlDbType.NVarChar,50), new SqlParameter("@customer_birthday", SqlDbType.NVarChar,50), new SqlParameter("@customer_phone", SqlDbType.NVarChar,50), new SqlParameter("@customer_mobile", SqlDbType.NVarChar,50), new SqlParameter("@customer_number", SqlDbType.NVarChar,50), new SqlParameter("@ambulance_enter", SqlDbType.NVarChar,50), new SqlParameter("@live_condition", SqlDbType.NVarChar,50), new SqlParameter("@children_condition", SqlDbType.NVarChar,50), new SqlParameter("@remarks", SqlDbType.NVarChar,-1), new SqlParameter("@customer_ukey", SqlDbType.NVarChar,100), new SqlParameter("@spouse_name", SqlDbType.NVarChar,50), new SqlParameter("@spouse_identifyNo", SqlDbType.NVarChar,50), new SqlParameter("@spouse_sex", SqlDbType.NVarChar,50), new SqlParameter("@spouse_birthday", SqlDbType.NVarChar,50), new SqlParameter("@account_address", SqlDbType.NVarChar,500), new SqlParameter("@customer_address", SqlDbType.NVarChar,500), new SqlParameter("@post_code", SqlDbType.NVarChar,50), new SqlParameter("@waiter_name", SqlDbType.NVarChar,50), new SqlParameter("@customer_belongs", SqlDbType.NVarChar,500), new SqlParameter("@neighborhood_phone", SqlDbType.NVarChar,50), new SqlParameter("@machine_no", SqlDbType.NVarChar,50), new SqlParameter("@owned_property", SqlDbType.NVarChar,500), new SqlParameter("@property_phone", SqlDbType.NVarChar,50), new SqlParameter("@police_belongs", SqlDbType.NVarChar,50), new SqlParameter("@police_phone", SqlDbType.NVarChar,50), new SqlParameter("@use_status", SqlDbType.NVarChar,50), new SqlParameter("@charge_kind", SqlDbType.NVarChar,50), new SqlParameter("@F_IsDelete", SqlDbType.Int,4), new SqlParameter("@F_CreateTime", SqlDbType.DateTime), new SqlParameter("@icon", SqlDbType.NVarChar,500), new SqlParameter("@F_UpdateTime", SqlDbType.DateTime), new SqlParameter("@F_ID", SqlDbType.Int,4)}; parameters[0].Value = model.customer_no; parameters[1].Value = model.customer_name; parameters[2].Value = model.identify_no; parameters[3].Value = model.customer_sex; parameters[4].Value = model.customer_birthday; parameters[5].Value = model.customer_phone; parameters[6].Value = model.customer_mobile; parameters[7].Value = model.customer_number; parameters[8].Value = model.ambulance_enter; parameters[9].Value = model.live_condition; parameters[10].Value = model.children_condition; parameters[11].Value = model.remarks; parameters[12].Value = model.customer_ukey; parameters[13].Value = model.spouse_name; parameters[14].Value = model.spouse_identifyNo; parameters[15].Value = model.spouse_sex; parameters[16].Value = model.spouse_birthday; parameters[17].Value = model.account_address; parameters[18].Value = model.customer_address; parameters[19].Value = model.post_code; parameters[20].Value = model.waiter_name; parameters[21].Value = model.customer_belongs; parameters[22].Value = model.neighborhood_phone; parameters[23].Value = model.machine_no; parameters[24].Value = model.owned_property; parameters[25].Value = model.property_phone; parameters[26].Value = model.police_belongs; parameters[27].Value = model.police_phone; parameters[28].Value = model.use_status; parameters[29].Value = model.charge_kind; parameters[30].Value = model.F_IsDelete; parameters[31].Value = model.F_CreateTime; parameters[32].Value = model.icon; parameters[33].Value = model.F_UpdateTime; parameters[34].Value = model.F_ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } /// /// 删除一条数据 /// public bool Delete(int F_ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from T_Sys_Customer "); strSql.Append(" where F_ID=@F_ID"); SqlParameter[] parameters = { new SqlParameter("@F_ID", SqlDbType.Int,4) }; parameters[0].Value = F_ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } /// /// 批量删除数据 /// public bool DeleteList(string F_IDlist) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from T_Sys_Customer "); strSql.Append(" where F_ID in (" + F_IDlist + ") "); int rows = DbHelperSQL.ExecuteSql(strSql.ToString()); if (rows > 0) { return true; } else { return false; } } /// /// 得到一个对象实体 /// public CallCenterApi.Model.T_Sys_Customer GetModel(int F_ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 F_ID,customer_no,customer_name,identify_no,customer_sex,customer_birthday,customer_phone,customer_mobile,customer_number,ambulance_enter,live_condition,children_condition,remarks,customer_ukey,spouse_name,spouse_identifyNo,spouse_sex,spouse_birthday,account_address,customer_address,post_code,waiter_name,customer_belongs,neighborhood_phone,machine_no,owned_property,property_phone,police_belongs,police_phone,use_status,charge_kind,F_IsDelete,F_CreateTime,F_UpdateTime,icon from T_Sys_Customer "); strSql.Append(" where F_ID=@F_ID"); SqlParameter[] parameters = { new SqlParameter("@F_ID", SqlDbType.Int,4) }; parameters[0].Value = F_ID; CallCenterApi.Model.T_Sys_Customer model = new CallCenterApi.Model.T_Sys_Customer(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } } /// /// 得到一个对象实体 /// public CallCenterApi.Model.T_Sys_Customer DataRowToModel(DataRow row) { CallCenterApi.Model.T_Sys_Customer model = new CallCenterApi.Model.T_Sys_Customer(); if (row != null) { if (row["F_ID"] != null && row["F_ID"].ToString() != "") { model.F_ID = int.Parse(row["F_ID"].ToString()); } if (row["customer_no"] != null) { model.customer_no = row["customer_no"].ToString(); } if (row["customer_name"] != null) { model.customer_name = row["customer_name"].ToString(); } if (row["identify_no"] != null) { model.identify_no = row["identify_no"].ToString(); } if (row["customer_sex"] != null) { model.customer_sex = row["customer_sex"].ToString(); } if (row["customer_birthday"] != null) { model.customer_birthday = row["customer_birthday"].ToString(); } if (row["customer_phone"] != null) { model.customer_phone = row["customer_phone"].ToString(); } if (row["customer_mobile"] != null) { model.customer_mobile = row["customer_mobile"].ToString(); } if (row["customer_number"] != null) { model.customer_number = row["customer_number"].ToString(); } if (row["ambulance_enter"] != null) { model.ambulance_enter = row["ambulance_enter"].ToString(); } if (row["live_condition"] != null) { model.live_condition = row["live_condition"].ToString(); } if (row["children_condition"] != null) { model.children_condition = row["children_condition"].ToString(); } if (row["remarks"] != null) { model.remarks = row["remarks"].ToString(); } if (row["customer_ukey"] != null) { model.customer_ukey = row["customer_ukey"].ToString(); } if (row["spouse_name"] != null) { model.spouse_name = row["spouse_name"].ToString(); } if (row["spouse_identifyNo"] != null) { model.spouse_identifyNo = row["spouse_identifyNo"].ToString(); } if (row["spouse_sex"] != null) { model.spouse_sex = row["spouse_sex"].ToString(); } if (row["spouse_birthday"] != null) { model.spouse_birthday = row["spouse_birthday"].ToString(); } if (row["account_address"] != null) { model.account_address = row["account_address"].ToString(); } if (row["customer_address"] != null) { model.customer_address = row["customer_address"].ToString(); } if (row["post_code"] != null) { model.post_code = row["post_code"].ToString(); } if (row["waiter_name"] != null) { model.waiter_name = row["waiter_name"].ToString(); } if (row["customer_belongs"] != null) { model.customer_belongs = row["customer_belongs"].ToString(); } if (row["neighborhood_phone"] != null) { model.neighborhood_phone = row["neighborhood_phone"].ToString(); } if (row["machine_no"] != null) { model.machine_no = row["machine_no"].ToString(); } if (row["owned_property"] != null) { model.owned_property = row["owned_property"].ToString(); } if (row["property_phone"] != null) { model.property_phone = row["property_phone"].ToString(); } if (row["police_belongs"] != null) { model.police_belongs = row["police_belongs"].ToString(); } if (row["police_phone"] != null) { model.police_phone = row["police_phone"].ToString(); } if (row["use_status"] != null) { model.use_status = row["use_status"].ToString(); } if (row["charge_kind"] != null) { model.charge_kind = row["charge_kind"].ToString(); } if (row["F_IsDelete"] != null && row["F_IsDelete"].ToString() != "") { model.F_IsDelete = int.Parse(row["F_IsDelete"].ToString()); } if (row["F_CreateTime"] != null && row["F_CreateTime"].ToString() != "") { model.F_CreateTime = DateTime.Parse(row["F_CreateTime"].ToString()); } if (row["F_UpdateTime"] != null && row["F_UpdateTime"].ToString() != "") { model.F_UpdateTime = DateTime.Parse(row["F_UpdateTime"].ToString()); } if (row["icon"] != null) { model.icon = row["icon"].ToString(); } } return model; } /// /// 获得数据列表 /// public DataSet GetList(string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select F_ID,customer_no,customer_name,identify_no,customer_sex,customer_birthday,customer_phone,customer_mobile,customer_number,ambulance_enter,live_condition,children_condition,remarks,customer_ukey,spouse_name,spouse_identifyNo,spouse_sex,spouse_birthday,account_address,customer_address,post_code,waiter_name,customer_belongs,neighborhood_phone,machine_no,owned_property,property_phone,police_belongs,police_phone,use_status,charge_kind,F_IsDelete,F_CreateTime,F_UpdateTime,icon "); strSql.Append(" FROM T_Sys_Customer "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } return DbHelperSQL.Query(strSql.ToString()); } /// /// 获得前几行数据 /// public DataSet GetList(int Top, string strWhere, string filedOrder) { StringBuilder strSql = new StringBuilder(); strSql.Append("select "); if (Top > 0) { strSql.Append(" top " + Top.ToString()); } strSql.Append(" F_ID,customer_no,customer_name,identify_no,customer_sex,customer_birthday,customer_phone,customer_mobile,customer_number,ambulance_enter,live_condition,children_condition,remarks,customer_ukey,spouse_name,spouse_identifyNo,spouse_sex,spouse_birthday,account_address,customer_address,post_code,waiter_name,customer_belongs,neighborhood_phone,machine_no,owned_property,property_phone,police_belongs,police_phone,use_status,charge_kind,F_IsDelete,F_CreateTime,F_UpdateTime,icon "); strSql.Append(" FROM T_Sys_Customer "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } strSql.Append(" order by " + filedOrder); return DbHelperSQL.Query(strSql.ToString()); } /// /// 获取记录总数 /// public int GetRecordCount(string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select count(1) FROM T_Sys_Customer "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } object obj = DbHelperSQL.GetSingle(strSql.ToString()); if (obj == null) { return 0; } else { return Convert.ToInt32(obj); } } /// /// 分页获取数据列表 /// public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex) { StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT * FROM ( "); strSql.Append(" SELECT ROW_NUMBER() OVER ("); if (!string.IsNullOrEmpty(orderby.Trim())) { strSql.Append("order by T." + orderby); } else { strSql.Append("order by T.F_ID desc"); } strSql.Append(")AS Row, T.* from T_Sys_Customer T "); if (!string.IsNullOrEmpty(strWhere.Trim())) { strSql.Append(" WHERE " + strWhere); } strSql.Append(" ) TT"); strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex); return DbHelperSQL.Query(strSql.ToString()); } /* /// /// 分页获取数据列表 /// public DataSet GetList(int PageSize,int PageIndex,string strWhere) { SqlParameter[] parameters = { new SqlParameter("@tblName", SqlDbType.VarChar, 255), new SqlParameter("@fldName", SqlDbType.VarChar, 255), new SqlParameter("@PageSize", SqlDbType.Int), new SqlParameter("@PageIndex", SqlDbType.Int), new SqlParameter("@IsReCount", SqlDbType.Bit), new SqlParameter("@OrderType", SqlDbType.Bit), new SqlParameter("@strWhere", SqlDbType.VarChar,1000), }; parameters[0].Value = "T_Sys_Customer"; parameters[1].Value = "F_ID"; parameters[2].Value = PageSize; parameters[3].Value = PageIndex; parameters[4].Value = 0; parameters[5].Value = 0; parameters[6].Value = strWhere; return CallCenterApi.RunProcedure("UP_GetRecordByPage",parameters,"ds"); }*/ #endregion BasicMethod #region ExtensionMethod #endregion ExtensionMethod } }