private bool saveMessage(Int32 iUserId, Int32 iPrivateLabelId)
        {
            Int32            iShopId;
            Boolean          bFound     = false;
            Boolean          bHasShop   = checkUserPrefferedShop(iUserId, out iShopId);
            List <MessageBL> lstMessage = MessageBL.getDataByUserIdAndType(iUserId, Constants.REGISTRATIONMESSAGTYPE);

            if (lstMessage != null && lstMessage.Count > 0)
            {
                foreach (MessageBL objMessage in lstMessage)
                {
                    if (objMessage.iShopID == null)
                    {
                        objMessage.bIsRead       = false;
                        objMessage.dtMessageTime = DateTime.Now;
                        objMessage.strMessage    = Constants.REGISTRATIONMESSAGE;
                        if (iPrivateLabelId != 0)
                        {
                            objMessage.iPrivateLabelID = iPrivateLabelId;
                        }
                        bFound = true;
                    }
                    else
                    {
                        objMessage.bIsRead    = (bHasShop && iShopId == objMessage.iShopID) ? true : objMessage.bIsRead;
                        objMessage.strMessage = Constants.PREFFEREDSHOPMESSAGE;
                        bFound = true;
                    }
                    objMessage.Save();
                }
            }
            if (!bFound)
            {
                MessageBL objMessage = new MessageBL();
                objMessage.iPhoneUserID  = iUserId;
                objMessage.iType         = Constants.REGISTRATIONMESSAGTYPE;
                objMessage.strMessage    = Constants.REGISTRATIONMESSAGE;
                objMessage.bIsRead       = false;
                objMessage.dtMessageTime = DateTime.Now;
                if (iPrivateLabelId != 0)
                {
                    objMessage.iPrivateLabelID = iPrivateLabelId;
                }
                objMessage.Save();

                if (bHasShop)
                {
                    MessageBL _objMessage = new MessageBL();
                    _objMessage.iShopID       = iShopId;
                    _objMessage.iPhoneUserID  = iUserId;
                    _objMessage.iType         = Constants.REGISTRATIONMESSAGTYPE;
                    _objMessage.strMessage    = Constants.PREFFEREDSHOPMESSAGE;
                    _objMessage.bIsRead       = true;
                    _objMessage.dtMessageTime = DateTime.Now;
                    _objMessage.Save();
                }
            }
            return(false);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Boolean          bResult           = false;
            AccidentReportBL objAccidentReport = new AccidentReportBL();
            string           strZipFilePath    = String.Empty;

            try
            {
                String strPhoneId  = String.Empty;
                String strPhoneId1 = String.Empty;
                if (!String.IsNullOrEmpty(Request.QueryString["ShopID"]))
                {
                    //get the phone user id
                    if (Request.QueryString["User_ID"] != null)
                    {
                        strPhoneId1 = Request.QueryString["User_ID"];
                    }
                    else if (Request.Headers["User_ID"] != null)
                    {
                        strPhoneId1 = Request.Headers["User_ID"];
                    }
                    if (!Int32.TryParse(Security.DecodeNumbers(Request.QueryString["ShopID"]), out iShopID))
                    {
                        return;
                    }
                }
                else
                {
                    //get the phone user id
                    if (Request.QueryString["User_ID"] != null)
                    {
                        strPhoneId = Request.QueryString["User_ID"];
                    }
                    else if (Request.Headers["User_ID"] != null)
                    {
                        strPhoneId = Request.Headers["User_ID"];
                    }
                }
                //if (!String.IsNullOrEmpty(strPhoneId))
                //{
                //if fphone user id is found
                UserBL objUser = null;
                if (String.IsNullOrEmpty(strPhoneId1))
                {
                    objUser = UserBL.getDataByPhoneId(strPhoneId);
                }
                else
                {
                    MyCustomerBL objMyCustomer = MyCustomerBL.getDataByShopIdNPhone(iShopID, strPhoneId1);
                    if (objMyCustomer != null)
                    {
                        objUser = UserBL.getByActivityId(objMyCustomer.iUserId.Value);
                    }
                }
                if (objUser != null)
                {
                    //if user of previous phone user id is found fill his accident report information
                    String strUserName = String.Empty;

                    if (String.IsNullOrEmpty(objUser.strUserName))
                    {
                        if (Request.QueryString["Phone_Owner_Name"] != null)
                        {
                            strUserName = Request.QueryString["Phone_Owner_Name"];
                        }
                        else if (Request.Headers["Phone_Owner_Name"] != null)
                        {
                            strUserName = Request.Headers["Phone_Owner_Name"];
                        }
                    }

                    if (!String.IsNullOrEmpty(strUserName) && objUser.strFirstName != strUserName)
                    {
                        //if user's first name is changed
                        objUser.strFirstName = strUserName;
                        objUser.Save();
                    }

                    objAccidentReport.iUserId = objUser.ID;

                    if (Request.QueryString["Street_Name"] != null)
                    {
                        objAccidentReport.strStreet = Request.QueryString["Street_Name"].ToString();
                    }
                    else if (Request.Headers["Street_Name"] != null)
                    {
                        objAccidentReport.strStreet = Request.Headers["Street_Name"].ToString();
                    }

                    if (Request.QueryString["City_State"] != null)
                    {
                        objAccidentReport.strCity = Request.QueryString["City_State"].ToString();
                    }
                    else if (Request.Headers["City_State"] != null)
                    {
                        objAccidentReport.strCity = Request.Headers["City_State"].ToString();
                    }

                    if (Request.QueryString["Accident_Description"] != null)
                    {
                        objAccidentReport.strDescription = Request.QueryString["Accident_Description"].ToString();
                    }
                    else if (Request.Headers["Accident_Description"] != null)
                    {
                        objAccidentReport.strDescription = Request.Headers["Accident_Description"].ToString();
                    }

                    if (Request.QueryString["Name"] != null)
                    {
                        objAccidentReport.strDriverName = Request.QueryString["Name"].ToString();
                    }
                    else if (Request.Headers["Name"] != null)
                    {
                        objAccidentReport.strDriverName = Request.Headers["Name"].ToString();
                    }

                    if (Request.QueryString["Phone"] != null)
                    {
                        objAccidentReport.strDriverPhone = Request.QueryString["Phone"].ToString();
                    }
                    else if (Request.Headers["Phone"] != null)
                    {
                        objAccidentReport.strDriverPhone = Request.Headers["Phone"].ToString();
                    }

                    if (Request.QueryString["License_State_and_Plate"] != null)
                    {
                        objAccidentReport.strDriverLicenseStatePlate = Request.QueryString["License_State_and_Plate"].ToString();
                    }
                    else if (Request.Headers["License_State_and_Plate"] != null)
                    {
                        objAccidentReport.strDriverLicenseStatePlate = Request.Headers["License_State_and_Plate"].ToString();
                    }

                    if (Request.QueryString["Driver_License"] != null)
                    {
                        objAccidentReport.strDriverLicenseNo = Request.QueryString["Driver_License"].ToString();
                    }
                    else if (Request.Headers["Driver_License"] != null)
                    {
                        objAccidentReport.strDriverLicenseNo = Request.Headers["Driver_License"].ToString();
                    }

                    if (Request.QueryString["Vehicle_Type"] != null)
                    {
                        objAccidentReport.strDriverVehicleType = Request.QueryString["Vehicle_Type"].ToString();
                    }
                    else if (Request.Headers["Vehicle_Type"] != null)
                    {
                        objAccidentReport.strDriverVehicleType = Request.Headers["Vehicle_Type"].ToString();
                    }

                    if (Request.QueryString["Their_Insurance_Company"] != null)
                    {
                        objAccidentReport.strInsuranceCompanyName = Request.QueryString["Their_Insurance_Company"].ToString();
                    }
                    else if (Request.Headers["Their_Insurance_Company"] != null)
                    {
                        objAccidentReport.strInsuranceCompanyName = Request.Headers["Their_Insurance_Company"].ToString();
                    }

                    if (Request.QueryString["Their_Insurance_Policy"] != null)
                    {
                        objAccidentReport.strInsurancePolicyNo = Request.QueryString["Their_Insurance_Policy"].ToString();
                    }
                    else if (Request.Headers["Their_Insurance_Policy"] != null)
                    {
                        objAccidentReport.strInsurancePolicyNo = Request.Headers["Their_Insurance_Policy"].ToString();
                    }

                    if (Request.QueryString["Police_Office_and_Badge"] != null)
                    {
                        objAccidentReport.strPoliceOffice = Request.QueryString["Police_Office_and_Badge"].ToString();
                    }
                    else if (Request.Headers["Police_Office_and_Badge"] != null)
                    {
                        objAccidentReport.strPoliceOffice = Request.Headers["Police_Office_and_Badge"].ToString();
                    }

                    if (Request.QueryString["Police_Report"] != null)
                    {
                        objAccidentReport.strPoliceReportNo = Request.QueryString["Police_Report"].ToString();
                    }
                    else if (Request.Headers["Police_Report"] != null)
                    {
                        objAccidentReport.strPoliceReportNo = Request.Headers["Police_Report"].ToString();
                    }

                    if (Request.QueryString["Witness"] != null)
                    {
                        objAccidentReport.strWitnesses = Request.QueryString["Witness"].ToString();
                    }
                    else if (Request.Headers["Witness"] != null)
                    {
                        objAccidentReport.strWitnesses = Request.Headers["Witness"].ToString();
                    }

                    if (Request.QueryString["Witness_Comment"] != null)
                    {
                        objAccidentReport.strWitnessComments = Request.QueryString["Witness_Comment"].ToString();
                    }
                    else if (Request.Headers["Witness_Comment"] != null)
                    {
                        objAccidentReport.strWitnessComments = Request.Headers["Witness_Comment"].ToString();
                    }

                    if (Request.QueryString["Misc_Notes"] != null)
                    {
                        objAccidentReport.strMiscNotes = Request.QueryString["Misc_Notes"].ToString();
                    }
                    else if (Request.Headers["Misc_Notes"] != null)
                    {
                        objAccidentReport.strMiscNotes = Request.Headers["Misc_Notes"].ToString();
                    }

                    byte[] photo;

                    UserPreferredShopBL objUserPreferredShop = UserPreferredShopBL.getShopByUserId(objUser.ID);


                    MessageBL objMessage = null;
                    if (objUserPreferredShop != null || iShopID > 0)
                    {
                        //add one message against his preferred shop
                        objMessage              = new MessageBL();
                        objMessage.strMessage   = "Accident Report";
                        objMessage.iPhoneUserID = objUser.ID;
                        if (objUserPreferredShop != null)
                        {
                            objMessage.iShopID = objUserPreferredShop.iShopId;
                        }
                        else
                        {
                            objMessage.iShopID = iShopID;
                        }
                        objMessage.dtMessageTime = DateTime.Now;
                        objMessage.iType         = Constants.AccidentReport;
                        if (objMessage.Save())
                        {
                            if (Request.ContentType.Contains("image"))
                            {
                                if (Request.ContentLength > 1)
                                {
                                    photo = Request.BinaryRead(Request.ContentLength);
                                    //int cnt = Request.TotalBytes;
                                    //photo = Request.BinaryRead(cnt);
                                    MemoryStream         bipimag = new MemoryStream(photo);
                                    System.Drawing.Image imag    = new Bitmap(bipimag);
                                    if (!String.IsNullOrEmpty(Server.MapPath(Constants.ACIIDENTREPORTIMAGE)))
                                    {
                                        String filePath = Server.MapPath(Constants.ACIIDENTREPORTIMAGE) + "\\" + objMessage.ID + ".jpeg";
                                        imag.Save(Constants.SHOPAPP_PATH_IMAGES + "\\" + objMessage.ID + ".jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
                                        objMessage.strAttachment = objMessage.ID + ".jpeg";
                                    }
                                }
                            }
                            else if (Request.ContentType.Contains("multipart"))
                            {
                                if (Request.Files.Count > 0 && !String.IsNullOrEmpty(Constants.SHOPAPP_PATH_IMAGES))
                                {
                                    // Zip the file if more than one photo
                                    if (Request.Files.Count > 1)
                                    {
                                        strZipFilePath = Constants.SHOPAPP_PATH_IMAGES + "\\" + objMessage.ID + ".zip";
                                        ZipOutputStream objZipFile = new ZipOutputStream(File.Create(strZipFilePath));
                                        //0-9, 9 being the highest level of compression
                                        objZipFile.SetLevel(3);
                                        // To permit the zip to be unpacked by built-in extractor in WinXP and Server2003, WinZip 8, Java, and other older code,
                                        // you need to do one of the following: Specify UseZip64.Off, or set the Size.
                                        // If the file may be bigger than 4GB, or you do not need WinXP built-in compatibility, you do not need either,
                                        // but the zip will be in Zip64 format which not all utilities can understand.
                                        objZipFile.UseZip64 = UseZip64.Off;
                                        for (int i = 0; i < Request.Files.Count; i++)
                                        {
                                            HttpPostedFile file = Request.Files[i];
                                            if (!Directory.Exists(Constants.SHOPAPP_PATH_IMAGES + "\\TempZipFiles"))
                                            {
                                                Directory.CreateDirectory(Constants.SHOPAPP_PATH_IMAGES + "\\TempZipFiles");
                                            }
                                            String strFilePath = Constants.SHOPAPP_PATH_IMAGES + "\\TempZipFiles\\" + file.FileName;
                                            if (File.Exists(strFilePath))
                                            {
                                                File.Delete(strFilePath);
                                            }
                                            file.SaveAs(strFilePath);
                                            string   strEntryName = Path.GetFileName(strFilePath); // Removes drive from name and fixes slash direction
                                            ZipEntry objZipEntry  = new ZipEntry(strEntryName);
                                            objZipEntry.DateTime = DateTime.Now;
                                            objZipFile.PutNextEntry(objZipEntry);
                                            // Zip the file in buffered chunks
                                            // the "using" will close the stream even if an exception occurs
                                            byte[] buffer = new byte[4096];
                                            using (FileStream streamReader = File.OpenRead(strFilePath))
                                            {
                                                StreamUtils.Copy(streamReader, objZipFile, buffer);
                                            }
                                            objZipFile.CloseEntry();
                                            File.Delete(strFilePath);
                                        }
                                        objZipFile.IsStreamOwner = true;        // Makes the Close also Close the underlying stream
                                        objZipFile.Close();
                                        objMessage.strAttachment = objMessage.ID + ".zip";
                                    }
                                    else
                                    {
                                        // String filePath = Server.MapPath(Constants.ACIIDENTREPORTIMAGE) + "\\" + objMessage.ID + Path.GetExtension(Request.Files[0].FileName);
                                        Request.Files[0].SaveAs(Constants.SHOPAPP_PATH_IMAGES + "\\" + objMessage.ID + Path.GetExtension(Request.Files[0].FileName));
                                        objMessage.strAttachment = objMessage.ID + Path.GetExtension(Request.Files[0].FileName);
                                    }
                                }
                            }
                            objMessage.Save();
                            objAccidentReport.iMessageId = objMessage.ID;
                            //save the accident report if saved return true else false
                            if (objAccidentReport.Save())
                            {
                                bResult = true;
                                if (Request.QueryString["Contact_Email_ID"] != null)
                                {
                                    SendAccidentReport(objMessage, objAccidentReport, Request.QueryString["Contact_Email_ID"], Request.Headers["Customer_Email_ID"], Request.Headers["Accident_Report_Date"]);
                                }
                                else if (!String.IsNullOrEmpty(Request.Headers["Contact_Email_ID"]))
                                {
                                    SendAccidentReport(objMessage, objAccidentReport, Request.Headers["Contact_Email_ID"], Request.Headers["Customer_Email_ID"], Request.Headers["Accident_Report_Date"]);
                                }
                            }
                        }
                    }
                }
                //}
            }
            catch (Exception ex)
            {
                bResult = false;
            }

            XmlDocument  xmlDoc = new XmlDocument();
            MemoryStream stream = new MemoryStream();
            //XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.ASCII);
            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

            xmlWriter.WriteStartDocument();
            xmlWriter.WriteStartElement("AccidentReport");
            xmlWriter.WriteElementString("Status", bResult ? "Success" : "Fail");
            xmlWriter.WriteEndElement();
            xmlWriter.WriteEndDocument();
            xmlWriter.Flush();
            byte[] byteArray = stream.ToArray();
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "filename=MyExportedFile.xml");
            HttpContext.Current.Response.AppendHeader("Content-Length", byteArray.Length.ToString());
            HttpContext.Current.Response.ContentType = "text/xml";
            HttpContext.Current.Response.BinaryWrite(byteArray);
        }
        private bool saveMessage(Int32 iUserId)
        {
            Int32   iShopId;
            Boolean hasGroupOfPrivateShops;
            Boolean bPerformOperation;
            Boolean bHasShop = setUserPrefferedShop(iUserId, out iShopId, out hasGroupOfPrivateShops, out bPerformOperation);

            if (hasGroupOfPrivateShops || !(bPerformOperation))
            {
                return(false);
            }
            if (bHasShop)
            {
                DeletedUsersFromRepairProspectBL objDeletedUsersFromRepairProspectBL = DeletedUsersFromRepairProspectBL.getDataByShopId(iShopId, iUserId);
                if (objDeletedUsersFromRepairProspectBL != null)
                {
                    objDeletedUsersFromRepairProspectBL.Delete();
                }
                UnreadUsersFromRepairProspectBL OldPrefferedShop = UnreadUsersFromRepairProspectBL.getDataByUserId(iUserId);
                if (OldPrefferedShop != null)
                {
                    if (OldPrefferedShop.ShopID != iShopId)
                    {
                        OldPrefferedShop.Delete();
                    }
                }
                UnreadUsersFromRepairProspectBL objOldEntry = UnreadUsersFromRepairProspectBL.getDataByShopId(iShopId, iUserId);
                if (objOldEntry == null)
                {
                    UnreadUsersFromRepairProspectBL objUnreadUsersFromRepairProspectBL = new UnreadUsersFromRepairProspectBL();
                    objUnreadUsersFromRepairProspectBL.User_id = iUserId;
                    objUnreadUsersFromRepairProspectBL.ShopID  = iShopId;
                    objUnreadUsersFromRepairProspectBL.Save();
                }
            }
            try
            {
                Int32 iPrivateLabelId = 0;
                if (Request.QueryString[Constants.QUERYSTRING_PRIVATELABELSHOPID] != null)
                {
                    Int32.TryParse(Request.QueryString[Constants.QUERYSTRING_PRIVATELABELSHOPID], out iPrivateLabelId);
                }
                else if (Request.Form[Constants.QUERYSTRING_PRIVATELABELSHOPID] != null)
                {
                    Int32.TryParse(Request.Form[Constants.QUERYSTRING_PRIVATELABELSHOPID], out iPrivateLabelId);
                }
                if (iPrivateLabelId == 0)
                {
                    return(false);
                }
                List <BodyShopPrivateLabelBL> lstBodyShopPrivateLabel = BodyShopPrivateLabelBL.GetShopListByPrivateLabelId(iPrivateLabelId);
                if (lstBodyShopPrivateLabel == null || lstBodyShopPrivateLabel.Count == 0)
                {
                    return(false);
                }
                List <MessageBL> lstMessage = MessageBL.getDataByUserIdAndType(iUserId, Constants.REGISTRATIONMESSAGTYPE);
                Boolean          bFound     = false;
                if (lstMessage != null && lstMessage.Count > 0)
                {
                    foreach (MessageBL objMessage in lstMessage)
                    {
                        if (objMessage.iShopID == null)
                        {
                            objMessage.bIsRead    = true;
                            objMessage.strMessage = Constants.REGISTRATIONMESSAGE;
                            if (iPrivateLabelId != 0)
                            {
                                objMessage.iPrivateLabelID = iPrivateLabelId;
                            }
                        }
                        else
                        {
                            objMessage.bIsRead    = false;
                            objMessage.iShopID    = iShopId;
                            objMessage.strMessage = Constants.PREFFEREDSHOPMESSAGE;
                            bFound = true;
                        }
                        objMessage.Save();
                    }
                }
                else
                {
                    MessageBL objMessage = new MessageBL();
                    objMessage.iPhoneUserID  = iUserId;
                    objMessage.iType         = Constants.REGISTRATIONMESSAGTYPE;
                    objMessage.strMessage    = Constants.REGISTRATIONMESSAGE;
                    objMessage.bIsRead       = false;
                    objMessage.dtMessageTime = DateTime.Now;
                    if (iPrivateLabelId != 0)
                    {
                        objMessage.iPrivateLabelID = iPrivateLabelId;
                    }
                    objMessage.Save();

                    MessageBL _objMessage = new MessageBL();
                    _objMessage.iShopID       = iShopId;
                    _objMessage.iPhoneUserID  = iUserId;
                    _objMessage.iType         = Constants.REGISTRATIONMESSAGTYPE;
                    _objMessage.strMessage    = Constants.PREFFEREDSHOPMESSAGE;
                    _objMessage.bIsRead       = false;
                    _objMessage.dtMessageTime = DateTime.Now;
                    _objMessage.Save();
                    bFound = true;
                }
                if (!bFound)
                {
                    MessageBL _objMessage = new MessageBL();
                    _objMessage.iShopID       = iShopId;
                    _objMessage.iPhoneUserID  = iUserId;
                    _objMessage.iType         = Constants.REGISTRATIONMESSAGTYPE;
                    _objMessage.strMessage    = Constants.PREFFEREDSHOPMESSAGE;
                    _objMessage.bIsRead       = false;
                    _objMessage.dtMessageTime = DateTime.Now;
                    _objMessage.Save();
                }
            }
            catch (Exception ex)
            {
            }
            return(false);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Boolean bResult = false;

            try
            {
                String strPhoneId  = String.Empty;
                String strPhoneId1 = String.Empty;

                if (!String.IsNullOrEmpty(Request.QueryString["ShopID"]))
                {
                    if (Request.QueryString["User_ID"] != null)
                    {
                        strPhoneId1 = Request.QueryString["User_ID"];
                    }
                    else if (Request.Form["User_ID"] != null)
                    {
                        strPhoneId1 = Request.Form["User_ID"];
                    }
                    if (!Int32.TryParse(Security.DecodeNumbers(Request.QueryString["ShopID"]), out iShopID))
                    {
                        return;
                    }
                }
                else
                {
                    if (Request.QueryString["User_ID"] != null)
                    {
                        strPhoneId = Request.QueryString["User_ID"];
                    }
                    else if (Request.Form["User_ID"] != null)
                    {
                        strPhoneId = Request.Form["User_ID"];
                    }
                }
                UserBL objUser = null;
                if (!String.IsNullOrEmpty(strPhoneId))
                {
                    //if phone user id is found
                    objUser = UserBL.getDataByPhoneId(strPhoneId);
                }
                else
                {
                    MyCustomerBL objMyCustomer = MyCustomerBL.getDataByShopIdNPhone(iShopID, strPhoneId1);
                    if (objMyCustomer != null)
                    {
                        objUser = UserBL.getByActivityId(objMyCustomer.iUserId.Value);
                    }
                }

                if (objUser != null)
                {
                    String strUserName = String.Empty;

                    if (string.IsNullOrEmpty(objUser.strUserName))
                    {
                        if (Request.QueryString["Phone_Owner_Name"] != null)
                        {
                            objUser.strUserName = Request.QueryString["Phone_Owner_Name"];
                        }
                        else if (Request.Form["Phone_Owner_Name"] != null && !string.IsNullOrEmpty(Request.Form["Phone_Owner_Name"].ToString()))
                        {
                            objUser.strUserName = Request.Form["Phone_Owner_Name"];
                        }
                    }
                    objUser.Save();

                    UserPreferredShopBL objUserPreferredShop = UserPreferredShopBL.getShopByUserId(objUser.ID);



                    MessageBL objMessage = null;
                    if (objUserPreferredShop != null || iShopID > 0)
                    {
                        objMessage = new MessageBL();
                        objMessage.iPhoneUserID = objUser.ID;
                        if (objUserPreferredShop != null)
                        {
                            objMessage.iShopID = objUserPreferredShop.iShopId;
                        }
                        else
                        {
                            objMessage.iShopID = iShopID;
                        }
                        objMessage.dtMessageTime = DateTime.Now;

                        if (Request.QueryString["Message"] != null)
                        {
                            objMessage.strMessage = Request.QueryString["Message"].ToString();
                        }
                        else if (Request.Form["Message"] != null)
                        {
                            objMessage.strMessage = Request.Form["Message"].ToString();
                        }

                        String strType = String.Empty;
                        if (Request.QueryString["MessageType"] != null)
                        {
                            strType = Request.QueryString["MessageType"].ToString();
                        }
                        else if (Request.Form["MessageType"] != null)
                        {
                            strType = Request.Form["MessageType"].ToString();
                        }

                        String[] strPhoneNumbers = null;
                        if (Request.QueryString["smsTo"] != null)
                        {
                            strPhoneNumbers = Request.QueryString["smsTo"].ToString().Split(',');
                        }

                        if (strType.ToLower() == "predefinedsms" && Request.QueryString["Message"] != null)
                        {
                            String strMSG = Request.QueryString["Message"].ToString();
                            if (strPhoneNumbers != null)
                            {
                                SMS objSMS = new SMS();
                                foreach (String item in strPhoneNumbers)
                                {
                                    objSMS.SendSMS(item, objMessage.strMessage, objUser.strPhone, objUser.ID);
                                }
                            }
                        }

                        try
                        {
                            if (Request.QueryString["Latitude"] != null)
                            {
                                objMessage.fLatitude = Convert.ToDouble(Request.QueryString["Latitude"]);
                            }
                            else if (Request.Form["Latitude"] != null)
                            {
                                objMessage.fLatitude = Convert.ToDouble(Request.Form["Latitude"]);
                            }
                        }
                        catch (Exception ex)
                        {
                            objMessage.fLatitude = 0.0;
                        }
                        try
                        {
                            if (Request.QueryString["Longitude"] != null)
                            {
                                objMessage.fLongitude = Convert.ToDouble(Request.QueryString["Longitude"]);
                            }
                            else if (Request.Form["Longitude"] != null)
                            {
                                objMessage.fLongitude = Convert.ToDouble(Request.Form["Longitude"]);
                            }
                        }
                        catch (Exception ex)
                        {
                            objMessage.fLongitude = 0.0;
                        }
                        objMessage.iType = Constants.PredefinedSMS;

                        objMessage.Save();

                        BodyShopBL objBodyShop = null;
                        if (objUserPreferredShop != null)
                        {
                            objBodyShop = BodyShopBL.getShopById(Convert.ToInt32(objUserPreferredShop.iShopId));
                        }
                        else
                        {
                            objBodyShop = BodyShopBL.getShopById(iShopID);
                        }

                        if (objBodyShop != null)
                        {
                            objBodyShop.iNoHelpSelection = (objBodyShop.iNoHelpSelection == null) ? 1 : (objBodyShop.iNoHelpSelection + 1);

                            if (objBodyShop.Save())
                            {
                                if (Cache["CommunicationList"] != null)
                                {
                                    Cache.Remove("CommunicationList");
                                }
                                if (Cache["OpportunityList"] != null)
                                {
                                    Cache.Remove("OpportunityList");
                                }
                                if (Cache["RepairProspect"] != null)
                                {
                                    Cache.Remove("RepairProspect");
                                }
                                if (Cache["EmailMarketing"] != null)
                                {
                                    Cache.Remove("EmailMarketing");
                                }
                                if (Cache["TextMarketing"] != null)
                                {
                                    Cache.Remove("TextMarketing");
                                }
                                bResult = true;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                bResult = false;
            }

            XmlDocument  xmlDoc = new XmlDocument();
            MemoryStream stream = new MemoryStream();
            //XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.ASCII);
            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

            xmlWriter.WriteStartDocument();
            xmlWriter.WriteStartElement("EditCountReport");
            xmlWriter.WriteElementString("Status", bResult ? "Success" : "Fail");
            xmlWriter.WriteEndElement();
            xmlWriter.WriteEndDocument();
            xmlWriter.Flush();
            byte[] byteArray = stream.ToArray();
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "filename=MyExportedFile.xml");
            HttpContext.Current.Response.AppendHeader("Content-Length", byteArray.Length.ToString());
            HttpContext.Current.Response.ContentType = "text/xml";
            HttpContext.Current.Response.BinaryWrite(byteArray);
        }
Beispiel #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Boolean bResult = false;

            try
            {
                String strPhoneId  = String.Empty;
                String strPhoneId1 = String.Empty;

                if (!String.IsNullOrEmpty(Request.QueryString["ShopID"]))
                {
                    if (Request.QueryString["User_ID"] != null)
                    {
                        strPhoneId1 = Request.QueryString["User_ID"];
                    }
                    else if (Request.Form["User_ID"] != null)
                    {
                        strPhoneId1 = Request.Form["User_ID"];
                    }
                    if (!Int32.TryParse(Security.DecodeNumbers(Request.QueryString["ShopID"]), out iShopID))
                    {
                        return;
                    }
                }
                else
                {
                    if (Request.QueryString["User_ID"] != null)
                    {
                        strPhoneId = Request.QueryString["User_ID"];
                    }
                    else if (Request.Form["User_ID"] != null)
                    {
                        strPhoneId = Request.Form["User_ID"];
                    }
                }
                UserBL objUser = null;
                if (!String.IsNullOrEmpty(strPhoneId))
                {
                    //if phone user id is found
                    objUser = UserBL.getDataByPhoneId(strPhoneId);
                }
                else
                {
                    MyCustomerBL objMyCustomer = MyCustomerBL.getDataByShopIdNPhone(iShopID, strPhoneId1);
                    if (objMyCustomer != null)
                    {
                        objUser = UserBL.getByActivityId(objMyCustomer.iUserId.Value);
                    }
                }
                if (objUser != null)
                {
                    //if user of that phone user id is found fill message info
                    String strUserName = String.Empty;

                    if (string.IsNullOrEmpty(objUser.strUserName))
                    {
                        if (Request.QueryString["Phone_Owner_Name"] != null)
                        {
                            objUser.strUserName = Request.QueryString["Phone_Owner_Name"];
                        }
                        else if (Request.Form["Phone_Owner_Name"] != null && !string.IsNullOrEmpty(Request.Form["Phone_Owner_Name"].ToString()))
                        {
                            objUser.strUserName = Request.Form["Phone_Owner_Name"];
                        }
                    }

                    //if (!String.IsNullOrEmpty(strUserName) && objUser.strFirstName != strUserName)
                    //{
                    //if user's first name is changed replace it
                    //objUser.strFirstName = strUserName;
                    objUser.Save();
                    //}

                    UserPreferredShopBL objUserPreferredShop = UserPreferredShopBL.getShopByUserId(objUser.ID);



                    if (objUserPreferredShop != null || iShopID > 0)
                    {
                        String strMSG = String.Empty;
                        //save the message against his preferred body shop
                        MessageBL objMessage = new MessageBL();
                        objMessage.iPhoneUserID = objUser.ID;
                        if (objUserPreferredShop != null)
                        {
                            objMessage.iShopID = objUserPreferredShop.iShopId;
                        }
                        else
                        {
                            objMessage.iShopID = iShopID;
                        }
                        objMessage.dtMessageTime = DateTime.Now;

                        if (Request.QueryString["Message"] != null)
                        {
                            objMessage.strMessage = Request.QueryString["Message"].ToString();
                        }
                        else if (Request.Form["Message"] != null)
                        {
                            objMessage.strMessage = Request.Form["Message"].ToString();
                        }

                        String strType = String.Empty;
                        if (Request.QueryString["MessageType"] != null)
                        {
                            strType = Request.QueryString["MessageType"].ToString();
                        }
                        else if (Request.Form["MessageType"] != null)
                        {
                            strType = Request.Form["MessageType"].ToString();
                        }

                        //Check isSendSMS flag to send SMS via Web Application
                        Boolean bIsSendSMS       = false;
                        String  strBodyShopPhone = String.Empty;
                        if (Request.QueryString["sendSMS"] != null && Request.QueryString["sendSMS"].ToString() == "1")
                        {
                            bIsSendSMS = true;
                        }

                        BodyShopBL objBodyShop = null;
                        if (objUserPreferredShop != null && objUserPreferredShop.iShopId.HasValue)
                        {
                            objBodyShop = BodyShopBL.getShopById(objUserPreferredShop.iShopId.Value);
                        }
                        else if (iShopID > 0)
                        {
                            objBodyShop = BodyShopBL.getShopById(iShopID);
                        }
                        if (objBodyShop != null && objBodyShop.strPhone != null)
                        {
                            strBodyShopPhone = objBodyShop.strPhone;
                        }

                        if (!String.IsNullOrEmpty(strType))
                        {
                            switch (strType.ToLower())
                            {
                            //select the message type eg. SMS, Email, Predefined SMS
                            case "sms":
                                objMessage.iType = Constants.SMS;
                                if (bIsSendSMS)
                                {
                                    if (!String.IsNullOrEmpty(strBodyShopPhone))
                                    {
                                        SMS objSMS = new SMS();
                                        objSMS.SendSMS(strBodyShopPhone, objMessage.strMessage, objUser.strPhone, objUser.ID);
                                    }
                                }
                                break;

                            case "email":
                                objMessage.iType = Constants.Email;
                                break;

                            case "predefinedsms":
                                objMessage.iType = Constants.PredefinedSMS;
                                break;
                            }
                        }

                        //save the message n if saved return true to phone n remove cache
                        if (objMessage.Save())
                        {
                            bResult = true;
                            if (objMessage.iType == Constants.PredefinedSMS)
                            {
                                if (Cache["OpportunityList"] != null)
                                {
                                    Cache.Remove("OpportunityList");
                                }
                            }
                            else if (objMessage.iType == Constants.SMS || objMessage.iType == Constants.Email)
                            {
                                if (Cache["CommunicationList"] != null)
                                {
                                    Cache.Remove("CommunicationList");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                bResult = false;
            }

            XmlDocument  xmlDoc = new XmlDocument();
            MemoryStream stream = new MemoryStream();
            //XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.ASCII);
            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

            xmlWriter.WriteStartDocument();
            xmlWriter.WriteStartElement("MessageReport");
            xmlWriter.WriteElementString("Status", bResult ? "Success" : "Fail");
            xmlWriter.WriteEndElement();
            xmlWriter.WriteEndDocument();
            xmlWriter.Flush();
            byte[] byteArray = stream.ToArray();
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "filename=MyExportedFile.xml");
            HttpContext.Current.Response.AppendHeader("Content-Length", byteArray.Length.ToString());
            HttpContext.Current.Response.ContentType = "text/xml";
            HttpContext.Current.Response.BinaryWrite(byteArray);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Boolean bResult = false;

            try
            {
                //String strPhoneId = String.Empty;

                ////get the phone user id
                //if (Request.QueryString["User_ID"] != null)
                //    strPhoneId = Request.QueryString["User_ID"];
                //else if (Request.Headers["User_ID"] != null)
                //    strPhoneId = Request.Headers["User_ID"];
                //else if (Request.Form["User_ID"] != null)
                //    strPhoneId = Request.Form["User_ID"];
                String strPhoneId  = String.Empty;
                String strPhoneId1 = String.Empty;

                if (!String.IsNullOrEmpty(Request.QueryString["ShopID"]))
                {
                    if (Request.QueryString["User_ID"] != null)
                    {
                        strPhoneId1 = Request.QueryString["User_ID"];
                    }
                    else if (Request.Headers["User_ID"] != null)
                    {
                        strPhoneId = Request.Headers["User_ID"];
                    }
                    else if (Request.Form["User_ID"] != null)
                    {
                        strPhoneId1 = Request.Form["User_ID"];
                    }
                    if (!Int32.TryParse(Security.DecodeNumbers(Request.QueryString["ShopID"]), out iShopID))
                    {
                        return;
                    }
                }
                else
                {
                    if (Request.QueryString["User_ID"] != null)
                    {
                        strPhoneId = Request.QueryString["User_ID"];
                    }
                    else if (Request.Headers["User_ID"] != null)
                    {
                        strPhoneId = Request.Headers["User_ID"];
                    }
                    else if (Request.Form["User_ID"] != null)
                    {
                        strPhoneId = Request.Form["User_ID"];
                    }
                }
                UserBL objUser = null;
                if (!String.IsNullOrEmpty(strPhoneId))
                {
                    string[] strPhones = strPhoneId.Split('_');

                    //find user using phoneID for private label
                    if (strPhones.Length == 3)
                    {
                        objUser = UserBL.getDataByPhoneId(strPhoneId);
                    }
                    else
                    {
                        objUser = UserBL.GetDataByPhoneNumber(strPhones[0]);
                    }
                    if (objUser != null)
                    {
                        MyCustomerBL objMyCustomer = MyCustomerBL.getDataByUserId(objUser.ID);
                        if (objMyCustomer != null)
                        {
                            iShopID = objMyCustomer.iShopId;
                        }
                    }
                }
                else
                {
                    MyCustomerBL objMyCustomer = MyCustomerBL.getDataByShopIdNPhone(iShopID, strPhoneId1);
                    if (objMyCustomer != null)
                    {
                        objUser = UserBL.getByActivityId(objMyCustomer.iUserId.Value);
                    }
                }
                if (objUser != null)
                {
                    //if user of previous phone user id is found fill his accident report information
                    String strUserName = String.Empty;

                    if (String.IsNullOrEmpty(objUser.strUserName))
                    {
                        if (Request.QueryString["Phone_Owner_Name"] != null)
                        {
                            strUserName = Request.QueryString["Phone_Owner_Name"];
                        }
                        else if (Request.Headers["Phone_Owner_Name"] != null)
                        {
                            strUserName = Request.Headers["Phone_Owner_Name"];
                        }
                        else if (Request.Form["Phone_Owner_Name"] != null)
                        {
                            strUserName = Request.Form["Phone_Owner_Name"];
                        }
                    }

                    if (!String.IsNullOrEmpty(strUserName) && objUser.strFirstName != strUserName)
                    {
                        //if user's first name is changed
                        objUser.strFirstName = strUserName;
                        objUser.Save();
                    }
                    UserPreferredShopBL objUserPreferredShop = UserPreferredShopBL.getShopByUserId(objUser.ID);


                    MessageBL objMessage = null;
                    if (objUserPreferredShop != null || iShopID > 0)
                    {
                        String strMessage = "Requested Appointment on: ";
                        if (Request.QueryString["datetime"] != null)
                        {
                            strMessage = strMessage + String.Format("{0:g}", Convert.ToDateTime(Request.QueryString["datetime"].ToString()));
                        }
                        else if (Request.Headers["datetime"] != null)
                        {
                            strMessage = strMessage + String.Format("{0:g}", Convert.ToDateTime(Request.Headers["datetime"].ToString()));
                        }
                        else if (Request.Form["datetime"] != null)
                        {
                            DateTime dtAppointmentDate;
                            DateTime.TryParse((Request.Form["datetime"].ToString()), out dtAppointmentDate);
                            strMessage = strMessage + String.Format("{0:g}", dtAppointmentDate.ToString());
                        }



                        if (Request.QueryString["reason"] != null)
                        {
                            strMessage = strMessage + " For: " + Request.QueryString["reason"].ToString();
                        }
                        else if (Request.Headers["reason"] != null)
                        {
                            strMessage = strMessage + " For: " + Request.Headers["reason"].ToString();
                        }
                        else if (Request.Form["reason"] != null)
                        {
                            strMessage = strMessage + " For: " + Request.Form["reason"].ToString();
                        }
                        //add one message against his preferred shop
                        objMessage              = new MessageBL();
                        objMessage.strMessage   = strMessage;
                        objMessage.iPhoneUserID = objUser.ID;
                        if (objUserPreferredShop != null)
                        {
                            objMessage.iShopID = objUserPreferredShop.iShopId;
                        }
                        else
                        {
                            objMessage.iShopID = iShopID;
                        }
                        objMessage.dtMessageTime = DateTime.Now;
                        objMessage.iType         = Constants.REQUEST_APPOINTMENT;
                        if (objMessage.Save())
                        {
                            bResult = true;
                        }
                    }
                    else if (iShopID > 0)
                    {
                        String strMessage = "Requested Appointment on: ";
                        if (Request.QueryString["datetime"] != null)
                        {
                            strMessage = strMessage + String.Format("{0:g}", Convert.ToDateTime(Request.QueryString["datetime"].ToString()));
                        }
                        else if (Request.Headers["datetime"] != null)
                        {
                            strMessage = strMessage + String.Format("{0:g}", Convert.ToDateTime(Request.Headers["datetime"].ToString()));
                        }
                        else if (Request.Form["datetime"] != null)
                        {
                            DateTime dtAppointmentDate;
                            DateTime.TryParse((Request.Form["datetime"].ToString()), out dtAppointmentDate);
                            strMessage = strMessage + String.Format("{0:g}", dtAppointmentDate.ToString());
                        }



                        if (Request.QueryString["reason"] != null)
                        {
                            strMessage = strMessage + " For: " + Request.QueryString["reason"].ToString();
                        }
                        else if (Request.Headers["reason"] != null)
                        {
                            strMessage = strMessage + " For: " + Request.Headers["reason"].ToString();
                        }
                        else if (Request.Form["reason"] != null)
                        {
                            strMessage = strMessage + " For: " + Request.Form["reason"].ToString();
                        }
                        //add one message against his preferred shop
                        objMessage               = new MessageBL();
                        objMessage.strMessage    = strMessage;
                        objMessage.iPhoneUserID  = objUser.ID;
                        objMessage.iShopID       = iShopID;
                        objMessage.dtMessageTime = DateTime.Now;
                        objMessage.iType         = Constants.REQUEST_APPOINTMENT;
                        if (objMessage.Save())
                        {
                            bResult = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                bResult = false;
            }

            XmlDocument  xmlDoc = new XmlDocument();
            MemoryStream stream = new MemoryStream();
            //XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.ASCII);
            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

            xmlWriter.WriteStartDocument();
            xmlWriter.WriteStartElement("ScheduleRepairAppointment");
            xmlWriter.WriteElementString("Status", bResult ? "Success" : "Fail");
            xmlWriter.WriteEndElement();
            xmlWriter.WriteEndDocument();
            xmlWriter.Flush();
            byte[] byteArray = stream.ToArray();
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "filename=MyExportedFile.xml");
            HttpContext.Current.Response.AppendHeader("Content-Length", byteArray.Length.ToString());
            HttpContext.Current.Response.ContentType = "text/xml";
            HttpContext.Current.Response.BinaryWrite(byteArray);
        }