private void Save_Incoming_Calls(dynamic data) { //var ug_code = this.UserSession.User.AU_UG_Code; //if (ug_code != 28 && ug_code != 40) //{ // throw new Exception(Interna ? "Without the permission!" : "无此权限!"); //} var db = DBCRMTree.GetInstance(); try { using (var tran = db.GetTransaction()) { //CT_Handler var s_data = JsonConvert.SerializeObject(data.data); if (string.IsNullOrWhiteSpace(s_data)) { throw new Exception(Interna ? "No data!" : "无数据!"); } CT_Comm_History ch = JsonConvert.DeserializeObject <CT_Comm_History>(s_data); ch.CH_UType = (byte)UserSession.User.UG_UType; ch.CH_AD_OM_Code = UserSession.DealerEmpl.DE_AD_OM_Code; ch.CH_Update_dt = DateTime.Now; ch.CH_Code = Convert.ToInt32(ch.Insert()); CT_Handler handler = JsonConvert.DeserializeObject <CT_Handler>(s_data); handler.HD_CH_Code = ch.CH_Code; handler.HD_AU_Code = UserSession.User.AU_Code; handler.HD_Code = Convert.ToInt32(handler.Insert()); CT_Dialog_Hist dh = JsonConvert.DeserializeObject <CT_Dialog_Hist>(s_data); if (!dh.DH_Duration.HasValue) { dh.DH_Duration = -1; } if (!dh.DH_legacy.HasValue) { dh.DH_legacy = false; } dh.DH_HD_Code = handler.HD_Code; dh.DH_Update_dt = DateTime.Now; dh.Insert(); //db.AbortTransaction(); tran.Complete(); } Response.Write(JsonConvert.SerializeObject(new { isOK = true })); } catch (Exception ex) { db.AbortTransaction(); Response.Write(JsonConvert.SerializeObject(new { isOK = false, msg = ex.Message })); } }
private void Save_Dialog(dynamic data, CT_Handler hd) { var s_dh = JsonConvert.SerializeObject(data.data); if (string.IsNullOrWhiteSpace(s_dh)) { return; } CT_Dialog_Hist dh = JsonConvert.DeserializeObject <CT_Dialog_Hist>(s_dh); dh.DH_HD_Code = hd.HD_Code; dh.DH_Click = hd.HD_Action; dh.DH_Update_dt = DateTime.Now; dh.Insert(); }
private void Save_CustomerService(dynamic data) { //var ug_code = this.UserSession.User.AU_UG_Code; //if (ug_code != 28 && ug_code != 40) //{ // throw new Exception(Interna ? "Without the permission!" : "无此权限!"); //} var db = DBCRMTree.GetInstance(); var timerSet = false; try { using (var tran = db.GetTransaction()) { //CT_Handler var s_hd = JsonConvert.SerializeObject(data.data); if (string.IsNullOrWhiteSpace(s_hd)) { throw new Exception(Interna ? "No History!" : "无信息!"); } CT_Handler handler = JsonConvert.DeserializeObject <CT_Handler>(s_hd); var hd = CT_Handler.SingleOrDefault(handler.HD_Code); //CT_Comm_History var ch = CT_Comm_History.SingleOrDefault(hd.HD_CH_Code); //Count the number of similar Actions var o = db.SingleOrDefault <dynamic>(@"SELECT count(*) as Act_cnt from CT_Dialog_Hist where DH_legacy=1 and DH_HD_Code=@0 and DH_Click=@1", hd.HD_Code, handler.HD_Action); //o.Act_cnt //Get Dealer Limits and call back duration int Start, End; int WaitTime = 15; int MaxCnt = 2; var strStart = "||" + handler.HD_Action.ToString() + ","; if (UserSession.Dealer.AD_Call_Limits.Contains(strStart)) { Start = UserSession.Dealer.AD_Call_Limits.IndexOf(strStart, 0) + strStart.Length; End = UserSession.Dealer.AD_Call_Limits.IndexOf("||", Start); string tStr = UserSession.Dealer.AD_Call_Limits.Substring(Start, End - Start); MaxCnt = System.Convert.ToInt32(tStr.Split(',')[0]); WaitTime = System.Convert.ToInt32(tStr.Split(',')[1]); } var s_ct = JsonConvert.SerializeObject(data.data); //Clear all existing reminders for this person db.Execute("UPDATE CT_Reminder_Timers SET RT_Status=0 WHERE RT_Type=1 AND [RT_AU_Code]=" + hd.HD_AU_Code + " AND [RT_Pointer]=" + hd.HD_Code + " AND RT_STatus=1"); var rt = JsonConvert.DeserializeObject <CT_Reminder_Timers>(s_ct); rt.RT_Pointer = hd.HD_Code; rt.RT_AU_Code = hd.HD_AU_Code; rt.RT_Status = 1; rt.RT_Type = 1; if (rt.RT_Time != null) { rt.Insert();//Set the new timer timerSet = true; } //var s_ct = JsonConvert.SerializeObject(data.data); //var ct = JsonConvert.DeserializeObject<CT_Callback_Sch>(s_ct); //ct.CT_CH_Code = hd.HD_CH_Code; //CT_Callback_Sch.Delete("where CT_CH_Code=@0", ct.CT_CH_Code); //ct.Insert(); //Save the process into CT_Dialog History, before hd.HD_Action is changed. var prev_Action = hd.HD_Action; var prev_Status = ch.CH_Status; hd.HD_Action = handler.HD_Action; Save_Dialog(data, hd); //call me back if (handler.HD_Action == 31 || handler.HD_Action == 40) { hd.HD_Code = 0; hd.HD_Action = 0; hd.HD_Code = Convert.ToInt32(hd.Insert()); ch.CH_Status = 5; if (!timerSet) { rt.Insert(); //Set the new timer } } //Do Not Call, Do not use this number else if (handler.HD_Action == 25 || handler.HD_Action == 27) { hd.HD_Action = handler.HD_Action; hd.Update(new string[] { "HD_Action" }); ch.CH_Status = 10; var s = JsonConvert.SerializeObject(data.data); var phone = JsonConvert.DeserializeObject <CT_Phone_List>(s); phone.PL_Update_dt = DateTime.Now; phone.PL_DonotUse = true; phone.Update(new string[] { "PL_Update_dt", "PL_DonotUse" }); //Cancel all the current calls to this phone number db.Execute("UPDATE CT_Reminder_Timers SET RT_Status=0 WHERE RT_Type=1 AND [RT_AU_Code]=" + hd.HD_AU_Code + " AND [RT_Pointer]=" + hd.HD_Code + " AND RT_STatus=1"); db.Execute("Update CT_Handler Set HD_Action=95 where HD_CH_Code in (Select CH_Code from CT_Comm_History where CH_Status <10 and CH_Type in (3,4,5,6) and [CH_ML_PL_Code] = @0)", phone.PL_Code); db.Execute("Update CT_Comm_History set CH_Update_dt=GetDate(), CH_Status =35 WHERE CH_Status <10 and CH_Type in (3,4,5,6) and [CH_ML_PL_Code] = @0", phone.PL_Code); } // Duplicate Call else if (handler.HD_Action == 22) { hd.HD_Action = handler.HD_Action; hd.Update(new string[] { "HD_Action" }); ch.CH_Status = 10; var s = JsonConvert.SerializeObject(data.data); var phone = JsonConvert.DeserializeObject <CT_Phone_List>(s); phone.PL_Update_dt = DateTime.Now; phone.PL_DonotUse = false; phone.Update(new string[] { "PL_Update_dt", "PL_DonotUse" }); //Cancel all the current calls to this phone number db.Execute("UPDATE CT_Reminder_Timers SET RT_Status=0 WHERE RT_Type=1 AND [RT_AU_Code]=" + hd.HD_AU_Code + " AND [RT_Pointer]=" + hd.HD_Code + " AND RT_STatus=1"); db.Execute("Update CT_Handler Set HD_Action=95 where HD_CH_Code in (Select CH_Code from CT_Comm_History where CH_Status <10 and CH_Type in (3,4,5,6) and [CH_ML_PL_Code] = @0)", phone.PL_Code); db.Execute("Update CT_Comm_History set CH_Update_dt=GetDate(), CH_Status =35 WHERE CH_Status <10 and CH_Type in (3,4,5,6) and [CH_ML_PL_Code] = @0", phone.PL_Code); } //Phone Change,Do not use this number, Invalid #, Wrong#, Not Owner(Will not provide info) else if (handler.HD_Action == 41 || handler.HD_Action == 42 || handler.HD_Action == 44 || handler.HD_Action == 45) { hd.HD_Action = handler.HD_Action; hd.Update(new string[] { "HD_Action" }); ch.CH_Status = 10; var s = JsonConvert.SerializeObject(data.data); var phone = JsonConvert.DeserializeObject <CT_Phone_List>(s); phone.PL_Update_dt = DateTime.Now; phone.PL_Active = false; phone.Update(new string[] { "PL_Update_dt", "PL_Active" }); //Cancel all the current calls to this phone number db.Execute("UPDATE CT_Reminder_Timers SET RT_Status=0 WHERE RT_Type=1 AND [RT_AU_Code]=" + hd.HD_AU_Code + " AND [RT_Pointer]=" + hd.HD_Code + " AND RT_STatus=1"); db.Execute("Update CT_Handler Set HD_Action=95 where HD_CH_Code in (Select CH_Code from CT_Comm_History where CH_Status <10 and CH_Type in (3,4,5,6) and [CH_ML_PL_Code] = @0)", phone.PL_Code); db.Execute("Update CT_Comm_History set CH_Update_dt=GetDate(), CH_Status =35 WHERE CH_Status <10 and CH_Type in (3,4,5,6) and [CH_ML_PL_Code] = @0", phone.PL_Code); } //busy, Nobody Answered, Stop Service,Phone Shutdown, Wiat one day after 3 times, 2 days after 5 times,... else if (handler.HD_Action == 10 || handler.HD_Action == 15 || handler.HD_Action == 16 || handler.HD_Action == 14) { if ((o.Act_cnt + 1) >= MaxCnt) { ch.CH_Status = 10; } else { ch.CH_Status = 5; hd.Update(new string[] { "HD_Action" }); rt.RT_Time = DateTime.Now.AddMinutes(WaitTime); if (!timerSet) { rt.Insert(); //Set the new timer } } } //Car Sold, Customer REfused to continue else if (handler.HD_Action == 50 || handler.HD_Action == 38) { hd.HD_Action = handler.HD_Action; hd.Update(new string[] { "HD_Action" }); ch.CH_Status = 10; var s = JsonConvert.SerializeObject(data.data); var car = JsonConvert.DeserializeObject <CT_Car_Inventory>(s); car.CI_Update_dt = DateTime.Now; car.CI_Activate_Tag = 0; car.Update(new string[] { "CI_Update_dt", "CI_Activate_Tag" }); //Cancel all the campaigns for this car db.Execute("UPDATE CT_Reminder_Timers SET RT_Status=0 WHERE RT_Type=1 AND [RT_AU_Code]=" + hd.HD_AU_Code + " AND [RT_Pointer]=" + hd.HD_Code + " AND RT_STatus=1"); db.Execute("Update CT_Handler Set HD_Action=95 where HD_CH_Code in (Select CH_Code from CT_Comm_History where CH_Status <10 and CH_Type in (3,4,5,6) and CH_CI_Code = @0)", car.CI_Code); db.Execute("Update CT_Comm_History set CH_Update_dt=GetDate(), CH_Status =35 WHERE CH_Status <10 and CH_Type in (3,4,5,6) and CH_CI_Code = @0", car.CI_Code); } else //Others { hd.HD_Action = handler.HD_Action; hd.Update(new string[] { "HD_Action" }); //Dialog // Save_Dialog(data, hd); ch.CH_Status = 10; } //db.AbortTransaction(); ch.CH_Update_dt = DateTime.Now; ch.Update(new string[] { "CH_Status", "CH_Update_dt" }); tran.Complete(); } Response.Write(JsonConvert.SerializeObject(new { isOK = true })); } catch (Exception ex) { db.AbortTransaction(); Response.Write(JsonConvert.SerializeObject(new { isOK = false, msg = ex.Message })); } }