Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Boolean       bResult        = false;
            VehicleInfoBL objVehicleInfo = new VehicleInfoBL();

            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;
                    String strPhone    = 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 (Request.QueryString["Current_Phone_Number"] != null)
                    {
                        strPhone = Request.QueryString["Current_Phone_Number"];
                    }
                    else if (Request.Form["Current_Phone_Number"] != null)
                    {
                        strPhone = Request.Form["Current_Phone_Number"];
                    }

                    String        strPhoneNumber = strPhone;
                    StringBuilder strNewNumber   = new StringBuilder();
                    foreach (char c in strPhoneNumber)
                    {
                        if (Char.IsNumber(c))
                        {
                            strNewNumber.Append(c);
                        }
                    }


                    objUser.strPhone = String.IsNullOrEmpty(strPhone) ? objUser.strPhone : strPhone;

                    //if (!String.IsNullOrEmpty(strUserName) && objUser.strFirstName != strUserName)
                    //{
                    //    objUser.strFirstName = strUserName;
                    //}
                    objUser.Save();

                    objVehicleInfo.iUserId = objUser.ID;

                    if (Request.QueryString["Model"] != null && Request.QueryString["Model"] != "undefined")
                    {
                        objVehicleInfo.strModel = Request.QueryString["Model"].ToString();
                    }
                    else if (Request.Form["Model"] != null && Request.Form["Model"] != "undefined")
                    {
                        objVehicleInfo.strModel = Request.Form["Model"].ToString();
                    }

                    if (Request.QueryString["Make"] != null && Request.QueryString["Make"] != "undefined")
                    {
                        objVehicleInfo.strMake = Request.QueryString["Make"].ToString();
                    }
                    else if (Request.Form["Make"] != null && Request.Form["Make"] != "undefined")
                    {
                        objVehicleInfo.strMake = Request.Form["Make"].ToString();
                    }

                    if (Request.QueryString["Year"] != null && Request.QueryString["Year"] != "undefined")
                    {
                        objVehicleInfo.strYear = Request.QueryString["Year"].ToString();
                    }
                    else if (Request.Form["Year"] != null && Request.Form["Year"] != "undefined")
                    {
                        objVehicleInfo.strYear = Request.Form["Year"].ToString();
                    }

                    if (Request.QueryString["OtherInfo"] != null && Request.QueryString["OtherInfo"] != "undefined")
                    {
                        objVehicleInfo.strOtherInfo = Request.QueryString["OtherInfo"].ToString();
                    }
                    else if (Request.Form["OtherInfo"] != null && Request.Form["OtherInfo"] != "undefined")
                    {
                        objVehicleInfo.strOtherInfo = Request.Form["OtherInfo"].ToString();
                    }

                    if (Request.QueryString["IsUsing"] != null && Request.QueryString["IsUsing"] != "undefined")
                    {
                        objVehicleInfo.bIsUsing = Convert.ToBoolean(Request.QueryString["IsUsing"]);
                    }
                    else if (Request.Form["IsUsing"] != null && Request.Form["IsUsing"] != "undefined")
                    {
                        objVehicleInfo.bIsUsing = Convert.ToBoolean(Request.Form["IsUsing"]);
                    }

                    if (objVehicleInfo.bIsUsing != null)
                    {
                        if (Convert.ToBoolean(objVehicleInfo.bIsUsing))
                        {
                            List <VehicleInfoBL> objUserVehicles = VehicleInfoBL.getDataByUserId(objUser.ID);
                            if (objUserVehicles != null)
                            {
                                foreach (VehicleInfoBL objTemp in objUserVehicles)
                                {
                                    if (objTemp.strMake.Equals(objVehicleInfo.strMake) && objTemp.strModel.Equals(objVehicleInfo.strModel) && objTemp.strYear.Equals(objVehicleInfo.strYear))
                                    {
                                        objVehicleInfo          = objTemp;
                                        objVehicleInfo.bIsUsing = true;
                                    }
                                    else
                                    {
                                        objTemp.bIsUsing = false;
                                        objTemp.Save();
                                    }
                                }
                            }
                        }
                    }
                    if (objVehicleInfo.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 = true;
            }

            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("VehicleInformation");
            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);
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                String strPhoneId = String.Empty;
                String strImage   = String.Empty;
                String strNewApp  = String.Empty;

                if (!String.IsNullOrEmpty(Request.QueryString["ShopID"]))
                {
                    if (!Int32.TryParse(Security.DecodeNumbers(Request.QueryString["ShopID"]), out iShopID))
                    {
                        return;
                    }
                }
                //else
                //{
                //    Int32.TryParse(strNewApp, out iShopID);
                //}


                if (Request.QueryString["User_Id"] != null)
                {
                    strPhoneId = Request.QueryString["User_Id"];
                    strNewApp  = Request.QueryString["N"];
                }
                else if (Request.Form["User_Id"] != null)
                {
                    strPhoneId = Request.Form["User_Id"];
                    strNewApp  = Request.Form["N"];
                }

                //Check phone no is not empty/null
                if (!String.IsNullOrEmpty(strPhoneId))
                {
                    List <MyCustomerBL> lstMyCustomer = null;
                    UserBL objUser = null;
                    if (iShopID != 0)
                    {
                        MyCustomerBL objMyCustomer = null;
                        lstMyCustomer = MyCustomerBL.getDataByShopIDandMobileList(iShopID, strPhoneId);

                        if (lstMyCustomer != null && lstMyCustomer.Count > 0)
                        {
                            objMyCustomer = lstMyCustomer.Find(t => t.strStatusOfVehicle.ToLower().Trim() != Constants.VEHICLE_STATUS_DELIVERED.ToLower().Trim());
                        }

                        if (objMyCustomer != null)
                        {
                            if (!String.IsNullOrEmpty(objMyCustomer.strStatusOfVehicle))
                            {
                                //If status is delivered then dont show details for this customer
                                if (objMyCustomer.strStatusOfVehicle.ToLower().Trim() == Constants.VEHICLE_STATUS_DELIVERED.ToLower().Trim())
                                {
                                    return;
                                }
                            }



                            objUser = UserBL.getByActivityId(objMyCustomer.iUserId.Value);
                            //remove diffrent name customers, there should be only same name customers
                            lstMyCustomer.RemoveAll(p1 => p1.strUserName != objMyCustomer.strUserName);
                        }

                        ////Find User using phone no & shopID
                        //MyCustomerBL objMyCustomer = MyCustomerBL.getDataByShopIdNPhone(iShopID, strPhoneId);
                        //if (objMyCustomer != null)
                        //{
                        //    objUser = UserBL.getByActivityId(objMyCustomer.iUserId.Value);

                        //}
                    }
                    else
                    {
                        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)
                    {
                        List <VehicleInfoBL> lstVehicleInfo = null;
                        if (lstMyCustomer != null)
                        {
                            lstVehicleInfo = new List <VehicleInfoBL>();
                            foreach (MyCustomerBL objMyCustomerBL in lstMyCustomer)
                            {
                                //get Customer's Vehicle Details
                                lstVehicleInfo.AddRange(VehicleInfoBL.getDataByUserId(objMyCustomerBL.iUserId.Value));
                            }
                        }
                        else
                        {
                            //if user found get vehicle info
                            lstVehicleInfo = VehicleInfoBL.getDataByUserId(objUser.ID);
                        }
                        if (lstVehicleInfo != null)
                        {
                            foreach (var objVehicleInfo in lstVehicleInfo)
                            {
                                //get count of vehicle media links newly uploaded
                                iCount += VehicleMediaLinkBL.getNewLinkCountByVehicleID(objVehicleInfo.ID);
                                //get Vehicle status Changed
                                UserVehicleStatusBL objUserVehicleStatusBL = UserVehicleStatusBL.getDataByVehicleId(objVehicleInfo.ID);
                                if (objUserVehicleStatusBL != null && objUserVehicleStatusBL.bIsRead.HasValue && objUserVehicleStatusBL.bIsRead.Value == 1)
                                {
                                    strVehicleStatus = "true";
                                }
                            }
                            ////Find current vehicle info
                            //VehicleInfoBL objVehicleInfo = lstVehicleInfo.Find(p => p.bIsUsing == true || p.bIsUsing == null);
                            //if (objVehicleInfo != null)
                            //{
                            //    //get count of vehicle media links newly uploaded
                            //    iCount = VehicleMediaLinkBL.getNewLinkCountByVehicleID(objVehicleInfo.ID);
                            //    //get Vehicle status Changed
                            //    UserVehicleStatusBL objUserVehicleStatusBL = UserVehicleStatusBL.getDataByVehicleId(objVehicleInfo.ID);
                            //    if (objUserVehicleStatusBL != null && objUserVehicleStatusBL.bIsRead.HasValue && objUserVehicleStatusBL.bIsRead.Value == 1)
                            //        strVehicleStatus = "true";
                            //}
                        }
                    }
                    //for sending info to html5 app using xml
                    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("VehicleMediaCount");
                    //count for newly uploaded vehiclemedia links
                    xmlWriter.WriteElementString("Count", String.IsNullOrEmpty(iCount.ToString()) ? "" : iCount.ToString());
                    //check vehicleStatus
                    xmlWriter.WriteElementString("VehicleStatus", String.IsNullOrEmpty(strVehicleStatus) ? "" : strVehicleStatus);


                    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);
                }
            }
            catch (Exception ex)
            {
            }
        }