protected void message_Click(object sender, EventArgs e) { if (Page.IsValid) { try { if (Session["CheckRefresh"] != null) { if (Session["CheckRefresh"].ToString() == ViewState["CheckRefresh"].ToString()) { Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString()); if (Session["User_Id"] != null) { bl.User_id = Session["User_Id"].ToString(); // bl.Sender_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 = Request.Cookies["User_Id"].Value; } } bl.Receiver_id = util.Decrypt_AES(Request.QueryString["uid"].ToString(), key); bl.Sender_id = util.Decrypt_AES(Request.QueryString["sid"].ToString(), key); bl.Status = "A"; bl.Date_time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); bl.Sending_date = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); bl.Client_id = util.GetClientIpAddress(this.Page); string description = txt_Message.Text.Trim(); description = description.Replace("\r\n", "<br/>"); // bl.Message = util.Encrypt_AES(txt_Message.Text.Trim(), key); bl.Message = util.Encrypt_AES(description, key); bl.Category_id = util.Decrypt_AES(Request.QueryString["chid"].ToString(), key); bl.Action_id = Get_trans_action(bl.Category_id); bl.Subject = util.Encrypt_AES(Txt_subject.Text.Trim(), key); bl.Sent_method = "Chat"; Int32 maxLimit = 10485760; if (FileUpload1.HasFile) { bl.Isfile = true; bl.Isfile_ = "Y"; string ext = System.IO.Path.GetExtension(FileUpload1.FileName); double size = FileUpload1.PostedFile.ContentLength; string contenttypee = FileUpload1.PostedFile.ContentType.ToLower(); if (FileUpload1.PostedFile.ContentLength > maxLimit) { Utilities.MessageBoxShow("File Is too Big...Maximum Size allowed is 5 Mb"); } else if (contenttypee == "application/pdf" || contenttypee == "application/x-pdf" || contenttypee == "application/x-unknown" || contenttypee == "image/gif" || contenttypee == "image/png" || contenttypee == "image/jpg" || contenttypee == "image/jpeg") { bl.File_extn = Path.GetExtension(FileUpload1.PostedFile.FileName).ToString(); Stream fs = default(Stream); fs = FileUpload1.PostedFile.InputStream; BinaryReader br1 = new BinaryReader(fs); bl.Document_data = br1.ReadBytes(FileUpload1.PostedFile.ContentLength); bl.Document_name = FileUpload1.PostedFile.FileName; if (ext == ".pdf") { bl.Mime_type = "application/pdf"; } else { bl.Mime_type = contenttypee; } } else { Utilities.MessageBoxShow("Only .pdf .jpeg .gif .jpg .png files are allowed, try again"); } } else { bl.Isfile_ = "N"; bl.Isfile = false; } rb = dl.chatbox_insert(bl); if (rb.status) { dtagain = dl.select_sender_name(bl); if (dtagain.table.Rows.Count > 0) { bl.Middle_name = dtagain.table.Rows[0]["applicant_first_name"].ToString(); bl.Email_id = dtagain.table.Rows[0]["applicant_email"].ToString(); } txt_Message.Text = null; Thread Stamp_Action = new Thread(delegate() { bl.User_type = "DOC"; dtttt = dl.select_receriver_name(bl); if (dtagain.table.Rows.Count > 0) { if (bl.Action_id == "2") { bl.Message = "Hi " + bl.Middle_name + ", Your case online consultation at cellsalts4health is submitted to " + dtttt.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; bl.Success = email_to_user_new(bl.Email_id, bl.Message); rb = dl.sms_log(bl); bl.Type = null; } bl.First_name = dtttt.table.Rows[0]["applicant_first_name"].ToString(); bl.Message = "Hi " + bl.First_name + ", " + bl.Middle_name + " has messaged you. Please login and check."; bl.Success = send_sms_to_user(bl.Receiver_id, bl.Message); rb = dl.sms_log(bl); if (dtttt.table.Rows[0]["applicant_email"].ToString() != "" && dtttt.table.Rows[0]["applicant_email"].ToString() != null) { bl.Success = email_to_user_new(dtttt.table.Rows[0]["applicant_email"].ToString(), bl.Message); rb = dl.sms_log(bl); } } }); Stamp_Action.IsBackground = true; Stamp_Action.Start(); // chat(); } chat(); } else { Utilities.MessageBoxShow("Page Refresh or Back button is now allowed"); } } else { Utilities.MessageBoxShow("Page expired!!! Please re open this page in new window."); } } catch (NullReferenceException) { // Utilities.MessageBoxShow_Redirect("Records could not be saved: Please Try Again", "chatting.aspx"); Utilities.MessageBoxShow_Redirect("Records could not be saved: Please Try Again", "../Logout.aspx"); } } }