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_Rec_RegRecords /// public partial class T_Rec_RegRecords { public T_Rec_RegRecords() { } #region Method /// /// 是否存在该记录 /// public bool Exists(int F_ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select count(1) from T_Rec_RegRecords"); 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_Rec_RegRecords model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into T_Rec_RegRecords("); strSql.Append(@"F_RecCode,F_CusID,F_Type,F_Direction,F_Complained,F_Content, F_Remark,F_CreateBy,F_CreateOn,F_IsDelete,F_DeleteOn,F_DeleteBy,F_Tel,F_CallId, F_userName,F_userPhone,F_userSex,F_userProvince,F_userCity,F_userArea,F_ProblemType,F_Unit, F_UnitOffice,F_CaseParty,F_CitizensType,F_PutRecord,F_ZXZType )"); strSql.Append(" values ("); strSql.Append(@"@F_RecCode,@F_CusID,@F_Type,@F_Direction,@F_Complained,@F_Content, @F_Remark,@F_CreateBy,@F_CreateOn,@F_IsDelete,@F_DeleteOn,@F_DeleteBy,@F_Tel,@F_CallId, @F_userName,@F_userPhone,@F_userSex,@F_userProvince,@F_userCity,@F_userArea,@F_ProblemType,@F_Unit, @F_UnitOffice,@F_CaseParty,@F_CitizensType,@F_PutRecord,@F_ZXZType )"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@F_RecCode", SqlDbType.NVarChar,50), new SqlParameter("@F_CusID", SqlDbType.Int,4), new SqlParameter("@F_Type", SqlDbType.Int,4), new SqlParameter("@F_Direction", SqlDbType.Int,4), new SqlParameter("@F_Complained", SqlDbType.VarChar,2000), new SqlParameter("@F_Content", SqlDbType.VarChar), new SqlParameter("@F_Remark", SqlDbType.VarChar), new SqlParameter("@F_CreateBy", SqlDbType.VarChar,50), new SqlParameter("@F_CreateOn", SqlDbType.DateTime), new SqlParameter("@F_IsDelete", SqlDbType.Int,4), new SqlParameter("@F_DeleteOn", SqlDbType.VarChar,50), new SqlParameter("@F_DeleteBy", SqlDbType.DateTime), new SqlParameter("@F_Tel", SqlDbType.VarChar,200), new SqlParameter("@F_CallId", SqlDbType.VarChar,50), new SqlParameter("@F_userName", SqlDbType.VarChar,50), new SqlParameter("@F_userPhone", SqlDbType.VarChar,50), new SqlParameter("@F_userSex", SqlDbType.VarChar,50), new SqlParameter("@F_userProvince", SqlDbType.VarChar,50), new SqlParameter("@F_userCity", SqlDbType.VarChar,50), new SqlParameter("@F_userArea", SqlDbType.VarChar,50), new SqlParameter("@F_ProblemType", SqlDbType.VarChar,50) , new SqlParameter("@F_Unit", SqlDbType.VarChar,50), new SqlParameter("@F_UnitOffice", SqlDbType.VarChar,50), new SqlParameter("@F_CaseParty", SqlDbType.VarChar,50), new SqlParameter("@F_CitizensType", SqlDbType.VarChar,50), new SqlParameter("@F_PutRecord", SqlDbType.VarChar,50) , new SqlParameter("@F_ZXZType", SqlDbType.VarChar,50) }; parameters[0].Value = model.F_RecCode; parameters[1].Value = model.F_CusID; parameters[2].Value = model.F_Type; parameters[3].Value = model.F_Direction; parameters[4].Value = model.F_Complained; parameters[5].Value = model.F_Content; parameters[6].Value = model.F_Remark; parameters[7].Value = model.F_CreateBy; parameters[8].Value = model.F_CreateOn; parameters[9].Value = model.F_IsDelete; parameters[10].Value = model.F_DeleteOn; parameters[11].Value = model.F_DeleteBy; parameters[12].Value = model.F_Tel; parameters[13].Value = model.F_CallId; parameters[14].Value = model.F_userName; parameters[15].Value = model.F_userPhone; parameters[16].Value = model.F_userSex; parameters[17].Value = model.F_userProvince; parameters[18].Value = model.F_userCity; parameters[19].Value = model.F_userArea; parameters[20].Value = model.F_ProblemType; parameters[21].Value = model.F_Unit; parameters[22].Value = model.F_UnitOffice; parameters[23].Value = model.F_CaseParty; parameters[24].Value = model.F_CitizensType; parameters[25].Value = model.F_PutRecord; parameters[26].Value = model.F_ZXZType; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return 0; } else { return Convert.ToInt32(obj); } } /// /// 更新一条数据 /// public bool Update(CallCenterApi.Model.T_Rec_RegRecords model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_Rec_RegRecords set "); strSql.Append("F_RecCode=@F_RecCode,"); strSql.Append("F_CusID=@F_CusID,"); strSql.Append("F_Type=@F_Type,"); strSql.Append("F_Direction=@F_Direction,"); strSql.Append("F_Complained=@F_Complained,"); strSql.Append("F_Content=@F_Content,"); strSql.Append("F_Remark=@F_Remark,"); strSql.Append("F_CreateBy=@F_CreateBy,"); strSql.Append("F_CreateOn=@F_CreateOn,"); strSql.Append("F_IsDelete=@F_IsDelete,"); strSql.Append("F_DeleteOn=@F_DeleteOn,"); strSql.Append("F_DeleteBy=@F_DeleteBy,"); strSql.Append("F_Tel=@F_Tel,"); strSql.Append("F_CallId=@F_CallId"); strSql.Append("F_userName =@F_userName,"); strSql.Append("F_userPhone =@F_userPhone,"); strSql.Append("F_userSex =@F_userSex,"); strSql.Append("F_userProvince=@F_userProvince,"); strSql.Append("F_userCity =@F_userCity,"); strSql.Append("F_userArea =@F_userArea,"); strSql.Append("F_ProblemType =@F_ProblemType,"); strSql.Append("F_Unit =@F_Unit, "); strSql.Append("F_UnitOffice =@F_UnitOffice,"); strSql.Append("F_CaseParty =@F_CaseParty,"); strSql.Append("F_CitizensType=@F_CitizensType,"); strSql.Append("F_PutRecord =@F_PutRecord,"); strSql.Append("F_ZXZType =@F_ZXZType,"); strSql.Append(" where F_ID=@F_ID"); SqlParameter[] parameters = { new SqlParameter("@F_RecCode", SqlDbType.NVarChar,50), new SqlParameter("@F_CusID", SqlDbType.Int,4), new SqlParameter("@F_Type", SqlDbType.Int,4), new SqlParameter("@F_Direction", SqlDbType.Int,4), new SqlParameter("@F_Complained", SqlDbType.VarChar,2000), new SqlParameter("@F_Content", SqlDbType.VarChar), new SqlParameter("@F_Remark", SqlDbType.VarChar), new SqlParameter("@F_CreateBy", SqlDbType.VarChar,50), new SqlParameter("@F_CreateOn", SqlDbType.DateTime), new SqlParameter("@F_IsDelete", SqlDbType.Int,4), new SqlParameter("@F_DeleteOn", SqlDbType.VarChar,50), new SqlParameter("@F_DeleteBy", SqlDbType.DateTime), new SqlParameter("@F_Tel", SqlDbType.VarChar,200), new SqlParameter("@F_CallId", SqlDbType.VarChar,50), new SqlParameter("@F_ID", SqlDbType.Int,4), new SqlParameter("@F_userName", SqlDbType.VarChar,50), new SqlParameter("@F_userPhone", SqlDbType.VarChar,50), new SqlParameter("@F_userSex", SqlDbType.VarChar,50), new SqlParameter("@F_userProvince", SqlDbType.VarChar,50), new SqlParameter("@F_userCity", SqlDbType.VarChar,50), new SqlParameter("@F_userArea", SqlDbType.VarChar,50), new SqlParameter("@F_ProblemType", SqlDbType.VarChar,50) , new SqlParameter("@F_Unit", SqlDbType.VarChar,50), new SqlParameter("@F_UnitOffice", SqlDbType.VarChar,50), new SqlParameter("@F_CaseParty", SqlDbType.VarChar,50), new SqlParameter("@F_CitizensType", SqlDbType.VarChar,50), new SqlParameter("@F_PutRecord", SqlDbType.VarChar,50), new SqlParameter("@F_ZXZType", SqlDbType.VarChar,50) }; parameters[0].Value = model.F_RecCode; parameters[1].Value = model.F_CusID; parameters[2].Value = model.F_Type; parameters[3].Value = model.F_Direction; parameters[4].Value = model.F_Complained; parameters[5].Value = model.F_Content; parameters[6].Value = model.F_Remark; parameters[7].Value = model.F_CreateBy; parameters[8].Value = model.F_CreateOn; parameters[9].Value = model.F_IsDelete; parameters[10].Value = model.F_DeleteOn; parameters[11].Value = model.F_DeleteBy; parameters[12].Value = model.F_Tel; parameters[13].Value = model.F_CallId; parameters[14].Value = model.F_ID; parameters[14].Value = model.F_userName; parameters[15].Value = model.F_userPhone; parameters[16].Value = model.F_userSex; parameters[17].Value = model.F_userProvince; parameters[18].Value = model.F_userCity; parameters[19].Value = model.F_userArea; parameters[20].Value = model.F_ProblemType; parameters[21].Value = model.F_Unit; parameters[22].Value = model.F_UnitOffice; parameters[23].Value = model.F_CaseParty; parameters[24].Value = model.F_CitizensType; parameters[25].Value = model.F_PutRecord; parameters[26].Value = model.F_ZXZType; 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_Rec_RegRecords "); 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_Rec_RegRecords "); 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_Rec_RegRecords GetModel(int F_ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 * from T_Rec_RegRecords "); strSql.Append(" where F_ID=@F_ID"); SqlParameter[] parameters = { new SqlParameter("@F_ID", SqlDbType.Int,4) }; parameters[0].Value = F_ID; CallCenterApi.Model.T_Rec_RegRecords model = new CallCenterApi.Model.T_Rec_RegRecords(); 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_Rec_RegRecords DataRowToModel(DataRow row) { CallCenterApi.Model.T_Rec_RegRecords model = new CallCenterApi.Model.T_Rec_RegRecords(); if (row != null) { if (row["F_ID"] != null && row["F_ID"].ToString() != "") { model.F_ID = int.Parse(row["F_ID"].ToString()); } if (row["F_RecCode"] != null && row["F_RecCode"].ToString() != "") { model.F_RecCode = row["F_RecCode"].ToString(); } if (row["F_CusID"] != null && row["F_CusID"].ToString() != "") { model.F_CusID = int.Parse(row["F_CusID"].ToString()); } if (row["F_Type"] != null && row["F_Type"].ToString() != "") { model.F_Type = int.Parse(row["F_Type"].ToString()); } if (row["F_Direction"] != null && row["F_Direction"].ToString() != "") { model.F_Direction = int.Parse(row["F_Direction"].ToString()); } if (row["F_Complained"] != null && row["F_Complained"].ToString() != "") { model.F_Complained = row["F_Complained"].ToString(); } if (row["F_Content"] != null && row["F_Content"].ToString() != "") { model.F_Content = row["F_Content"].ToString(); } if (row["F_Remark"] != null && row["F_Remark"].ToString() != "") { model.F_Remark = row["F_Remark"].ToString(); } if (row["F_CreateBy"] != null && row["F_CreateBy"].ToString() != "") { model.F_CreateBy = row["F_CreateBy"].ToString(); } if (row["F_CreateOn"] != null && row["F_CreateOn"].ToString() != "") { model.F_CreateOn = DateTime.Parse(row["F_CreateOn"].ToString()); } if (row["F_IsDelete"] != null && row["F_IsDelete"].ToString() != "") { model.F_IsDelete = int.Parse(row["F_IsDelete"].ToString()); } if (row["F_DeleteOn"] != null && row["F_DeleteOn"].ToString() != "") { model.F_DeleteOn = row["F_DeleteOn"].ToString(); } if (row["F_DeleteBy"] != null && row["F_DeleteBy"].ToString() != "") { model.F_DeleteBy = DateTime.Parse(row["F_DeleteBy"].ToString()); } if (row["F_Tel"] != null && row["F_Tel"].ToString() != "") { model.F_Tel = row["F_Tel"].ToString(); } if (row["F_CallId"] != null && row["F_CallId"].ToString() != "") { model.F_CallId = row["F_CallId"].ToString(); } if (row["F_userName"] != null && row["F_userName"].ToString() != "") { model.F_userName = row["F_userName"].ToString(); } if (row["F_userPhone"] != null && row["F_userPhone"].ToString() != "") { model.F_userPhone = row["F_userPhone"].ToString(); } if (row["F_userSex"] != null && row["F_userSex"].ToString() != "") { model.F_userSex = row["F_userSex"].ToString(); } if (row["F_userProvince"] != null && row["F_userProvince"].ToString() != "") { model.F_userProvince = row["F_userProvince"].ToString(); } if (row["F_userCity"] != null && row["F_userCity"].ToString() != "") { model.F_userCity = row["F_userCity"].ToString(); } if (row["F_userArea"] != null && row["F_userArea"].ToString() != "") { model.F_userArea = row["F_userArea"].ToString(); } if (row["F_ProblemType"] != null && row["F_ProblemType"].ToString() != "") { model.F_ProblemType = row["F_ProblemType"].ToString(); } if (row["F_Unit"] != null && row["F_Unit"].ToString() != "") { model.F_Unit = row["F_Unit"].ToString(); } if (row["F_UnitOffice"] != null && row["F_UnitOffice"].ToString() != "") { model.F_UnitOffice = row["F_UnitOffice"].ToString(); } if (row["F_CaseParty"] != null && row["F_CaseParty"].ToString() != "") { model.F_CaseParty = row["F_CaseParty"].ToString(); } if (row["F_CitizensType"] != null && row["F_CitizensType"].ToString() != "") { model.F_CitizensType = row["F_CitizensType"].ToString(); } if (row["F_PutRecord"] != null && row["F_PutRecord"].ToString() != "") { model.F_PutRecord = row["F_PutRecord"].ToString(); } if (row["F_ZXZType"] != null && row["F_ZXZType"].ToString() != "") { model.F_ZXZType = row["F_ZXZType"].ToString(); } } return model; } /// /// 获得数据列表 /// public DataSet GetList(string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * "); strSql.Append(" FROM T_Rec_RegRecords "); 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(" * "); strSql.Append(" FROM T_Rec_RegRecords "); 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_Rec_RegRecords "); 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_Rec_RegRecords 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()); } #endregion Method } }