public void BindData() { int recid; if (int.TryParse(RecId, out recid)) { Entities.BlackWhiteList model = BLL.BlackWhiteList.Instance.GetModel(recid); edit_txtPhoneNum.Value = model.PhoneNum; edit_txtYouXiaoQi.Value = model.ExpiryDate.ToString("yyyy-MM-dd"); if (model.CallType == 1) //呼入 { edit_ckb_calltype_1.Checked = true; } if (model.CallType == 2) //呼出 { edit_ckb_calltype_2.Checked = true; } if (model.CallType == 3) //呼入和呼出 { edit_ckb_calltype_1.Checked = true; edit_ckb_calltype_2.Checked = true; } strReason = model.Reason; cdids = model.CDIDS; } }
private void BindModelData(int recid) { strRecID = recid.ToString(); Entities.BlackWhiteList model = BLL.BlackWhiteList.Instance.GetModel(recid); edit_txtPhoneNum.Value = model.PhoneNum; edit_txtYouXiaoQi.Value = model.ExpiryDate.ToString("yyyy-MM-dd"); if (model.CallType == 1) //呼入 { edit_ckb_calltype_1.Checked = true; } if (model.CallType == 2) //呼出 { edit_ckb_calltype_2.Checked = true; } if (model.CallType == 3) //呼入和呼出 { edit_ckb_calltype_1.Checked = true; edit_ckb_calltype_2.Checked = true; } strReason = model.Reason; cdids = model.CDIDS; txtCallID.Value = string.IsNullOrEmpty(CallId.Trim()) ? (model.CallID.HasValue ? model.CallID.Value.ToString() : "") : CallId.Trim(); selNoDisturbReason.SelectedIndex = model.CallOutNDType < 0 ? 0 : model.CallOutNDType; }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Entities.BlackWhiteList model) { StringBuilder strSql = new StringBuilder(); strSql.Append("INSERT INTO BlackWhiteList("); strSql.Append("Type,PhoneNum,EffectiveDate,ExpiryDate,CallType,CDIDS,Reason,SynchrodataStatus,CreateUserId,CreateDate,UpdateUserId,UpdateDate,Status,CallID,CallOutNDType)"); strSql.Append(" VALUES ("); strSql.Append("@Type,@PhoneNum,@EffectiveDate,@ExpiryDate,@CallType,@CDIDS,@Reason,@SynchrodataStatus,@CreateUserId,@CreateDate,@UpdateUserId,@UpdateDate,@Status,@CallID,@CallOutNDType)"); strSql.Append(";SELECT @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Type", SqlDbType.Int, 4), new SqlParameter("@PhoneNum", SqlDbType.VarChar, 20), new SqlParameter("@EffectiveDate", SqlDbType.DateTime), new SqlParameter("@ExpiryDate", SqlDbType.DateTime), new SqlParameter("@CallType", SqlDbType.Int, 4), new SqlParameter("@CDIDS", SqlDbType.Int, 4), new SqlParameter("@Reason", SqlDbType.NVarChar, 500), new SqlParameter("@SynchrodataStatus", SqlDbType.Int, 4), new SqlParameter("@CreateUserId", SqlDbType.Int, 4), new SqlParameter("@CreateDate", SqlDbType.DateTime), new SqlParameter("@UpdateUserId", SqlDbType.Int, 4), new SqlParameter("@UpdateDate", SqlDbType.DateTime), new SqlParameter("@Status", SqlDbType.Int, 4), new SqlParameter("@CallID", SqlDbType.BigInt), new SqlParameter("@CallOutNDType", SqlDbType.Int, 4) }; parameters[0].Value = model.Type; parameters[1].Value = model.PhoneNum; parameters[2].Value = model.EffectiveDate; parameters[3].Value = model.ExpiryDate; parameters[4].Value = model.CallType; parameters[5].Value = model.CDIDS; parameters[6].Value = model.Reason; parameters[7].Value = model.SynchrodataStatus; parameters[8].Value = model.CreateUserId; parameters[9].Value = model.CreateDate; parameters[10].Value = model.UpdateUserId; parameters[11].Value = model.UpdateDate; parameters[12].Value = model.Status; parameters[13].Value = model.CallID; parameters[14].Value = model.CallOutNDType; object obj = SqlHelper.ExecuteScalar(CONNECTIONSTRINGS, CommandType.Text, strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
private void AddData(out string msg) { msg = string.Empty; try { string[] cdidsArr = CDIDS2.Split(','); for (int i = 0; i < cdidsArr.Length; i++) { if (BLL.BlackWhiteList.Instance.IsPhoneNumberCDIDExist(PhoneNum, int.Parse(cdidsArr[i]))) { msg = "{result:'no',msg:'电话号码已添加过,请核对数据'}"; return; } } Entities.BlackWhiteList model = new Entities.BlackWhiteList(); model.Type = int.Parse(Type); model.PhoneNum = PhoneNum; model.EffectiveDate = DateTime.Now; model.ExpiryDate = GetExpiryDate(ExpiryDate); model.CallType = int.Parse(CallType); int cdids; if (int.TryParse(CDIDS, out cdids)) { model.CDIDS = cdids; } model.Reason = Reason; model.SynchrodataStatus = 0; model.CreateUserId = BLL.Util.GetLoginUserID(); model.CreateDate = DateTime.Now; model.Status = 0; int retVal = BLL.BlackWhiteList.Instance.Add(model); if (retVal > 0) { msg = "{result:'yes',msg:'保存成功'}"; } else { msg = "{result:'no',msg:'操作失败,请稍后再试'}"; } } catch (Exception ex) { msg = "{result:'no',msg:'" + ex.Message + "'}"; } }
/// 新增或者更新数据 /// <summary> /// 新增或者更新数据 /// </summary> /// <param name="dt"></param> /// <returns></returns> public int UpdateDataForSynch(DataTable dt) { int successCoun = 0; try { for (int i = 0; i < dt.Rows.Count; i++) { Entities.BlackWhiteList model = new Entities.BlackWhiteList(); model.RecId = Convert.ToInt32(dt.Rows[i]["RecId"]); model.Type = Convert.ToInt32(dt.Rows[i]["Type"]); model.PhoneNum = dt.Rows[i]["PhoneNum"].ToString(); model.EffectiveDate = (dt.Rows[i]["EffectiveDate"] == null ? Constant.DATE_INVALID_VALUE : Convert.ToDateTime(dt.Rows[i]["EffectiveDate"])); model.ExpiryDate = (dt.Rows[i]["ExpiryDate"] == null ? Constant.DATE_INVALID_VALUE : Convert.ToDateTime(dt.Rows[i]["ExpiryDate"])); model.CallType = Convert.ToInt32(dt.Rows[i]["CallType"]); model.CDIDS = Convert.ToInt32(dt.Rows[i]["CDIDS"]); model.Reason = dt.Rows[i]["Reason"].ToString(); model.SynchrodataStatus = 2; model.CreateUserId = (dt.Rows[i]["CreateUserId"] == null ? Constant.INT_INVALID_VALUE : Convert.ToInt32(dt.Rows[i]["CreateUserId"])); model.CreateDate = (dt.Rows[i]["CreateDate"] == null ? Constant.DATE_INVALID_VALUE : Convert.ToDateTime(dt.Rows[i]["CreateDate"])); model.UpdateDate = (dt.Rows[i]["UpdateDate"] == null ? Constant.DATE_INVALID_VALUE : Convert.ToDateTime(dt.Rows[i]["UpdateDate"])); model.UpdateUserId = (dt.Rows[i]["UpdateUserId"] == null ? Constant.INT_INVALID_VALUE : Convert.ToInt32(dt.Rows[i]["UpdateUserId"])); model.Status = Convert.ToInt32(dt.Rows[i]["Status"]); if (Dal.BlackWhiteList.Instance.IsRecIdExistForSynch(Convert.ToInt32(dt.Rows[i]["RecId"])) > 0) { if (Dal.BlackWhiteList.Instance.UpdateForSynch(model)) { successCoun++; } } else { if (Dal.BlackWhiteList.Instance.AddForSynch(model) > 0) { successCoun++; } } } } catch (Exception ex) { BLL.Loger.Log4Net.Error("同步修改的黑白名单数据时出现异常:" + ex.Message); } return(successCoun); }
/// 增加一条数据 /// <summary> /// 增加一条数据 /// </summary> public int AddForSynch(Entities.BlackWhiteList model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into dbo.BlackWhiteList ("); strSql.Append("RecId,Type,PhoneNum,EffectiveDate,ExpiryDate,CallType,CDIDS,Reason,SynchrodataStatus,CreateUserId,CreateDate,UpdateUserId,UpdateDate,Status)"); strSql.Append(" values ("); strSql.Append("@RecId,@Type,@PhoneNum,@EffectiveDate,@ExpiryDate,@CallType,@CDIDS,@Reason,@SynchrodataStatus,@CreateUserId,@CreateDate,@UpdateUserId,@UpdateDate,@Status)"); SqlParameter[] parameters = { new SqlParameter("@RecId", SqlDbType.Int, 4), new SqlParameter("@Type", SqlDbType.Int, 4), new SqlParameter("@PhoneNum", SqlDbType.VarChar, 20), new SqlParameter("@EffectiveDate", SqlDbType.DateTime), new SqlParameter("@ExpiryDate", SqlDbType.DateTime), new SqlParameter("@CallType", SqlDbType.Int, 4), new SqlParameter("@CDIDS", SqlDbType.Int, 4), new SqlParameter("@Reason", SqlDbType.NVarChar, 500), new SqlParameter("@SynchrodataStatus", SqlDbType.Int, 4), new SqlParameter("@CreateUserId", SqlDbType.Int, 4), new SqlParameter("@CreateDate", SqlDbType.DateTime), new SqlParameter("@UpdateUserId", SqlDbType.Int, 4), new SqlParameter("@UpdateDate", SqlDbType.DateTime), new SqlParameter("@Status", SqlDbType.Int, 4) }; parameters[0].Value = model.RecId; parameters[1].Value = model.Type; parameters[2].Value = model.PhoneNum; parameters[3].Value = model.EffectiveDate; parameters[4].Value = model.ExpiryDate; parameters[5].Value = model.CallType; parameters[6].Value = model.CDIDS; parameters[7].Value = model.Reason; parameters[8].Value = model.SynchrodataStatus; parameters[9].Value = model.CreateUserId; parameters[10].Value = model.CreateDate; parameters[11].Value = model.UpdateUserId; parameters[12].Value = model.UpdateDate; parameters[13].Value = model.Status; return(SqlHelper.ExecuteNonQuery(ConnectionStrings_Holly_Business, CommandType.Text, strSql.ToString(), parameters)); }
/// 更新一条免打扰数据 /// <summary> /// 更新一条免打扰数据 /// </summary> public bool UpdateNoDisturbData(Entities.BlackWhiteList model) { SqlParameter[] parameters = { new SqlParameter("@RecId", SqlDbType.Int, 4), new SqlParameter("@PhoneNum", SqlDbType.VarChar, 20), new SqlParameter("@CallType", SqlDbType.Int, 4), new SqlParameter("@Status", SqlDbType.Int, 4), new SqlParameter("@ExpiryDate", SqlDbType.DateTime), new SqlParameter("@CDIDS", SqlDbType.Int, 4), new SqlParameter("@Reason", SqlDbType.NVarChar, 500), new SqlParameter("@UpdateUserId", SqlDbType.Int, 4), new SqlParameter("@UpdateDate", SqlDbType.DateTime), new SqlParameter("@SynchrodataStatus", SqlDbType.Int, 4), new SqlParameter("@CallID", SqlDbType.BigInt), new SqlParameter("@CallOutNDType", SqlDbType.Int, 4), new SqlParameter("@CreateDate", SqlDbType.DateTime), new SqlParameter("@CreateUserId", SqlDbType.Int, 4), new SqlParameter("@BGID", SqlDbType.Int, 4), new SqlParameter("@backvalue", SqlDbType.Int, 4) }; parameters[0].Value = model.RecId; parameters[1].Value = model.PhoneNum; parameters[2].Value = model.CallType; parameters[3].Value = model.Status; parameters[4].Value = model.ExpiryDate.ToString("yyyy-MM-dd 0:0:0"); parameters[5].Value = model.CDIDS; parameters[6].Value = model.Reason; parameters[7].Value = model.UpdateUserId; parameters[8].Value = model.UpdateDate; parameters[9].Value = model.SynchrodataStatus; parameters[10].Value = model.CallID; parameters[11].Value = model.CallOutNDType; parameters[12].Value = model.CreateDate.ToString("yyyy-MM-dd 0:0:0"); parameters[13].Value = model.CreateUserId; parameters[14].Value = model.BGID; parameters[15].Direction = ParameterDirection.Output; SqlHelper.ExecuteNonQuery(CONNECTIONSTRINGS, CommandType.StoredProcedure, "p_NoDisturbData_Update", parameters); return((int)(parameters[15].Value) == 1 ? true : false); }
/// <summary> /// 处理导入的数据 /// </summary> private bool DealDataImportedForBlack(string fileName, out string msg) { System.Diagnostics.Debug.WriteLine("[HandlerImport]DealDataImported begin..."); BLL.Loger.Log4Net.Info("[HandlerImport]DealDataImported begin..."); bool success = true; msg = ""; //(1)连接EXCEL文件 string ext = Path.GetExtension(fileName); string connStr = string.Empty; if (ext.ToLower() == ".xls") { connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + @fileName + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\""; } else { //throw new Exception("上传文件应为xls或者xlsx格式的文件"); //throw new Exception("上传文件应为xls格式的文件"); msg = "传文件应为xls格式的文件"; return(false); } List <BusinessTypeMod> modeBusinessType = new List <BusinessTypeMod>(); modeBusinessType = (List <BusinessTypeMod>)Newtonsoft.Json.JavaScriptConvert.DeserializeObject(BusinessTypeJSON, typeof(List <BusinessTypeMod>)); int userid = BLL.Util.GetLoginUserID(); Entities.EmployeeAgent employeeagent = BLL.EmployeeAgent.Instance.GetEmployeeAgentByUserID(userid); using (OleDbConnection conn = new OleDbConnection(connStr)) { conn.Open(); //返回Excel的架构,包括各个sheet表的名称,类型,创建时间和修改时间等 DataTable dtSheetName = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "Table" }); //包含excel中表名的字符串数组 string firstSheetName = dtSheetName.Rows[0]["TABLE_NAME"].ToString(); //读取第一个sheet填充数据sheetConfig.Name.Replace(".", "#") + "$" OleDbCommand command = new OleDbCommand("select * from [" + firstSheetName.Replace(".", "#") + "]", conn); IDataReader idr = command.ExecuteReader(); // string phone = Constant.STRING_INVALID_VALUE; //string IsReturnVisit = Constant.STRING_INVALID_VALUE; List <Entities.BlackWhiteList> myDataList = new List <Entities.BlackWhiteList>(); while (idr.Read()) { Entities.BlackWhiteList model = new Entities.BlackWhiteList(); try { model.Type = int.Parse(Type); if (!string.IsNullOrEmpty(idr[0].ToString().Trim())) { model.PhoneNum = idr[0].ToString().Trim(); } else { msg = "模板数据不能为空"; return(false); } if (!string.IsNullOrEmpty(idr[1].ToString().Trim())) { model.EffectiveDate = DateTime.Parse(idr[1].ToString().Trim()); } else { msg = "模板数据不能为空"; return(false); } if (!string.IsNullOrEmpty(idr[2].ToString().Trim())) { model.ExpiryDate = DateTime.Parse(idr[2].ToString().Trim()); } else { msg = "模板数据不能为空"; return(false); } if (!string.IsNullOrEmpty(idr[3].ToString().Trim())) { int calltype = 0; if (idr[3].ToString().Trim().Contains("呼入")) { calltype = 1; } if (idr[3].ToString().Trim().Contains("呼出")) { calltype += 2; } if (calltype == 0) { msg = "模板数据异常,请检查模板数据"; return(false); } else { model.CallType = calltype; } } else { msg = "模板数据不能为空"; return(false); } if (!string.IsNullOrEmpty(idr[4].ToString().Trim())) { string cidsReal = idr[4].ToString().Replace(",", ",").Trim(); string[] businessnameArr = cidsReal.Split(','); int cdids = 0; for (int i = 0; i < businessnameArr.Length; i++) { for (int j = 0; j < modeBusinessType.Count; j++) { if (modeBusinessType[j].BusinessName == businessnameArr[i]) { if (BLL.BlackWhiteList.Instance.IsPhoneNumberCDIDExist(model.PhoneNum, int.Parse(modeBusinessType[j].BusinessRightValue))) { msg = "电话号码已添加过,请核对数据"; return(false); } cdids += int.Parse(modeBusinessType[j].BusinessRightValue); } } } if (cdids == 0) { msg = "模板数据异常,请检查模板数据"; return(false); } else { model.CDIDS = cdids; } } else { msg = "模板数据不能为空"; return(false); } if (!string.IsNullOrEmpty(idr[5].ToString().Trim())) { model.Reason = idr[5].ToString().Trim(); } else { msg = "模板数据不能为空"; return(false); } } catch (Exception ex) { msg = "模板数据异常,请检查模板数据"; return(false); } model.SynchrodataStatus = 0; model.CreateUserId = userid; model.CreateDate = DateTime.Now; model.UpdateUserId = Constant.INT_INVALID_VALUE; model.UpdateDate = Constant.DATE_INVALID_VALUE; model.Status = 0; if (employeeagent != null && employeeagent.BGID.HasValue) { model.BGID = employeeagent.BGID.Value; } myDataList.Add(model); } DataTable dtBW = BLL.Util.ListToDataTable(myDataList); BLL.BlackWhiteList.Instance.ImportData(dtBW); //return success; } //FileInfo fi = new FileInfo(fileName); //fi.Delete(); ClearFiles(fileName); return(success); }
private void UpdateData(out string msg) { msg = string.Empty; try { int recid; if (int.TryParse(RecId, out recid)) { string[] cdidsArr = CDIDS2.Split(','); for (int i = 0; i < cdidsArr.Length; i++) { if (BLL.BlackWhiteList.Instance.IsPhoneNumExist(PhoneNum, int.Parse(cdidsArr[i]), recid)) { msg = "{result:'no',msg:'电话号码已添加过,请核对数据'}"; return; } } Entities.BlackWhiteList model = BLL.BlackWhiteList.Instance.GetModel(recid); model.PhoneNum = PhoneNum; model.CallType = int.Parse(CallType); model.ExpiryDate = GetExpiryDate(ExpiryDate); int cdids; if (int.TryParse(CDIDS, out cdids)) { model.CDIDS = cdids; } model.Reason = Reason; model.UpdateDate = DateTime.Now; model.UpdateUserId = BLL.Util.GetLoginUserID(); model.SynchrodataStatus = 1; //此处的判断要除去当前的recid对应的数据行 //if (BLL.BlackWhiteList.Instance.IsPhoneNumberCDIDExist(model.PhoneNum, model.CDIDS)) //{ // msg = "电话号码已添加过,请核对数据"; // return; //} bool retVal = BLL.BlackWhiteList.Instance.Update(model); if (retVal) { msg = "{result:'yes',msg:'保存成功'}"; } else { msg = "{result:'no',msg:'操作失败,请稍后再试'}"; } } else { msg = "{result:'no',msg:'参数异常'}"; } } catch (Exception ex) { msg = "{result:'no',msg:'" + ex.Message + "'}"; } }
private void AddNoDisturbData(out string msg) { msg = string.Empty; try { int valPhoneNumIsNoDisturb = BLL.BlackWhiteList.Instance.PhoneNumIsNoDisturb(PhoneNum); if (valPhoneNumIsNoDisturb == 2) { int userid = BLL.Util.GetLoginUserID(); //增加免打扰号码 Entities.BlackWhiteList model = new Entities.BlackWhiteList(); model.Type = 0; model.PhoneNum = PhoneNum; model.EffectiveDate = DateTime.Now; model.ExpiryDate = GetExpiryDate(ExpiryDate); model.CallType = int.Parse(CallType); int cdids; if (int.TryParse(CDIDS, out cdids)) { model.CDIDS = cdids; } model.Reason = Reason; model.SynchrodataStatus = 0; model.CreateUserId = userid; model.CreateDate = DateTime.Now; model.Status = 0; long callid; if (long.TryParse(CallID, out callid)) { model.CallID = callid; } int calloutndtype; if (int.TryParse(NoDisturbReason, out calloutndtype)) { model.CallOutNDType = calloutndtype; } Entities.EmployeeAgent employeeagent = BLL.EmployeeAgent.Instance.GetEmployeeAgentByUserID(userid); if (employeeagent != null && employeeagent.BGID.HasValue) { model.BGID = employeeagent.BGID.Value; } int retVal = BLL.BlackWhiteList.Instance.AddNoDisturbData(model); if (retVal > 0) { msg = "{result:'yes',msg:'保存成功'}"; } else { msg = "{result:'no',msg:'操作失败,请稍后再试'}"; } } else if (valPhoneNumIsNoDisturb == -1) { //修改免打扰号码,需要传递RecID int backRecID = BLL.BlackWhiteList.Instance.GetRecIDByPhoneNumberAndType(PhoneNum, 0); if (backRecID > 0) { UpdateNoDisturbData(out msg, backRecID); } else { msg = "{result:'no',msg:'没有找到主键RecID,请稍后再试'}"; } } else if (valPhoneNumIsNoDisturb == 0 || valPhoneNumIsNoDisturb == 1) { msg = "{result:'no',msg:'此号码已被设置为免打扰号码,不能重复添加'}"; } else { msg = "{result:'no',msg:'对号码的判断失败,请稍后再试'}"; } } catch (Exception ex) { msg = "{result:'no',msg:'" + ex.Message + "'}"; } }
/// <summary> /// 更新免打扰记录信息 /// </summary> /// <param name="msg"></param> private void UpdateNoDisturbData(out string msg, int updateRecID = 0) { msg = string.Empty; try { int recid = 0; if (int.TryParse(RecId, out recid) || updateRecID > 0) { if (BLL.BlackWhiteList.Instance.PhoneNumIsNoDisturb(PhoneNum) == 2) { //增加免打扰号码 //AddNoDisturbData(out msg); msg = "{result:'no',msg:'此号码还不是免打扰号码,请将此号码先添加为免打扰号码'}"; } else { int userid = BLL.Util.GetLoginUserID();; if (updateRecID > 0) { recid = updateRecID; } Entities.BlackWhiteList model = BLL.BlackWhiteList.Instance.GetModel(recid); model.RecId = recid; model.PhoneNum = PhoneNum; model.CallType = int.Parse(CallType); if (model.Status == -1 || model.Status == 1) { model.CreateDate = DateTime.Now; model.CreateUserId = userid; } DateTime expireydate = GetExpiryDate(ExpiryDate); if (expireydate.ToString("yyyy-MM-dd").CompareTo(DateTime.Now.ToString("yyyy-MM-dd")) >= 0) { model.Status = 0; } else { model.Status = 1; } model.ExpiryDate = expireydate; int cdids; if (int.TryParse(CDIDS, out cdids)) { model.CDIDS = cdids; } model.Reason = Reason; model.UpdateDate = DateTime.Now; model.UpdateUserId = userid; model.SynchrodataStatus = 1; long callid; if (long.TryParse(CallID, out callid)) { model.CallID = callid; } else if (updateRecID > 0) { model.CallID = null; } int calloutndtype; if (int.TryParse(NoDisturbReason, out calloutndtype)) { model.CallOutNDType = calloutndtype; } Entities.EmployeeAgent employeeagent = BLL.EmployeeAgent.Instance.GetEmployeeAgentByUserID(userid); if (employeeagent != null && employeeagent.BGID.HasValue) { model.BGID = employeeagent.BGID.Value; } bool retVal = BLL.BlackWhiteList.Instance.UpdateNoDisturbData(model); if (retVal) { msg = "{result:'yes',msg:'保存成功'}"; } else { msg = "{result:'no',msg:'操作失败,请稍后再试'}"; } } } else { msg = "{result:'no',msg:'参数异常'}"; } } catch (Exception ex) { msg = "{result:'no',msg:'" + ex.Message + "'}"; } }
/// 增加一条免打扰数据 /// <summary> /// 增加一条免打扰数据 /// </summary> public int AddNoDisturbData(Entities.BlackWhiteList model) { return(Dal.BlackWhiteList.Instance.AddNoDisturbData(model)); }
/// 更新一条免打扰数据 /// <summary> /// 更新一条免打扰数据 /// </summary> public bool UpdateNoDisturbData(Entities.BlackWhiteList model) { return(Dal.BlackWhiteList.Instance.UpdateNoDisturbData(model)); }
public int Add(Entities.BlackWhiteList model) { return(Dal.BlackWhiteList.Instance.Add(model)); }
/// <summary> /// 得到一个对象实体 /// </summary> public Entities.BlackWhiteList DataRowToModel(DataRow row) { Entities.BlackWhiteList model = new Entities.BlackWhiteList(); if (row != null) { if (row["RecId"] != null && row["RecId"].ToString() != "") { model.RecId = int.Parse(row["RecId"].ToString()); } if (row["Type"] != null && row["Type"].ToString() != "") { model.Type = int.Parse(row["Type"].ToString()); } if (row["PhoneNum"] != null) { model.PhoneNum = row["PhoneNum"].ToString(); } if (row["EffectiveDate"] != null && row["EffectiveDate"].ToString() != "") { model.EffectiveDate = DateTime.Parse(row["EffectiveDate"].ToString()); } if (row["ExpiryDate"] != null && row["ExpiryDate"].ToString() != "") { model.ExpiryDate = DateTime.Parse(row["ExpiryDate"].ToString()); } if (row["CallType"] != null && row["CallType"].ToString() != "") { model.CallType = int.Parse(row["CallType"].ToString()); } if (row["CDIDS"] != null && row["CDIDS"].ToString() != "") { model.CDIDS = int.Parse(row["CDIDS"].ToString()); } if (row["Reason"] != null) { model.Reason = row["Reason"].ToString(); } if (row["SynchrodataStatus"] != null && row["SynchrodataStatus"].ToString() != "") { model.SynchrodataStatus = int.Parse(row["SynchrodataStatus"].ToString()); } if (row["CreateUserId"] != null && row["CreateUserId"].ToString() != "") { model.CreateUserId = int.Parse(row["CreateUserId"].ToString()); } if (row["CreateDate"] != null && row["CreateDate"].ToString() != "") { model.CreateDate = DateTime.Parse(row["CreateDate"].ToString()); } if (row["UpdateUserId"] != null && row["UpdateUserId"].ToString() != "") { model.UpdateUserId = int.Parse(row["UpdateUserId"].ToString()); } if (row["UpdateDate"] != null && row["UpdateDate"].ToString() != "") { model.UpdateDate = DateTime.Parse(row["UpdateDate"].ToString()); } if (row["Status"] != null && row["Status"].ToString() != "") { model.Status = int.Parse(row["Status"].ToString()); } if (row["CallID"] != null && row["CallID"].ToString() != "") { model.CallID = long.Parse(row["CallID"].ToString()); } if (row["CallOutNDType"] != null && row["CallOutNDType"].ToString() != "") { model.CallOutNDType = int.Parse(row["CallOutNDType"].ToString()); } } return(model); }
/// <summary> /// 处理导入的数据 /// </summary> private bool DealDataImported(string fileName, out string msg) { System.Diagnostics.Debug.WriteLine("[HandlerImport]DealDataImported begin..."); BLL.Loger.Log4Net.Info("[HandlerImport]DealDataImported begin..."); bool success = false; msg = ""; //(1)连接EXCEL文件 string ext = Path.GetExtension(fileName); string connStr = string.Empty; if (ext.ToLower() == ".xls") { connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + @fileName + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\""; } else { //throw new Exception("上传文件应为xls或者xlsx格式的文件"); throw new Exception("上传文件应为xls格式的文件"); } List <BusinessTypeMod> modeBusinessType = new List <BusinessTypeMod>(); modeBusinessType = (List <BusinessTypeMod>)Newtonsoft.Json.JavaScriptConvert.DeserializeObject(BusinessTypeJSON, typeof(List <BusinessTypeMod>)); int userid = BLL.Util.GetLoginUserID(); Entities.EmployeeAgent employeeagent = BLL.EmployeeAgent.Instance.GetEmployeeAgentByUserID(userid); DataTable tbNoDisturbReason = BLL.Util.GetEnumDataTable(typeof(Entities.NoDisturbReason)); using (OleDbConnection conn = new OleDbConnection(connStr)) { conn.Open(); //返回Excel的架构,包括各个sheet表的名称,类型,创建时间和修改时间等 DataTable dtSheetName = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "Table" }); //包含excel中表名的字符串数组 string firstSheetName = dtSheetName.Rows[0]["TABLE_NAME"].ToString(); //读取第一个sheet填充数据sheetConfig.Name.Replace(".", "#") + "$" OleDbCommand command = new OleDbCommand("select * from [" + firstSheetName.Replace(".", "#") + "]", conn); IDataReader idr = command.ExecuteReader(); // string phone = Constant.STRING_INVALID_VALUE; //string IsReturnVisit = Constant.STRING_INVALID_VALUE; List <Entities.BlackWhiteList> myDataList = new List <Entities.BlackWhiteList>(); int rowIndex = 0; while (idr.Read()) { rowIndex++; Entities.BlackWhiteList model = new Entities.BlackWhiteList(); int backVal; string innerMsg = ""; try { //1.电话号码验证 if (!string.IsNullOrEmpty(idr[0].ToString().Trim())) { if (!BLL.Util.IsNumber(idr[0].ToString().Trim().Replace("-", ""))) { innerMsg += "第" + rowIndex + "行数据:" + "“电话号码”格式不正确,只能由数字组成<br/>"; msg += innerMsg; continue; } backVal = BLL.BlackWhiteList.Instance.PhoneNumIsNoDisturb(idr[0].ToString().Trim().Replace("-", "")); if (backVal == 0 || backVal == 1) //没有考虑到已删除数据的处理 { innerMsg += "第" + rowIndex + "行数据:" + "“电话号码”(" + idr[0] + ")已添加过,请核对数据<br/>"; msg += innerMsg; continue; } model.PhoneNum = idr[0].ToString().Trim().Replace("-", ""); } else { innerMsg += "第" + rowIndex + "行数据:" + "“电话号码”不能为空<br/>"; msg += innerMsg; continue; } //2.话务ID验证(可空) if (!string.IsNullOrEmpty(idr[1].ToString().Trim())) { if (!BLL.Util.IsNumber(idr[1].ToString().Trim())) { innerMsg += "第" + rowIndex + "行数据:" + "“话务ID”格式不正确,只能由数字组成<br/>"; msg += innerMsg; continue; } model.CallID = Convert.ToInt64(idr[1].ToString().Trim()); } //3.生效时间 if (!string.IsNullOrEmpty(idr[2].ToString().Trim())) { DateTime datetime; if (DateTime.TryParse(idr[2].ToString().Trim(), out datetime)) { model.EffectiveDate = datetime; } else { innerMsg += "第" + rowIndex + "行数据:" + "“生效时间”不是正确的日期时间格式<br/>"; msg += innerMsg; continue; } } else { innerMsg += "第" + rowIndex + "行数据:" + "“生效时间”不能为空<br/>"; msg += innerMsg; continue; } //4.过期时间 if (!string.IsNullOrEmpty(idr[3].ToString().Trim())) { DateTime datetime; if (DateTime.TryParse(idr[3].ToString().Trim(), out datetime)) { model.ExpiryDate = datetime; } else { innerMsg += "第" + rowIndex + "行数据:" + "“过期时间”不是正确的日期时间格式<br/>"; msg += innerMsg; continue; } } else { innerMsg += "第" + rowIndex + "行数据:" + "“过期时间”不能为空<br/>"; msg += innerMsg; continue; } //5.;类型 if (!string.IsNullOrEmpty(idr[4].ToString().Trim())) { int calltype = 0; if (idr[4].ToString().Trim().Contains("呼入")) { calltype = 1; //6.对应业务 if (!string.IsNullOrEmpty(idr[5].ToString().Trim())) { string cidsReal = idr[5].ToString().Replace(",", ",").Trim(); string[] businessnameArr = cidsReal.Split(','); int cdids = 0; for (int i = 0; i < businessnameArr.Length; i++) { for (int j = 0; j < modeBusinessType.Count; j++) { if (modeBusinessType[j].BusinessName == businessnameArr[i]) { cdids += int.Parse(modeBusinessType[j].BusinessRightValue); } } } if (cdids == 0) { innerMsg += "第" + rowIndex + "行数据:" + "“对应业务”数据异常,请检查数据<br/>"; msg += innerMsg; continue; } else { model.CDIDS = cdids; } } else { innerMsg += "第" + rowIndex + "行数据:" + "“对应业务”数据不能为空<br/>"; msg += innerMsg; continue; } } if (idr[4].ToString().Trim().Contains("呼出")) { calltype += 2; //7.原因 if (!string.IsNullOrEmpty(idr[6].ToString().Trim())) { bool hasVal = false; foreach (DataRow row in tbNoDisturbReason.Rows) { if (row["name"].ToString() == idr[6].ToString().Trim()) { model.CallOutNDType = int.Parse(row["value"].ToString()); hasVal = true; continue; } } if (!hasVal) { innerMsg += "第" + rowIndex + "行数据:" + "“原因”数据不正确,没有相匹配的原因数据<br/>"; msg += innerMsg; continue; } } else { innerMsg += "第" + rowIndex + "行数据:" + "“原因”数据不能为空<br/>"; msg += innerMsg; continue; } } if (calltype == 0) { innerMsg += "第" + rowIndex + "行数据:" + "“类型”数据异常,请检查数据<br/>"; msg += innerMsg; continue; } else { model.CallType = calltype; } } else { innerMsg += "第" + rowIndex + "行数据:" + "“类型”不能为空<br/>"; msg += innerMsg; continue; } //8.备注(可空) if (!string.IsNullOrEmpty(idr[7].ToString().Trim())) { model.Reason = idr[7].ToString().Trim(); } } catch (Exception eex) { innerMsg += "第" + rowIndex + "行数据:" + "部分数据异常,请检查数据<br/>"; msg += innerMsg; continue; } model.Type = int.Parse(Type); model.SynchrodataStatus = 0; model.CreateUserId = userid; model.CreateDate = DateTime.Now; model.UpdateUserId = Constant.INT_INVALID_VALUE; model.UpdateDate = Constant.DATE_INVALID_VALUE; model.Status = 0; if (employeeagent != null && employeeagent.BGID.HasValue) { model.BGID = employeeagent.BGID.Value; } if (innerMsg == "") { if (backVal == -1) { int backRecID = BLL.BlackWhiteList.Instance.GetRecIDByPhoneNumberAndType(idr[0].ToString().Trim().Replace("-", ""), 0); if (backRecID > 0) { model.RecId = backRecID; model.SynchrodataStatus = 1; model.UpdateDate = DateTime.Now; model.UpdateUserId = userid; bool retVal = BLL.BlackWhiteList.Instance.UpdateNoDisturbData(model); if (!retVal) { msg += "号码" + idr[0].ToString() + "更新失败<br/>"; } else { success = true; } } } else if (backVal == 2) { if (BLL.BlackWhiteList.Instance.AddNoDisturbData(model) <= 0) { msg += "号码" + idr[0].ToString() + "入库失败<br/>"; } else { success = true; } } } else { innerMsg = ""; } //myDataList.Add(model); } // DataTable dtBW = BLL.Util.ListToDataTable(myDataList); // BLL.BlackWhiteList.Instance.ImportData(dtBW); } //FileInfo fi = new FileInfo(fileName); //fi.Delete(); ClearFiles(fileName); return(success); }
/// 更新一条数据 /// <summary> /// 更新一条数据 /// </summary> public bool UpdateForSynch(Entities.BlackWhiteList model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update dbo.BlackWhiteList set "); strSql.Append("Type=@Type,"); strSql.Append("PhoneNum=@PhoneNum,"); strSql.Append("EffectiveDate=@EffectiveDate,"); strSql.Append("ExpiryDate=@ExpiryDate,"); strSql.Append("CallType=@CallType,"); strSql.Append("CDIDS=@CDIDS,"); strSql.Append("Reason=@Reason,"); strSql.Append("SynchrodataStatus=@SynchrodataStatus,"); strSql.Append("CreateUserId=@CreateUserId,"); strSql.Append("CreateDate=@CreateDate,"); strSql.Append("UpdateUserId=@UpdateUserId,"); strSql.Append("UpdateDate=@UpdateDate,"); strSql.Append("Status=@Status"); strSql.Append(" where RecId=@RecId"); SqlParameter[] parameters = { new SqlParameter("@Type", SqlDbType.Int, 4), new SqlParameter("@PhoneNum", SqlDbType.VarChar, 20), new SqlParameter("@EffectiveDate", SqlDbType.DateTime), new SqlParameter("@ExpiryDate", SqlDbType.DateTime), new SqlParameter("@CallType", SqlDbType.Int, 4), new SqlParameter("@CDIDS", SqlDbType.Int, 4), new SqlParameter("@Reason", SqlDbType.NVarChar, 500), new SqlParameter("@SynchrodataStatus", SqlDbType.Int, 4), new SqlParameter("@CreateUserId", SqlDbType.Int, 4), new SqlParameter("@CreateDate", SqlDbType.DateTime), new SqlParameter("@UpdateUserId", SqlDbType.Int, 4), new SqlParameter("@UpdateDate", SqlDbType.DateTime), new SqlParameter("@Status", SqlDbType.Int, 4), new SqlParameter("@RecId", SqlDbType.Int, 4) }; parameters[0].Value = model.Type; parameters[1].Value = model.PhoneNum; parameters[2].Value = model.EffectiveDate; parameters[3].Value = model.ExpiryDate; parameters[4].Value = model.CallType; parameters[5].Value = model.CDIDS; parameters[6].Value = model.Reason; parameters[7].Value = model.SynchrodataStatus; parameters[8].Value = model.CreateUserId; parameters[9].Value = model.CreateDate; parameters[10].Value = model.UpdateUserId; parameters[11].Value = model.UpdateDate; parameters[12].Value = model.Status; parameters[13].Value = model.RecId; int rows = SqlHelper.ExecuteNonQuery(ConnectionStrings_Holly_Business, CommandType.Text, strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }