public void chat() { string subdec = null; DateTime date1_stamp = new DateTime(); DateTime o = new DateTime(); try { if (Session["User_Id"] != null) { bl.User_id = Session["User_Id"].ToString(); } else { if (Request.Cookies["User_Id"] != null) { Session["User_Id"] = Request.Cookies["User_Id"].Value; bl.User_id = Request.Cookies["User_Id"].Value; } } bl.Sender_id = util.Decrypt_AES(Request.QueryString["sid"].ToString(), key); bl.Receiver_id = util.Decrypt_AES(Request.QueryString["uid"].ToString(), key); bl.Chat_id = util.Decrypt_AES(Request.QueryString["chid"].ToString(), key); dt1 = dl.select_chatbox_for_read(bl); if (dt1.table.Rows.Count > 0) { foreach (DataRow row in dt1.table.Rows) { bl.Chatboxid = row["id"].ToString(); rb = dl.update_read_chat(bl); } dt2 = dl.newmessage_update_new(bl); if (dt2.table.Rows.Count > 0 && dt2.table.Rows[0]["newmessage"].ToString() != "0") { ((Label)this.Page.Master.FindControl("lbl_new_message")).Text = dt2.table.Rows[0]["newmessage"].ToString(); ((Label)this.Page.Master.FindControl("lbl_new_message")).Visible = true; } else { ((Label)this.Page.Master.FindControl("lbl_new_message")).Visible = false; } } dt = dl.select_chatbox(bl); StringBuilder htmlTable = new StringBuilder(); int lol = 1; if (dt.table.Rows.Count > 0) { if (dt.table.Rows[0]["subject"].ToString() != "" || dt.table.Rows[0]["subject"] != null) { try { Txt_subject.Text = util.Decrypt_AES(dt.table.Rows[0]["subject"].ToString(), key); subdec = util.Decrypt_AES(dt.table.Rows[0]["subject"].ToString(), key); }catch (Exception ex) { Txt_subject.Text = ""; subdec = ""; } } if (Txt_subject.Text == "") { Txt_subject.Enabled = true; } else { Txt_subject.Enabled = false; } if (Request.QueryString["sub"] != null && Request.QueryString["sub"].ToString() != "") { try { Txt_subject.Text = util.Decrypt_AES(Request.QueryString["sub"].ToString(), key); subdec = util.Decrypt_AES(Request.QueryString["sub"].ToString(), key); }catch (Exception ex) { Txt_subject.Text = ""; subdec = ""; } } if (Txt_subject.Text == "") { Txt_subject.Enabled = true; } else { Txt_subject.Enabled = false; } if (dt.table.Rows[0]["feedback_sent"].ToString() == "N") { bl.Feedback_days = dt.table.Rows[0]["feedback_days"].ToString(); bl.Feedback_date = dt.table.Rows[0]["feedback_date"].ToString(); date1_stamp = Convert.ToDateTime(dt.table.Rows[0]["feedback_date"].ToString()); DateTime answer = date1_stamp.AddDays(Convert.ToInt32(bl.Feedback_days)); o = DateTime.Now; int result = DateTime.Compare(o, answer); if (result >= 0) { rb = dl.update_feedback_chat(bl); Thread Stamp_Action = new Thread(delegate() { bl.User_type = "USER"; dtnew = dl.select_receriver_name_for_user(bl); if (dtnew.table.Rows.Count > 0) { bl.Type = null; bl.First_name = dtnew.table.Rows[0]["applicant_first_name"].ToString(); bl.Message = "Hi " + bl.First_name + ", We want to hear from you about your consultation for " + subdec + ". Please log in and update the chat with the feedback."; bl.Success = send_sms_to_user(dtnew.table.Rows[0]["applicant_mobile"].ToString(), bl.Message); rb = dl.sms_log(bl); bl.Type = null; if (dtnew.table.Rows[0]["applicant_email"].ToString() != "" && dtnew.table.Rows[0]["applicant_email"].ToString() != null) { bl.Success = email_to_user_new(dtnew.table.Rows[0]["applicant_email"].ToString(), bl.Message); rb = dl.sms_log(bl); } } }); Stamp_Action.IsBackground = true; Stamp_Action.Start(); } } if (dt.table.Rows[0]["status1"].ToString() == "C") { chhaatt.Visible = false; } foreach (DataRow row in dt.table.Rows) { string type = row["sendertype"].ToString(); if (type == "USER") { htmlTable.AppendLine("<div class=\"process right\">"); } else if (type == "DOC") { htmlTable.AppendLine("<div class=\"process left\">"); } htmlTable.AppendLine("<div class=\"process-step\">"); htmlTable.AppendLine("<strong>" + row["senderinitial"].ToString() + "</strong>"); htmlTable.AppendLine("</div>"); if (type == "USER") { htmlTable.AppendLine("<div class=\"process-content rightt\">"); } else if (type == "DOC") { htmlTable.AppendLine("<div class=\"process-content \" >"); } htmlTable.AppendLine("<div class=\"process-icon\">"); htmlTable.AppendLine("<span class=\"flaticon-line\"></span>"); htmlTable.AppendLine("</div>"); htmlTable.AppendLine("<div class=\"process-info\">"); htmlTable.AppendLine("<h5 class=\"mb-20\">" + row["sendername"].ToString() + "</h5>"); // htmlTable.AppendLine("<p><b>" + row["message"].ToString() + "</b></p>"); htmlTable.AppendLine("<p style=\"text-align: justify\"><b>" + util.Decrypt_AES(row["message"].ToString(), key) + "</b></p>"); if (row["isfile"].ToString() == "Y") { htmlTable.AppendLine("<p><a target=\"_blank\" href=\"Handler_chat.ashx?id=" + row["id"].ToString() + "&chid=" + Server.UrlEncode(util.Encrypt_AES(Request.QueryString["chid"].ToString(), key)) + "\">" + row["document_name"].ToString() + "</a></p>"); } // htmlTable.AppendLine("<p><i class=\"fa fa-clock-o\" aria-hidden=\"true\"></i> " + row["sendinddate"].ToString() + "</p>"); htmlTable.AppendLine("<p style=\" font-size: 11px;\"> " + row["sendinddate"].ToString() + "</p>"); htmlTable.AppendLine("</div>"); htmlTable.AppendLine("</div>"); if (type == "USER" && lol == 1) { htmlTable.AppendLine("<div class=\"border-area right-bottom\"></div>"); } else if (type == "DOC" && lol == 1) { htmlTable.AppendLine("<div class=\"border-area left-bottom\"></div>"); } else if (type == "USER" && lol != 1) { htmlTable.AppendLine("<div class=\"border-area right-bottom\"></div>"); htmlTable.AppendLine("<div class=\"border-area right-top\"></div>"); } else if (type == "DOC" && lol != 1) { htmlTable.AppendLine("<div class=\"border-area left-top\"></div>"); htmlTable.AppendLine("<div class=\"border-area left-bottom\"></div>"); } htmlTable.AppendLine("</div>"); Literal1.Text = htmlTable.ToString(); lol++; } } else if (util.Decrypt_AES(Request.QueryString["chid"].ToString(), key) == "0") { bl.Sender_id = util.Decrypt_AES(Request.QueryString["sid"].ToString(), key); bl.Receiver_id = util.Decrypt_AES(Request.QueryString["uid"].ToString(), key); if (Request.QueryString["followupchid"] != null && Request.QueryString["followupchid"].ToString() != "") { bl.Followupchatid = util.Decrypt_AES(Request.QueryString["followupchid"].ToString(), key); bl.Follow_up_case_yes_no = "Y"; } else { bl.Follow_up_case_yes_no = "N"; } if (Request.QueryString["payment_id"] != null && Request.QueryString["payment_id"].ToString() != "") { bl.Payment_Id = Request.QueryString["payment_id"].ToString(); } else { bl.Payment_Id = ""; } bl.Status = "A"; // bl.Payment = "400"; int k = 0; if (Request.QueryString["payment_rupee"] != null) { k = Convert.ToInt32(Request.QueryString["payment_rupee"].ToString()); if (k != 0) { k = k / 100; } } bl.Payment = k.ToString(); bl.Validity = "7"; if (Session["User_Id"] != null) { bl.User_id = Session["User_Id"].ToString(); } else { if (Request.Cookies["User_Id"] != null) { Session["User_Id"] = Request.Cookies["User_Id"].Value; bl.User_id = Request.Cookies["User_Id"].Value; } } bl.Client_id = util.GetClientIpAddress(this.Page); bl.Date_time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); bl.Action_id = Get_trans_action(bl.Category_id); bl.Sent_method = "Chat"; bl.Chat_id = INTSUB_ID_from(); rb = dl.insert_chat_with_doctor_log(bl); if (rb.status) { dt = dl.select_sender_name(bl); if (dt.table.Rows.Count > 0) { bl.First_name = dt.table.Rows[0]["applicant_first_name"].ToString(); bl.Email_id = dt.table.Rows[0]["applicant_email"].ToString(); } Thread Stamp_Action = new Thread(delegate() { bl.User_type = "DOC"; dt = dl.select_receriver_name(bl); if (dt.table.Rows.Count > 0) { bl.Message = "Hi " + bl.First_name + ", Your online consultation is confirmed, Thanks. "; bl.Success = send_sms_to_user(bl.Sender_id, bl.Message); rb = dl.sms_log(bl); bl.Type = null; //bl.Message = "Hi " + bl.First_name + ", Your case online consultation at cellsalts4health is submitted to " + dt.table.Rows[0]["applicant_first_name"].ToString() + ", we will update you when he accepts it and if requires more details to prescribe the remedy. "; //bl.Success = send_sms_to_user(bl.Sender_id, bl.Message); //rb = dl.sms_log(bl); //bl.Type = null; if (bl.Email_id != "" && bl.Email_id != null) { //bl.Success = email_to_user_new(bl.Email_id, bl.Message); //rb = dl.sms_log(bl); if (k != 0) { bl.Type = null; string datetime = DateTime.Now.ToString("dd-MMMM-yyyy"); bl.Message = get_message(datetime, bl.Chat_id, bl.First_name, k.ToString()); bl.Success = email_to_user_new_pay(bl.Email_id, bl.Message); rb = dl.sms_log(bl); } } bl.First_name = dt.table.Rows[0]["applicant_first_name"].ToString(); bl.Message = "Hi " + bl.First_name + ", A new case is assigned to you for online consultation at cellsalts4health, Please login and check the details"; bl.Success = send_sms_to_user(bl.Receiver_id, bl.Message); rb = dl.sms_log(bl); bl.Type = null; if (dt.table.Rows[0]["applicant_email"].ToString() != "" && dt.table.Rows[0]["applicant_email"].ToString() != null) { bl.Success = email_to_user_new(dt.table.Rows[0]["applicant_email"].ToString(), bl.Message); rb = dl.sms_log(bl); } } }); Stamp_Action.IsBackground = true; Stamp_Action.Start(); if (Request.QueryString["sub"] != null && Request.QueryString["sub"].ToString() != "") { Response.Redirect("chatting.aspx?uid=" + Server.UrlEncode(Request.QueryString["uid"].ToString()) + "&chid=" + Server.UrlEncode(util.Encrypt_AES(bl.Chat_id, key)) + "&sid=" + Server.UrlEncode(Request.QueryString["sid"].ToString()) + "&sub=" + Server.UrlEncode(Request.QueryString["sub"].ToString())); } else { Response.Redirect("chatting.aspx?uid=" + Server.UrlEncode(Request.QueryString["uid"].ToString()) + "&chid=" + Server.UrlEncode(util.Encrypt_AES(bl.Chat_id, key)) + "&sid=" + Server.UrlEncode(Request.QueryString["sid"].ToString()) + "&sub="); } } } else { if (Request.QueryString["sub"] != null && Request.QueryString["sub"].ToString() != "") { try { Txt_subject.Text = util.Decrypt_AES(Request.QueryString["sub"].ToString(), key); subdec = util.Decrypt_AES(Request.QueryString["sub"].ToString(), key); } catch (Exception ex) { Txt_subject.Text = ""; subdec = ""; } } if (Txt_subject.Text == "") { Txt_subject.Enabled = true; } else { Txt_subject.Enabled = false; } //htmlTable.AppendLine("<div class=\"table-responsive\">"); //htmlTable.AppendLine("<table class=\"table table-1 table-bordered table-striped table-2\" style=\"border-color:#20B2AA; table-layout:fixed;font-size:10px;\" > "); //htmlTable.AppendLine("<tbody>"); //htmlTable.AppendLine("<tr>"); //htmlTable.AppendLine("<td colspan=8 style=\"background:#20B2AA;color:black;width:30px;font-weight:bolder;\"> No Chat Found </td>"); //htmlTable.AppendLine("</tr>"); //htmlTable.AppendLine("</tbody>"); //htmlTable.AppendLine("</table>"); //htmlTable.AppendLine("</div>"); //Literal1.Text = htmlTable.ToString(); } } catch (Exception ex) { // Utilities.MessageBoxShow_Redirect("Cannot Find Chat, Please try again...", "Consult_online_new.aspx"); File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + "log.txt", ex.ToString()); Utilities.MessageBoxShow_Redirect("Cannot Find Chat, Please try again...", "../Logout.aspx"); } }