protected void btnAddIndustry_Click(object sender, EventArgs e)
        {
            if (txtAddIndustry.Text == "")
            {
                lblAddIndustryError.Text = "Required";
            }
            else
            {
                using (GESEntities db = new GESEntities())
                {
                    try
                    {
                        Industry newIndustry = new Industry();
                        newIndustry.IndustryName = txtAddIndustry.Text.ToString();
                        newIndustry.IndustryDescription = txtAddIndustry.Text.ToString();
                        newIndustry.Status = "Active";

                        db.Industries.AddObject(newIndustry);
                        db.SaveChanges();

                        txtAddIndustry.Text = "";
                        lblAddIndustry.Text = "Added succesfully";

                        lblAddIndustryError.Text = "";

                        refreshIndustryEDS();
                    }
                    catch (Exception exp)
                    {
                        throw new Exception("ERROR: Unable to Add entry - " + exp.Message.ToString(), exp);
                    }
                }
            }
        }
        protected void btnAddMachType_Click(object sender, EventArgs e)
        {
            if (txtAddMachType.Text == "")
            {
                lblAddMachTypeError.Text = "Required";
            }
            else
            {
                using (GESEntities db = new GESEntities())
                {
                    try
                    {
                        MachineType newMachineType = new MachineType();
                        newMachineType.MachineTypeName = txtAddMachType.Text.ToString();
                        newMachineType.MachineTypeDescription = txtAddMachType.Text.ToString();
                        newMachineType.Status = "Active";

                        db.MachineTypes.AddObject(newMachineType);
                        db.SaveChanges();

                        txtAddMachType.Text = "";
                        lblAddMach.Text = "Added succesfully";

                        lblAddMachTypeError.Text = "";

                        refreshMachineTypeEDS();
                    }
                    catch (Exception exp)
                    {
                        throw new Exception("ERROR: Unable to Add entry - " + exp.Message.ToString(), exp);
                    }
                }
            }
        }
Example #3
0
 void Application_Start(object sender, EventArgs e)
 {
     using (GESEntities db = new GESEntities())
     {
         var getCounters = (from c in db.Counters where c.CounterType == "UserCounter" select c.NumberOfHits).Sum();
         if (getCounters != null)
         {
             totalNumberOfUsers = Int32.Parse(getCounters.ToString());
         }
         else
         {
             totalNumberOfUsers = 0;
         }
     }
 }
Example #4
0
        protected void CreateUserButton_Click(object sender, EventArgs e)
        {
            lblError.Text = "";

            using (GESEntities db = new GESEntities())
            {
                try
                {
                    //Check that email doesn't exist
                    var getUser = (from c in db.Users where c.Email == Email.Text.ToString() select c).FirstOrDefault();

                    if (getUser != null)
                    {
                        lblError.Text = "This Email address has already been registered";
                    }
                    else
                    {

                        //Register user
                        User newUser = new User();
                        newUser.UserName = Guid.NewGuid().ToString();
                        newUser.Password = Password.Text.ToString();
                        newUser.Email = Email.Text.ToString();
                        //newUser.FirstName = txtFirstName.Text.ToString();
                        //newUser.LastName = txtSurname.Text.ToString();
                        //newUser.CellNo = txtCellNo.Text.ToString();
                        //newUser.AddrCity = txtTown.Text.ToString();
                        newUser.RoleID = 2;
                        db.Users.AddObject(newUser);
                        db.SaveChanges();

                        //Send Welcome Email
                        SendWelcomeMail(Email.Text.ToString());

                        Response.Redirect("~/MyQuip.aspx");
                    }
                }
                catch (Exception exp)
                {
                    throw new Exception("ERROR: Unable to register New User - " + exp.Message.ToString(), exp);
                }
            }
        }
        private void refreshEquipmentDetail()
        {
            using (GESEntities db = new GESEntities())
            {
                try
                {
                    int machineID = 0;

                    try
                    {
                        Int32.TryParse(Request["MachineID"].ToString(), out machineID);
                    }
                    catch
                    {
                        machineID = 0;
                    }

                    var MachineList = (from c in db.vUsedMachineLists where c.MachineID == machineID select c);

                    FormView_Product.DataSource = MachineList;
                    FormView_Product.DataSourceID = "";
                    FormView_Product.DataBind();

                    var machineDetail = MachineList.FirstOrDefault();

                    Page.Header.Title = machineDetail.ManufacturerName + " " + machineDetail.ModelName + " " + machineDetail.Year + " " + machineDetail.MachineTypeName + " for sale" + " " + machineDetail.Location;
                    Page.Header.Description = machineDetail.ManufacturerName + " " + machineDetail.ModelName + " " + machineDetail.Year + " " + machineDetail.MachineTypeName + " for sale" + " in " + machineDetail.Location;
                    Page.Header.Keywords = machineDetail.ManufacturerName + ", " + machineDetail.ModelName + ", " + machineDetail.Year + ", " + machineDetail.MachineTypeName + " for sale" + ", " + machineDetail.MachineTypeName + " for sale " + machineDetail.Location;
                    lblSearchResultLabel.Text = Page.Header.Title;
                }
                catch (Exception exp)
                {
                    throw new Exception("ERROR: Unable to retrieve machine info - " + exp.Message.ToString(), exp);
                }
            }
        }
        protected void gridPhotos_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int index = Convert.ToInt32(e.CommandArgument);

            string buttonPressed = e.CommandName.ToString();

            int PhotoID = Int32.Parse(this.gridPhotos.Rows[index].Cells[0].Text);
            int MachineID = Int32.Parse(lblMachineID.Text.Substring(lblMachineID.Text.IndexOf(":") + 1).Trim());

            if (buttonPressed == "deletePhoto")
            {
                //Delete from Photo table
                using (GESEntities db = new GESEntities())
                {
                    try
                    {
                        var deletePhoto = (from c in db.Photos where c.PhotoID == PhotoID select c).FirstOrDefault();
                        if (deletePhoto != null)
                        {
                            db.DeleteObject(deletePhoto);
                            db.SaveChanges();
                        }
                    }
                    catch (Exception exp)
                    {
                        throw new Exception("ERROR: Unable to delete photo - " + exp.Message.ToString(), exp);
                    }
                }

                //Delete from file server
                string fileName = this.gridPhotos.Rows[index].Cells[3].Text;
                fileName = Server.MapPath(fileName);
                File.Delete(fileName);
            }
            else if (buttonPressed == "setThumbnail")
            {
                using (GESEntities db = new GESEntities())
                {
                    try
                    {
                        var MachinePhotos = (from c in db.Photos where c.MachineID == MachineID select c);

                        if (MachinePhotos != null)
                        {
                            foreach (var MachinePhotoItem in MachinePhotos)
                            {
                                UpdateMachinePhotoRow(MachinePhotoItem.PhotoID);
                            }
                        }

                        var PhotoRow = (from c in db.Photos where c.PhotoID == PhotoID select c).FirstOrDefault();
                        if (PhotoRow != null)
                        {
                            PhotoRow.ShowThumbnail = "Y";
                            db.SaveChanges();
                        }
                    }
                    catch (Exception exp)
                    {
                        throw new Exception("ERROR: Unable to Set Thumbnail - " + exp.Message.ToString(), exp);
                    }
                }
            }
            //gridPhotos.SelectedIndex = e.NewSelectedIndex;

            //Refresh Grid
            PhotosEntityDataSource.WhereParameters.Clear();
            PhotosEntityDataSource.AutoGenerateWhereClause = true;
            PhotosEntityDataSource.WhereParameters.Add("MachineID", TypeCode.Int32, MachineID.ToString());
        }
 public void UpdateMachinePhotoRow(int MachinePhotoItem)
 {
     using (GESEntities db = new GESEntities())
     {
         try
         {
             var MachinePhotoRow = (from c in db.Photos where c.PhotoID == MachinePhotoItem select c).FirstOrDefault();
             if (MachinePhotoRow != null)
             {
                 MachinePhotoRow.ShowThumbnail = "N";
                 db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to update photo row- " + exp.Message.ToString(), exp);
         }
     }
 }
        private void refreshMachineTypeEDS()
        {
            using (GESEntities db = new GESEntities())
            {
                try
                {
                    var MachineList = (from c in db.MachineTypes where c.Status == "Active" select c).OrderBy(x => x.MachineTypeName);

                    lbMachineType.DataSource = MachineList;
                    lbMachineType.DataSourceID = "";
                    lbMachineType.DataBind();

                }
                catch (Exception ex)
                {
                }
            }
        }
        public void UpdateMachineRow(int MachineID)
        {
            using (GESEntities db = new GESEntities())
            {
                try
                {
                    var editMachine = (from c in db.Machines where c.MachineID == MachineID select c).FirstOrDefault();
                    if (editMachine  != null)
                    {
                        editMachine.ManufacturerID = Int32.Parse(listManufacturer.SelectedItem.Value);
                        editMachine.MachineTypeID = Int32.Parse(listMachineType.SelectedItem.Value);
                        editMachine.ModelID = Int32.Parse(listModel.SelectedItem.Value);
                        editMachine.IndustryID = Int32.Parse(listIndustry.SelectedItem.Value);
                        editMachine.MachineDescription = txtMachineDescription.Text.ToString();
                        editMachine.MachineGrade = txtMachineGrade.Text.ToString();
                        editMachine.SerialNo = txtSerial.Text.ToString();
                        editMachine.Year = txtYear.Text.ToString();
                        editMachine.Mileage = txtMileage.Text.ToString();
                        editMachine.Location = txtLocation.Text.ToString();
                        editMachine.CostPrice = ConvertStringDecimal(txtCostPrice.Text.ToString());
                        editMachine.SellPrice = ConvertStringDecimal(txtSalesPrice.Text.ToString());
                        editMachine.Status = listStatus.SelectedItem.Value;
                        editMachine.DealerMachine = listDealerMachine.SelectedItem.Value;

                        db.SaveChanges();
                    }
                }
                catch (Exception exp)
                {
                    throw new Exception("ERROR: Unable to Update Cart Item - " + exp.Message.ToString(), exp);
                }
            }
        }
Example #10
0
        protected void btnEnquiry_Click(object sender, EventArgs e)
        {
            int enquiryID = 0;

            using (GESEntities db = new GESEntities())
            {
                try
                {
                    //Create a visitor user ID if not already logged in
                    //------------------------------------------------------------------------+
                    //  Add New User Record                                                   |
                    //------------------------------------------------------------------------+
                    User newUser = new User();
                    newUser.UserName = "******" + Guid.NewGuid().ToString();
                    newUser.Password = "******";
                    newUser.FirstName = txtFirstName.Text.ToString();
                    newUser.LastName = txtSurname.Text.ToString();
                    newUser.Email = txtEmail.Text.ToString();
                    newUser.CellNo = txtCellNo.Text.ToString();
                    newUser.AddrCity = txtTown.Text.ToString();
                    newUser.RoleID = 1; //Visitor
                    db.Users.AddObject(newUser);
                    db.SaveChanges();

                    //------------------------------------------------------------------------+
                    //  Add New Enquiry Record                                                |
                    //------------------------------------------------------------------------+
                    Enquiry newEnquiry = new Enquiry();
                    newEnquiry.UserID = newUser.UserID;
                    newEnquiry.DateInserted = DateTime.Now;
                    newEnquiry.Comments = txtComments.Text.ToString();
                    newEnquiry.MachineID = 0;
                    db.Enquiries.AddObject(newEnquiry);
                    db.SaveChanges();

                    enquiryID = newEnquiry.EnquiryID;
                }
                catch (Exception exp)
                {
                    throw new Exception("ERROR: Unable to Submit Enquiry - " + exp.Message.ToString(), exp);
                }
            }

            //------------------------------------------------------------------------+
            //  Send off the email notification                                       |
            //------------------------------------------------------------------------+
            string body = "";
            string subject = "";

            using (GESEntities db = new GESEntities())
            {
                try
                {
                    subject = "GES Website Enquiry # " + enquiryID.ToString() + " from the JCB Parts Lead Page";

                    body = body +
                            "Lead Detail" + Environment.NewLine +
                            "-----------" + Environment.NewLine +
                            "First Name : " + txtFirstName.Text.ToString() + Environment.NewLine +
                            "Surname : " + txtSurname.Text.ToString() + Environment.NewLine +
                            "Email : " + txtEmail.Text.ToString() + Environment.NewLine +
                            "Cell No : " + txtCellNo.Text.ToString() + Environment.NewLine +
                            "Town : " + txtTown.Text.ToString() + Environment.NewLine +
                            "Comments/Requirements : " + txtComments.Text.ToString();

                    //Send Mail
                    MailMessage mailObj = new MailMessage("*****@*****.**", "*****@*****.**", subject, body);
                    mailObj.To.Add("*****@*****.**");
                    mailObj.CC.Add("*****@*****.**");
                    mailObj.Body = body.ToString();

                    SmtpClient SMTPServer = new SmtpClient();
                    SMTPServer.Host = "smtp.gmail.com";
                    SMTPServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "reevesie007");
                    SMTPServer.EnableSsl = true;
                    try
                    {
                        SMTPServer.Send(mailObj);

                        Response.Redirect("~/LeadManagement/Lead-Enquiry-Confirmation.aspx", false);
                    }
                    catch (Exception ex)
                    {
                        string error = ex.ToString();
                    }
                }
                catch (Exception exp)
                {
                    throw new Exception("ERROR: Unable to send mail - " + exp.Message.ToString(), exp);
                }
            }
        }
        //private void refreshManufacturerEDS()
        //{
        //    ManufacturerEntityDataSource.WhereParameters.Clear();
        //    ManufacturerEntityDataSource.AutoGenerateWhereClause = true;
        //    ManufacturerEntityDataSource.WhereParameters.Add("Status", TypeCode.String, "Active");
        //}
        protected void btnAddMachine_Click(object sender, EventArgs e)
        {
            string userName = "";
            System.Security.Principal.IPrincipal User = HttpContext.Current.User;
            userName = User.Identity.Name.ToUpper();

            if (userName == "DEMO")
            {
                string newMachineID = "0";
                string mode = Request["mode"].ToString();
                string industryID = Request["industryID"].ToString();
                string machineTypeID = Request["machineTypeID"].ToString();

                Response.Redirect("AddUsedEquipment_Page3.aspx?mode=" + mode + "&machineID=" + newMachineID + "&industryID=" + industryID + "&machineTypeID=" + machineTypeID + "&Model=" + tbModel.Text.Replace(" ", "-") + "&ManufacturerID=" + lbManufacturer.SelectedItem.Value + "&uploadMethod=arigma", false);
            }
            else
            {

                using (GESEntities db = new GESEntities())
                {
                    try
                    {
                        if (Request["mode"].ToString() == "new")
                        {
                            Machine newMachine = new Machine();
                            newMachine.ManufacturerID = Int32.Parse(lbManufacturer.SelectedItem.Value);
                            newMachine.MachineTypeID = Int32.Parse(Request["machineTypeID"].ToString());
                            newMachine.ModelName = tbModel.Text;
                            newMachine.IndustryID = Int32.Parse(Request["industryID"].ToString());
                            newMachine.MachineDescription = txtMachineDescription.Text.ToString();
                            newMachine.MachineGrade = txtMachineGrade.Text.ToString();
                            newMachine.SerialNo = txtSerial.Text.ToString();
                            newMachine.Year = txtYear.Text.ToString();
                            newMachine.Mileage = txtMileage.Text.ToString();
                            newMachine.Location = txtLocation.Text.ToString();
                            newMachine.ContactPerson = txtContactPerson.Text.ToString();
                            newMachine.EmailAddress = txtEmailAddress.Text.ToString();
                            newMachine.ContactNumber = txtContactNumber.Text.ToString();
                            newMachine.CostPrice = ConvertStringDecimal(txtCostPrice.Text.ToString());
                            newMachine.SellPrice = ConvertStringDecimal(txtSalesPrice.Text.ToString());
                            newMachine.Status = listStatus.SelectedItem.Value;
                            newMachine.DealerMachine = "N";
                            newMachine.DateInserted = DateTime.Now;

                            db.Machines.AddObject(newMachine);
                            db.SaveChanges();

                            string newMachineID = newMachine.MachineID.ToString();
                            string mode = Request["mode"].ToString();
                            string industryID = Request["industryID"].ToString();
                            string machineTypeID = Request["machineTypeID"].ToString();

                            Response.Redirect("AddUsedEquipment_Page3.aspx?mode=" + mode + "&machineID=" + newMachineID + "&industryID=" + industryID + "&machineTypeID=" + machineTypeID + "&Model=" + tbModel.Text.Replace(" ", "-") + "&ManufacturerID=" + lbManufacturer.SelectedItem.Value + "&uploadMethod=arigma", false);
                        }
                        else
                        {
                            int machineID = 0;
                            try
                            {
                                Int32.TryParse(Request["machineID"].ToString(), out machineID);
                            }
                            catch
                            {
                                machineID = 0;
                            }

                            var editMachine = (from c in db.Machines where c.MachineID == machineID select c).FirstOrDefault();
                            if (editMachine != null)
                            {
                                editMachine.ManufacturerID = Int32.Parse(lbManufacturer.SelectedItem.Value);
                                editMachine.MachineTypeID = Int32.Parse(Request["machineTypeID"].ToString());
                                editMachine.ModelName = tbModel.Text;
                                editMachine.IndustryID = Int32.Parse(Request["industryID"].ToString());
                                editMachine.MachineDescription = txtMachineDescription.Text.ToString();
                                editMachine.MachineGrade = txtMachineGrade.Text.ToString();
                                editMachine.SerialNo = txtSerial.Text.ToString();
                                editMachine.Year = txtYear.Text.ToString();
                                editMachine.Mileage = txtMileage.Text.ToString();
                                editMachine.Location = txtLocation.Text.ToString();
                                editMachine.CostPrice = ConvertStringDecimal(txtCostPrice.Text.ToString());
                                editMachine.SellPrice = ConvertStringDecimal(txtSalesPrice.Text.ToString());
                                editMachine.Status = listStatus.SelectedItem.Value;
                                editMachine.DealerMachine = "N";
                                editMachine.DateInserted = DateTime.Now;

                                db.SaveChanges();
                                Response.Redirect("AddUsedEquipment_Page3.aspx?mode=" + Request["mode"].ToString() + "&machineID=" + Request["machineID"].ToString() + "&industryID=" + Request["industryID"].ToString() + "&machineTypeID=" + Request["machineTypeID"].ToString() + "&Model=" + tbModel.Text.Replace(" ", "-") + "&ManufacturerID=" + lbManufacturer.SelectedItem.Value + "&uploadMethod=arigma", false);
                            }
                        }
                    }
                    catch (Exception exp)
                    {
                        if (exp.Message.Contains("inner exception"))
                        {
                            lblStatus.Text = "ERROR: Unable to add/edit used equipment- " + exp.InnerException.ToString();
                        }
                        else
                        {
                            lblStatus.Text = "ERROR: Unable to add/edit used equipment- " + exp.Message.ToString();
                        }
                    }
                }
            }
        }
Example #12
0
        void Session_Start(object sender, EventArgs e)
        {
            // Increase the two counters
            totalNumberOfUsers += 1;
            currentNumberOfUsers += 1;

            try
            {
                // Save the Total Number of Users to the database
                using (GESEntities db = new GESEntities())
                {
                    string execPath = Server.HtmlEncode(Request.CurrentExecutionFilePath);
                    DateTime sDate = DateTime.Now.Date;

                    var editCounters = (from c in db.Counters where c.CounterType == "UserCounter" && c.ExecutionPath == execPath && c.DateInserted == sDate select c).FirstOrDefault();
                    if (editCounters != null)
                    {
                        //Edit
                        editCounters.NumberOfHits += 1;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Insert
                        Counter newCounter = new Counter();
                        newCounter.CounterType = "UserCounter";
                        newCounter.NumberOfHits = 1;
                        newCounter.ExecutionPath = Server.HtmlEncode(Request.CurrentExecutionFilePath);
                        newCounter.DateInserted = DateTime.Now.Date;
                        db.Counters.AddObject(newCounter);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception exp)
            {
                throw new Exception("ERROR: Unable to update counter - " + exp.Message.ToString(), exp);
            }
        }
Example #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                int machineID = 0;
                try
                {
                    Int32.TryParse(Request["machineID"].ToString(), out machineID);
                }
                catch
                {
                    machineID = 0;
                }

                hfMachineID.Value = machineID.ToString();
                hfBody.Value = "";

                string source = "";

                try
                {
                    source = Request["source"].ToString();

                    if (source == "used-equipment")
                    {
                        using (GESEntities db = new GESEntities())
                        {
                            try
                            {
                                var Machines = (from p in db.vUsedMachineLists where p.MachineID == machineID select p).FirstOrDefault();

                                hfBody.Value = "Machine Details" + Environment.NewLine +
                                                "---------------" + Environment.NewLine +
                                                "Machine ID : " + Machines.MachineID + Environment.NewLine +
                                                "Manufacturer : " + Machines.ManufacturerName + Environment.NewLine +
                                                "Machine Type : " + Machines.MachineTypeName + Environment.NewLine +
                                                "Model : " + Machines.ModelName + Environment.NewLine +
                                                "Description : " + Machines.MachineDescription + Environment.NewLine +
                                                "Condition : " + Machines.MachineGrade + Environment.NewLine +
                                                "Serial # : " + Machines.SerialNo + Environment.NewLine +
                                                "Year : " + Machines.Year + Environment.NewLine +
                                                "Mileage : " + Machines.Mileage + Environment.NewLine +
                                                "Location : " + Machines.Location + Environment.NewLine +
                                                "Selling Price : " + Machines.SellPrice + Environment.NewLine +
                                                "Status : " + Machines.Status + Environment.NewLine +
                                                Environment.NewLine;

                            }
                            catch (Exception exp)
                            {
                                throw new Exception("ERROR: Unable to obtain machine detail - " + exp.Message.ToString(), exp);
                            }
                        }

                        txtComments.Text = "Please contact me urgently to discuss the following machine:" + Environment.NewLine + hfBody.Value;

                    }

                    if (source == "equipment-to-sell")
                    {
                        txtComments.Text = "Thanks for clicking our banner advertisement." + Environment.NewLine + Environment.NewLine + "Either give Mark a call on 0732115904 to discuss personally or complete this enquiry page and email pictures to [email protected]." + Environment.NewLine + Environment.NewLine + "When completing this enquiry page please provide as much information as possible i.e. Manufacturer, model, year, hours, condition, known defects/problems";
                    }

                    if (source == "grease-gun-ad")
                    {
                        txtComments.Text = "I'm interested in your Grease Gun promotion. Please contact me urgently to discuss.";
                    }

                    if (source == "roller-320d-ad")
                    {
                        txtComments.Text = "I'm interested in your 320D Roller for sale. Please contact me urgently to discuss.";
                    }

                    if (source == "140h-rim-for-sale-ad")
                    {
                        txtComments.Text = "I'm interested in your 140H Rim for sale. Please contact me urgently to discuss.";
                    }

                    if (source == "post-ad")
                    {
                        txtComments.Text = "Please contact me to discuss advertising on your site.";
                    }

                    if (source == "shantui-forklift-promo")
                    {
                        txtComments.Text = "I'm interested in your Shantui Forklift promotion. Please contact me urgently to discuss.";
                    }

                    if (source == "shantui-list-page")
                    {
                        using (GESEntities db = new GESEntities())
                        {
                            try
                            {
                                var Machines = (from p in db.Shantuis where p.ProductID == machineID select p).FirstOrDefault();

                                hfBody.Value = "Product Details" + Environment.NewLine +
                                                "---------------" + Environment.NewLine +
                                                "Product ID : " + Machines.ProductID + Environment.NewLine +
                                                "Category : " + Machines.Category + Environment.NewLine +
                                                "Model : " + Machines.Model + Environment.NewLine +
                                                Environment.NewLine;

                            }
                            catch (Exception exp)
                            {
                                throw new Exception("ERROR: Unable to obtain machine detail - " + exp.Message.ToString(), exp);
                            }
                        }

                        txtComments.Text = "Please contact me urgently to discuss the following Shantui machine:" + Environment.NewLine + Environment.NewLine + hfBody.Value;
                    }

                }
                catch
                {
                    source = "Unknown";
                }
            }
        }
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            if (uploadFile.HasFile == false)
            {
                    UploadDetails.Text = "Please first select a file to upload...";
            }
            else
            {
                using (GESEntities db = new GESEntities())
                {
                    int iMachineID = Int32.Parse(lblMachineID.Text.Substring(lblMachineID.Text.IndexOf(":") + 1).Trim());

                    //Fetch next photo # in the photo table for this machine
                    int iNextMachinePhotoID = 0;

                    System.Nullable < Int32 > GetNextPhoto = (from p in db.Photos where p.MachineID == iMachineID select (int?)p.MachinePhotoID).Max();

                    if (GetNextPhoto.HasValue)
                    {
                        iNextMachinePhotoID = GetNextPhoto.Value + 1;
                    }
                    else
                    {
                        iNextMachinePhotoID = 1;
                    }

                    //Save the image
                    string fileName = iMachineID.ToString() + "-" + iNextMachinePhotoID.ToString() + Path.GetExtension(uploadFile.FileName);
                    string filePath = Server.MapPath("~/UsedPics/" + fileName);

                    string fileNameTemp = "Temp" + iMachineID.ToString() + "-" + iNextMachinePhotoID.ToString() + Path.GetExtension(uploadFile.FileName);
                    string filePathTemp = Server.MapPath("~/UsedPics/" + fileNameTemp);
                    uploadFile.SaveAs(filePathTemp);

                    //Resize image
                    Bitmap mg = new Bitmap(filePathTemp);

                    int imgHeight = mg.Height;
                    int imgWidth = mg.Width;

                    bool resizeImage = false;

                    if (imgHeight >= imgWidth)
                    {
                        if (imgHeight > 480)
                        {
                            resizeImage = true;
                        }
                    }
                    else
                    {
                        if (imgWidth > 640)
                        {
                            resizeImage = true;
                        }
                    }

                    if (resizeImage)
                    {
                        Bitmap bp = FixedSize(mg, 640, 480);

                        bp.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
                        bp.Dispose();
                    }
                    else
                    {
                        Bitmap bp = FixedSize(mg, imgHeight, imgWidth);

                        bp.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
                        bp.Dispose();
                    }

                    mg.Dispose();

                    //delete Temp file
                    if (File.Exists(filePathTemp))
                    {
                        File.Delete(filePathTemp);
                    }

                    // Display the uploaded file's details
                    UploadDetails.Text = string.Format(@"Uploaded file: {0}<br /> File size (in bytes): {1:N0}<br /> Content-type: {2}", uploadFile.FileName, uploadFile.FileBytes.Length, uploadFile.PostedFile.ContentType);

                    //insert a row into the photos table
                    Photo newPhoto = new Photo();
                    newPhoto.MachineID = iMachineID;
                    newPhoto.PhotoName = "Test";
                    newPhoto.PhotoDescription = "Test";
                    newPhoto.PhotoUrl = "UsedPics/" + fileName;
                    newPhoto.Status = "Active";
                    newPhoto.ShowThumbnail = "N";
                    newPhoto.MachinePhotoID = iNextMachinePhotoID;

                    db.Photos.AddObject(newPhoto);
                    db.SaveChanges();

                    //Refresh thumbnail list
                    PhotosEntityDataSource.WhereParameters.Clear();
                    PhotosEntityDataSource.AutoGenerateWhereClause = true;
                    PhotosEntityDataSource.WhereParameters.Add("MachineID", TypeCode.Int32, iMachineID.ToString());

                    gridPhotos.Visible = true;
                }
            }
        }
        protected void btnUploadSpec_Click(object sender, EventArgs e)
        {
            if (uploadFile.HasFile == false)
            {
                UploadDetails.Text = "Please first select a file to upload...";
            }
            else
            {
                using (GESEntities db = new GESEntities())
                {
                    int iMachineID = Int32.Parse(lblMachineID.Text.Substring(lblMachineID.Text.IndexOf(":") + 1).Trim());

                    //Fetch next photo # in the photo table for this machine
                    int iNextSpecID = 0;

                    System.Nullable<Int32> GetNextSpec = (from p in db.Specifications where p.MachineID == iMachineID select (int?)p.MachineSpecID).Max();

                    if (GetNextSpec.HasValue)
                    {
                        iNextSpecID = GetNextSpec.Value + 1;
                    }
                    else
                    {
                        iNextSpecID = 1;
                    }

                    //Save the image
                    string fileName = iMachineID.ToString() + "-" + iNextSpecID.ToString() + Path.GetExtension(uploadFile.FileName);
                    string filePath = Server.MapPath("~/Specs/" + fileName);

                    string fileNameTemp = "Temp" + iMachineID.ToString() + "-" + iNextSpecID.ToString() + Path.GetExtension(uploadFile.FileName);
                    string filePathTemp = Server.MapPath("~/Specs/" + fileNameTemp);
                    uploadFile.SaveAs(filePathTemp);

                    //delete Temp file
                    if (File.Exists(filePathTemp))
                    {
                        File.Delete(filePathTemp);
                    }

                    // Display the uploaded file's details
                    UploadDetails.Text = string.Format(@"Uploaded file: {0}<br /> File size (in bytes): {1:N0}<br /> Content-type: {2}", uploadFile.FileName, uploadFile.FileBytes.Length, uploadFile.PostedFile.ContentType);

                    //insert a row into the photos table
                    Specification newSpec = new Specification();
                    newSpec.MachineID = iMachineID;
                    newSpec.SpecName = "Test";
                    newSpec.SpecDescription = "Test";
                    newSpec.SpecUrl = "Specs/" + fileName;
                    newSpec.Status = "Active";
                    newSpec.MachineSpecID = iNextSpecID;

                    db.Specifications.AddObject(newSpec);
                    db.SaveChanges();

                    //Refresh thumbnail list
                    SpecsEntityDataSource.WhereParameters.Clear();
                    SpecsEntityDataSource.AutoGenerateWhereClause = true;
                    SpecsEntityDataSource.WhereParameters.Add("MachineID", TypeCode.Int32, iMachineID.ToString());

                    gridSpecs.Visible = true;
                }
            }
        }
        protected void btnAddModel_Click(object sender, EventArgs e)
        {
            if (txtAddModel.Text == "")
            {
                lblAddModelError.Text = "Required";
            }
            else
            {
                //Check that all fields are populated
                if (listManufacturer.SelectedIndex < 0)
                {
                    lblAddModel.Text = "Choose a Manufacturer";
                    return;
                }

                if (listMachineType.SelectedIndex < 0)
                {
                    lblAddModel.Text = "Choose a Machine Type";
                    return;
                }

                using (GESEntities db = new GESEntities())
                {
                    try
                    {
                        Model newModel = new Model();
                        newModel.ManufacturerID = Int32.Parse(listManufacturer.SelectedItem.Value); ;
                        newModel.MachineTypeID = Int32.Parse(listMachineType.SelectedItem.Value); ;
                        newModel.ModelName = txtAddModel.Text.ToString();
                        newModel.ModelDescription = txtAddModel.Text.ToString();
                        newModel.Status = "Active";

                        db.Models.AddObject(newModel);
                        db.SaveChanges();

                        hfManufacturer.Value = listManufacturer.SelectedItem.Value;
                        hfMachineType.Value = listMachineType.SelectedItem.Value;
                        hfModel.Value = newModel.ModelID.ToString();

                        txtAddModel.Text = "";
                        lblAddModel.Text = "Added succesfully";

                        refreshModelEDS();

                        lblAddModelError.Text = "";
                    }
                    catch (Exception exp)
                    {
                        throw new Exception("ERROR: Unable to Add entry - " + exp.Message.ToString(), exp);
                    }
                }
            }
        }
        protected void btnAddManu_Click(object sender, EventArgs e)
        {
            if (txtAddManu.Text == "")
            {
                lblAddManuError.Text = "Required";
            }
            else
            {
                using (GESEntities db = new GESEntities())
                {
                    try
                    {
                        Manufacturer newManufacturer = new Manufacturer();
                        newManufacturer.ManufacturerName = txtAddManu.Text.ToString();
                        newManufacturer.ManufacturerDescription = txtAddManu.Text.ToString();
                        newManufacturer.Status = "Active";

                        db.Manufacturers.AddObject(newManufacturer);
                        db.SaveChanges();

                        txtAddManu.Text = "";
                        lblAddManu.Text = "Added succesfully";

                        ModelEntityDataSource.WhereParameters.Clear();
                        ModelEntityDataSource.AutoGenerateWhereClause = true;

                        refreshManufacturerEDS();

                        lblAddManuError.Text = "";
                    }
                    catch (Exception exp)
                    {
                        throw new Exception("ERROR: Unable to Add entry - " + exp.Message.ToString(), exp);
                    }
                }
            }
        }
        protected void btnAddMachine_Click(object sender, EventArgs e)
        {
            using (GESEntities db = new GESEntities())
            {
                try
                {
                    Machine newMachine = new Machine();
                    newMachine.ManufacturerID = Int32.Parse(listManufacturer.SelectedItem.Value);
                    newMachine.MachineTypeID = Int32.Parse(listMachineType.SelectedItem.Value);
                    newMachine.ModelID = Int32.Parse(listModel.SelectedItem.Value);
                    newMachine.IndustryID = Int32.Parse(listIndustry.SelectedItem.Value);
                    newMachine.MachineDescription = txtMachineDescription.Text.ToString();
                    newMachine.MachineGrade = txtMachineGrade.Text.ToString();
                    newMachine.SerialNo = txtSerial.Text.ToString();
                    newMachine.Year = txtYear.Text.ToString();
                    newMachine.Mileage = txtMileage.Text.ToString();
                    newMachine.Location = txtLocation.Text.ToString();
                    newMachine.ContactPerson = txtContactPerson.Text.ToString();
                    newMachine.EmailAddress = txtEmailAddress.Text.ToString();
                    newMachine.ContactNumber = txtContactNumber.Text.ToString();
                    newMachine.CostPrice = ConvertStringDecimal(txtCostPrice.Text.ToString());
                    newMachine.SellPrice = ConvertStringDecimal(txtSalesPrice.Text.ToString());
                    newMachine.Status = listStatus.SelectedItem.Value;
                    newMachine.DealerMachine = "N";
                    newMachine.DateInserted = DateTime.Now;

                    db.Machines.AddObject(newMachine);
                    db.SaveChanges();

                    lblMachineID.Text = newMachine.MachineID.ToString();
                    lblStatus.Text = ". Successully created machine row";

                    panelUpload.Visible = true;
                    //btnAddMachine.Visible = false;
                    //btnUpdateMachine.Visible = true;
                    //btnAddAnother.Visible = true;

                    Response.Redirect("AddUsedEquipment.aspx?mode=edit&machineID=" + newMachine.MachineID.ToString());

                }
                catch (Exception exp)
                {
                    throw new Exception("ERROR: Unable to Submit Enquiry - " + exp.Message.ToString(), exp);
                }
            }
            //            Response.Redirect("ProductDetails.aspx?ProductID=" + productID);
        }
Example #19
0
        protected String insertZOHOLead(string enquiryID, string description, string title)
        {
            string price = "";
            //Get machine Type and Model
            using (GESEntities db = new GESEntities())
            {
                try
                {
                    int machineID = 0;
                    try
                    {
                        Int32.TryParse(hfMachineID.Value, out machineID);
                    }
                    catch
                    {
                        machineID = 0;
                    }

                    if (machineID > 0)
                    {
                        var Machines = (from p in db.vUsedMachineLists where p.MachineID == machineID select p).FirstOrDefault();

                        title = title.ToLower();
                        title = title.Replace(" - used equipment page", "");
                        title = title + " | " + Machines.MachineTypeName + " | " + Machines.ManufacturerName + " | " + Machines.ModelName;

                        price = Machines.SellPrice.ToString();
                    }
                }
                catch (Exception exp)
                {
                    throw new Exception("ERROR: Unable to obtain machine detail - " + exp.Message.ToString(), exp);
                }
            }

            WebRequest request = null;
            WebResponse response = null;
            string zohoResponse = "";

            try
            {
                string ZOHOApiKey = WebConfigurationManager.AppSettings["ZOHOApiKey"];
                string ZOHOUsername = WebConfigurationManager.AppSettings["ZOHOUsername"];
                string ZOHOPassword = WebConfigurationManager.AppSettings["ZOHOPassword"];
                string ZOHOTicket = getZOHOTicket("ZohoCRM", ZOHOUsername, ZOHOPassword);

                string uri = string.Format("https://crm.zoho.com/crm/private/xml/Leads/insertRecords?newFormat=1&apikey={0}&ticket={1}", ZOHOApiKey, ZOHOTicket);
                string xml =    @"xmlData=<?xml version=""1.0"" encoding=""utf-8""?>" +
                                @"<Leads>" +
                                    @"<row no=""1"">" +
                                        @"<FL val=""Lead Owner"">Graham Reeves</FL>" +
                                        @"<FL val=""Company"">New Lead</FL>" +
                                        @"<FL val=""Title"">" + title + "</FL>" +
                                        @"<FL val=""First Name"">" + txtFirstName.Text.ToString() + "</FL>" +
                                        @"<FL val=""Last Name"">" + txtSurname.Text.ToString() + "</FL>" +
                                        @"<FL val=""Email"">"+txtEmail.Text.ToString()+"</FL>" +
                                        @"<FL val=""Mobile"">"+txtCellNo.Text.ToString()+"</FL>" +
                                        @"<FL val=""Lead Source"">GES Website</FL>" +
                                        @"<FL val=""Lead Status"">Not Contacted</FL>" +
                                        @"<FL val=""LeadSourceID"">" + enquiryID + "</FL>" +
                                        @"<FL val=""City"">"+txtTown.Text.ToString()+"</FL>" +
                                        @"<FL val=""Price Range"">" + price + "</FL>" +
                                        @"<FL val=""Description"">" + description + "</FL>" +
                                    @"</row>" +
                                @"</Leads>";

                UTF8Encoding utf8 = new UTF8Encoding(false); // false = do not output UTF8 byte order mark (BOM)
                byte[] bytes = utf8.GetBytes(xml);

                // create web request
                request = WebRequest.Create(uri);
                request.Method = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                request.ContentLength = bytes.LongLength;

                // write xml to request stream
                using (Stream writer = request.GetRequestStream())
                {
                    writer.Write(bytes, 0, (int)request.ContentLength);
                    writer.Flush();
                }

                // send xml and get response
                response = request.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream());
                zohoResponse = reader.ReadToEnd();

                // output results
                //Response.Write(string.Format("<h1>Zoho lead v{0}<h1><h2>Zoho request<h2><textarea>{1}</textarea><h2>Zoho response<h2><textarea>{2}</textarea>", version, xml, zohoResponse));
            }
            catch (WebException webEx)
            {
                throw webEx;
            }
            catch (Exception ex)
            {

            }
            finally
            {
                // close request and response stream
                //if (request != null) request.Close();
                //if (response != null) response.Close();
            }

            return zohoResponse;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!IsPostBack)
            //{
            //    listManufacturer.Items.Insert(0, new ListItem("--Please select a value--", "-1", true));
            //    listMachineType.Items.Insert(0, new ListItem("--Please select a value--"));
            //    listModel.Items.Insert(-1, new ListItem("--Please select a value--", "-1"));
            //    listIndustry.Items.Insert(-1, new ListItem("--Please select a value--", "-1"));
            //}
            //else
            //{
            //    listManufacturer.AppendDataBoundItems = false;
            //    listMachineType.AppendDataBoundItems = false;
            //    listModel.AppendDataBoundItems = false;
            //    listIndustry.AppendDataBoundItems = false;
            //}

            string mode = "";
            try
            {
                mode = Request["mode"].ToString();
            }
            catch
            {
                mode = "new";
            }

            if (mode == "edit")
            {
                using (GESEntities db = new GESEntities())
                {
                    try
                    {
                        if (lblMachineID.Text == "")
                        {
                            int MachineID = 0;
                            Int32.TryParse(Request["MachineID"].ToString(), out MachineID);

                            //show machine data
                            var getmachineRow = (from p in db.Machines where p.MachineID == MachineID select p).FirstOrDefault();

                            if (getmachineRow != null)
                            {
                                lblMachineID.Text = getmachineRow.MachineID.ToString();

                                hfManufacturer.Value = getmachineRow.ManufacturerID.Value.ToString();
                                hfMachineType.Value = getmachineRow.MachineTypeID.ToString();
                                hfModel.Value = getmachineRow.ModelID.ToString();
                                hfIndustry.Value = getmachineRow.IndustryID.Value.ToString();
                                txtMachineDescription.Text = getmachineRow.MachineDescription;
                                txtMachineGrade.Text = getmachineRow.MachineGrade;
                                txtSerial.Text = getmachineRow.SerialNo;
                                txtYear.Text = getmachineRow.Year;
                                txtMileage.Text = getmachineRow.Mileage;
                                txtLocation.Text = getmachineRow.Location;
                                txtContactPerson.Text = getmachineRow.ContactPerson;
                                txtEmailAddress.Text = getmachineRow.EmailAddress;
                                txtContactNumber.Text = getmachineRow.ContactNumber;
                                txtCostPrice.Text = getmachineRow.CostPrice.ToString();
                                txtSalesPrice.Text = getmachineRow.SellPrice.ToString();
                                hfStatus.Value = getmachineRow.Status.ToString();

                                //Show panels and refresh grid
                                panelUpload.Visible = true;
                                gridPhotos.Visible = true;

                                //Show panels and refresh grid
                                gridSpecs.Visible = true;

                                //Refresh Photos grid
                                PhotosEntityDataSource.WhereParameters.Clear();
                                PhotosEntityDataSource.AutoGenerateWhereClause = true;
                                PhotosEntityDataSource.WhereParameters.Add("MachineID", TypeCode.Int32, MachineID.ToString());
                            }

                            btnAddMachine.Visible = false;
                            btnUpdateMachine.Visible = true;
                            btnAddAnother.Visible = true;
                        }
                    }
                    catch (Exception exp)
                    {
                        throw new Exception("ERROR: Unable to Submit Enquiry - " + exp.Message.ToString(), exp);
                    }
                }
            }
            else
            {
                if (!IsPostBack)
                {
                    hfManufacturer.Value = "0";
                    hfMachineType.Value = "0";
                    hfModel.Value = "0";
                    hfStatus.Value = "0";

                    btnAddMachine.Visible = true;
                    btnUpdateMachine.Visible = false;
                    btnAddAnother.Visible = false;
                }
            }
        }
Example #21
0
        protected void btnEnquiry_Click(object sender, EventArgs e)
        {
            bool proceed = true;
            lblFirstName.Text = "";
            lblSurname.Text = "";
            lblEmailRequired.Text = "";
            lblCellNo.Text = "";

            //do normal checks
            if (txtFirstName.Text == "")
            {
                lblFirstName.Text = "Oops.... First Name please";
                proceed = false;
            }

            if (txtSurname.Text == "")
            {
                lblSurname.Text = "Oops.... Surname please";
                proceed = false;
            }

            if (txtEmail.Text == "")
            {
                lblEmailRequired.Text = "Oops.... Email Address please";
                proceed = false;
            }
            else
            {
                if (!Regex.IsMatch(txtEmail.Text, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"))
                {
                    lblEmailRequired.Text = "Oops.... Please provide the correct email format";
                    proceed = false;
                }
            }

            if (txtCellNo.Text == "")
            {
                lblCellNo.Text = "Oops.... Cell # please";
                proceed = false;
            }
            else
            {
                if (!Regex.IsMatch(txtCellNo.Text, @"^[0-9]+$"))
                {
                    lblCellNo.Text = "Oops.... Please provide a numeric only number i.e. no spaces, hyphens, brackets, etc";
                    proceed = false;
                }
            }

            if (proceed)
            {
                btnEnquiry.Attributes.Add("onclick", "javascript:" + btnEnquiry.ClientID + ".disabled=true;" + ClientScript.GetPostBackEventReference(btnEnquiry, ""));

                int machineID = Int32.Parse(hfMachineID.Value);
                int enquiryID = 0;

                string source = "";

                try
                {
                    source = Request["source"].ToString();
                }
                catch
                {
                    source = "Unknown";
                }

                string body = "";
                string subject = "";

                using (GESEntities db = new GESEntities())
                {
                    try
                    {
                        //Create a visitor user ID if not already logged in
                        //------------------------------------------------------------------------+
                        //  Add New User Record                                                   |
                        //------------------------------------------------------------------------+
                        User newUser = new User();
                        newUser.UserName = "******" + Guid.NewGuid().ToString();
                        newUser.Password = "******";
                        newUser.FirstName = txtFirstName.Text.ToString();
                        newUser.LastName = txtSurname.Text.ToString();
                        newUser.Email = txtEmail.Text.ToString();
                        newUser.CellNo = txtCellNo.Text.ToString();
                        newUser.AddrCity = txtTown.Text.ToString();
                        newUser.RoleID = 1; //Visitor
                        newUser.Comments = txtComments.Text.ToString();
                        db.Users.AddObject(newUser);
                        db.SaveChanges();

                        //------------------------------------------------------------------------+
                        //  Add New Enquiry Record                                                |
                        //------------------------------------------------------------------------+
                        Enquiry newEnquiry = new Enquiry();
                        newEnquiry.UserID = newUser.UserID;
                        newEnquiry.DateInserted = DateTime.Now;
                        newEnquiry.Comments = txtComments.Text.ToString();
                        newEnquiry.MachineID = machineID;
                        newEnquiry.Source = source;
                        db.Enquiries.AddObject(newEnquiry);
                        db.SaveChanges();

                        enquiryID = newEnquiry.EnquiryID;

                        if (source == "grease-gun-ad")
                        {
                            subject = "GES Enquiry # " + enquiryID.ToString() + " - Grease Gun Advert";
                        }
                        else if (source == "post-ad")
                        {
                            subject = "GES Enquiry # " + enquiryID.ToString() + " - Advertising Banners";
                        }
                        else if (source == "roller-320d-ad")
                        {
                            subject = "GES Enquiry # " + enquiryID.ToString() + " - 320D Roller for sale";
                        }
                        else if (source == "140h-rim-for-sale-ad")
                        {
                            subject = "GES Enquiry # " + enquiryID.ToString() + " - 140H Rim for sale";
                        }
                        else if (source == "used-equipment")
                        {
                            subject = "GES Enquiry # " + enquiryID.ToString() + " - Used Equipment page";
                        }
                        else if (source == "shantui-forklift-promo")
                        {
                            subject = "GES Enquiry # " + enquiryID.ToString() + " - Shantui Forklift Promotion page";
                        }
                        else if (source == "shantui-list-page")
                        {
                            subject = "GES Enquiry # " + enquiryID.ToString() + " - Shantui list page";
                        }
                        else if (source == "contact-us")
                        {
                            subject = "GES Enquiry # " + enquiryID.ToString() + " - Contact Us page";
                        }
                        else if (source == "equipment-to-sell")
                        {
                            subject = "GES Enquiry # " + enquiryID.ToString() + " - Equipment To Sell Banner";
                        }
                        else
                        {
                            subject = "GES Enquiry # " + enquiryID.ToString() + " - Page source unknown";
                        }
                    }
                    catch (Exception exp)
                    {
                        throw new Exception("ERROR: Unable to Submit Enquiry - " + exp.Message.ToString(), exp);
                    }
                }

                //------------------------------------------------------------------------+
                //  Send off the email notification                                       |
                //------------------------------------------------------------------------+

                //body = hfBody.Value;

                body = body +
                        "Lead Detail" + Environment.NewLine +
                        "-----------" + Environment.NewLine +
                        "Lead Source : " + source + Environment.NewLine +
                        "First Name : " + txtFirstName.Text.ToString() + Environment.NewLine +
                        "Surname : " + txtSurname.Text.ToString() + Environment.NewLine +
                        "Email : " + txtEmail.Text.ToString() + Environment.NewLine +
                        "Cell No : " + txtCellNo.Text.ToString() + Environment.NewLine +
                        "Town : " + txtTown.Text.ToString() + Environment.NewLine +
                        "Comments/Requirements : " + Environment.NewLine + Environment.NewLine + txtComments.Text.ToString();

                try
                {
                    string SMTPHost = WebConfigurationManager.AppSettings["SMTPHost"];
                    string SMTPUsername = WebConfigurationManager.AppSettings["SMTPUsername"];
                    string SMTPPassword = WebConfigurationManager.AppSettings["SMTPPassword"];

                    //string SMTPFrom = WebConfigurationManager.AppSettings["SMTPFrom"];
                    string SMTPFrom = txtEmail.Text.ToString();
                    string SMTPTo = WebConfigurationManager.AppSettings["SMTPTo"];
                    string SMTPCc = WebConfigurationManager.AppSettings["SMTPCc"];

            #if DEBUG
                    SMTPFrom = WebConfigurationManager.AppSettings["SMTPFromTest"];
                    SMTPTo = WebConfigurationManager.AppSettings["SMTPToTest"];
                    SMTPCc = WebConfigurationManager.AppSettings["SMTPCcTest"];
            #endif

                    //Send Mail
                    MailMessage mailObj = new MailMessage();
                    MailAddress from = new MailAddress(SMTPFrom, txtFirstName.Text.ToString() + " " + txtSurname.Text.ToString());
                    mailObj.From = from;
                    mailObj.Subject = subject + " | " + txtFirstName.Text.ToString() + " " + txtSurname.Text.ToString();
                    mailObj.Body = body.ToString();

                    //Get the To receipients
                    char[] separator = new char[] { ';' };

                    string[] strToSplit = SMTPTo.Split(separator);

                    foreach (string arrStr in strToSplit)
                    {
                        mailObj.To.Add(arrStr);
                    }

                    //Get the CC receipients
                    string[] strCCSplit = SMTPCc.Split(separator);

                    foreach (string arrStr in strCCSplit)
                    {
                        mailObj.CC.Add(arrStr);
                    }

                    SmtpClient SMTPServer = new SmtpClient();
                    SMTPServer.Host = SMTPHost;
                    SMTPServer.Credentials = new System.Net.NetworkCredential(SMTPUsername, SMTPPassword);
                    //SMTPServer.EnableSsl = true;
                    try
                    {
                        SMTPServer.Send(mailObj);

                        Response.Redirect("EnquiryConfirmation.aspx", false);
                    }
                    catch (Exception ex)
                    {
                        lblError.Text = ex.ToString();
                    }
                }
                catch (Exception exp)
                {
                    throw new Exception("ERROR: Unable to send mail - " + exp.Message.ToString(), exp);
                }

                //Send lead to ZOHO
                insertZOHOLead(enquiryID.ToString(), body, subject);
             }
        }
Example #22
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();
            Response.ContentType = "text/xml";
            using (XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("urlset");
                writer.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");

                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/default.aspx");
                writer.WriteElementString("changefreq", "weekly");
                writer.WriteElementString("priority", "0");
                writer.WriteEndElement();

                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/shantui");
                writer.WriteElementString("changefreq", "weekly");
                writer.WriteElementString("priority", "0.5");
                writer.WriteEndElement();

                //Get all Shantui products
                using (GESEntities db = new GESEntities())
                {
                    try
                    {
                        var tmpShantui = (from c in db.Shantuis where c.MainPicture == "Y" select c).OrderBy(x => x.MainPictureOrder);

                        foreach (DAL.Shantui tmpShantuiIndex in tmpShantui)
                        {
                            writer.WriteStartElement("url");
                            writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/Shantui-" + tmpShantuiIndex.Category.Replace(" ","-"));
                            writer.WriteElementString("changefreq", "weekly");
                            writer.WriteElementString("priority", "0.5");
                            writer.WriteEndElement();
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("ERROR: Unable to Submit Enquiry - " + ex.Message.ToString(), ex);
                    }
                    db.Dispose();
                }

                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/used-equipment");
                writer.WriteElementString("lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now));
                writer.WriteElementString("changefreq", "daily");
                writer.WriteElementString("priority", "0.5");
                writer.WriteEndElement();

                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/tlb-for-sale");
                writer.WriteElementString("lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now));
                writer.WriteElementString("changefreq", "daily");
                writer.WriteElementString("priority", "0.5");
                writer.WriteEndElement();

                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/excavator-for-sale");
                writer.WriteElementString("lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now));
                writer.WriteElementString("changefreq", "daily");
                writer.WriteElementString("priority", "0.5");
                writer.WriteEndElement();

                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/bulldozer-for-sale");
                writer.WriteElementString("lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now));
                writer.WriteElementString("changefreq", "daily");
                writer.WriteElementString("priority", "0.5");
                writer.WriteEndElement();

                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/water-trucks-for-sale");
                writer.WriteElementString("lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now));
                writer.WriteElementString("changefreq", "daily");
                writer.WriteElementString("priority", "0.5");
                writer.WriteEndElement();

                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/compactors-for-sale");
                writer.WriteElementString("lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now));
                writer.WriteElementString("changefreq", "daily");
                writer.WriteElementString("priority", "0.5");
                writer.WriteEndElement();

                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/motor-grader-for-sale");
                writer.WriteElementString("lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now));
                writer.WriteElementString("changefreq", "daily");
                writer.WriteElementString("priority", "0.5");
                writer.WriteEndElement();

                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/dump-truck-for-sale");
                writer.WriteElementString("lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now));
                writer.WriteElementString("changefreq", "daily");
                writer.WriteElementString("priority", "0.5");
                writer.WriteEndElement();

                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/flatbed-truck-for-sale");
                writer.WriteElementString("lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now));
                writer.WriteElementString("changefreq", "daily");
                writer.WriteElementString("priority", "0.5");
                writer.WriteEndElement();

                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/tipper-truck-for-sale");
                writer.WriteElementString("lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now));
                writer.WriteElementString("changefreq", "daily");
                writer.WriteElementString("priority", "0.5");
                writer.WriteEndElement();

                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/wheel-loader-for-sale");
                writer.WriteElementString("lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now));
                writer.WriteElementString("changefreq", "daily");
                writer.WriteElementString("priority", "0.5");
                writer.WriteEndElement();

                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/front-end-loader-for-sale");
                writer.WriteElementString("lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now));
                writer.WriteElementString("changefreq", "daily");
                writer.WriteElementString("priority", "0.5");
                writer.WriteEndElement();

                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/road-roller-for-sale");
                writer.WriteElementString("lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now));
                writer.WriteElementString("changefreq", "daily");
                writer.WriteElementString("priority", "0.5");
                writer.WriteEndElement();

                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/bowser-for-sale");
                writer.WriteElementString("lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now));
                writer.WriteElementString("changefreq", "daily");
                writer.WriteElementString("priority", "0.5");
                writer.WriteEndElement();

                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/tow-tractor-for-sale");
                writer.WriteElementString("lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now));
                writer.WriteElementString("changefreq", "daily");
                writer.WriteElementString("priority", "0.5");
                writer.WriteEndElement();

                //loop thru all used equipment list
                using (GESEntities db = new GESEntities())
                {
                    try
                    {
                        //Get all Used Equipment products
                        var tmpUsed = (from c in db.Machines select c).OrderBy(x => x.MachineID);

                        foreach (DAL.Machine tmpUsedIndex in tmpUsed)
                        {
                            writer.WriteStartElement("url");
                            writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/UsedEquipmentDetail.aspx?MachineID=" + tmpUsedIndex.MachineID);
                            writer.WriteElementString("lastmod", String.Format("{0:yyyy-MM-dd}", tmpUsedIndex.DateInserted));
                            writer.WriteElementString("changefreq", "daily");
                            writer.WriteElementString("priority", "0.5");
                            writer.WriteEndElement();
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("ERROR: Unable to Submit Enquiry - " + ex.Message.ToString(), ex);
                    }
                    db.Dispose();
                }

                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/MyQuip.aspx");
                writer.WriteElementString("changefreq", "monthly");
                writer.WriteElementString("priority", "0.2");
                writer.WriteEndElement();

                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/ContactUs.aspx");
                writer.WriteElementString("changefreq", "monthly");
                writer.WriteElementString("priority", "0.2");
                writer.WriteEndElement();

                //writer.WriteStartElement("url");
                //writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/Enquire.aspx");
                //writer.WriteElementString("changefreq", "monthly");
                //writer.WriteElementString("priority", "0.2");
                //writer.WriteEndElement();

                //writer.WriteStartElement("url");
                //writer.WriteElementString("loc", "http://www.globalearthmoving.co.za/Account/Login.aspx");
                //writer.WriteElementString("changefreq", "monthly");
                //writer.WriteElementString("priority", "0.2");
                //writer.WriteEndElement();

                writer.WriteEndDocument();
                writer.Flush();
            }
            Response.End();
        }
Example #23
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            lblError.Text = "";
            string userName = "";
            string password = "";

            if (txtUserName.Text.ToString().ToUpper() == "ADMIN")
            {
                userName = "******";
                password = "******";
            }
            //else if (txtUserName.Text.ToString().ToUpper() == "DEMO")
            //{
            //    userName = "******";
            //    password = "******";
            //}
            else
            {
                using (GESEntities db = new GESEntities())
                {
                    try
                    {
                        string tmpUserName = txtUserName.Text.ToString().ToUpper();

                        var editUser = (from c in db.Users where c.UserName.ToUpper() == tmpUserName select c).FirstOrDefault();

                        if (editUser != null)
                        {
                            userName = editUser.UserName;
                            password = editUser.Password;
                        }
                    }
                    catch (Exception exp)
                    {
                        throw new Exception("ERROR: Unable to read from User table - " + exp.Message.ToString(), exp);
                    }
                }
            }

            bool userNameValid = string.Compare(txtUserName.Text.ToString().ToUpper(), userName, true) == 0;
            bool passwordValid = string.Compare(txtPassword.Text.ToString(), password, false) == 0;

            if (userNameValid && passwordValid)
            {
                //Update User table
                if (txtUserName.Text.ToString().ToUpper() != "ADMIN")
                {
                    using (GESEntities db = new GESEntities())
                    {
                        try
                        {
                            var editUser = (from c in db.Users where c.Email == userName select c).FirstOrDefault();
                            if (editUser != null)
                            {
                                editUser.LatestLoggedInDate = DateTime.Now;
                                editUser.NumberOfLogins = editUser.NumberOfLogins + 1;

                                db.SaveChanges();
                            }
                        }
                        catch (Exception exp)
                        {
                            throw new Exception("ERROR: Unable to update user Table - " + exp.Message.ToString(), exp);
                        }
                    }
                }

                FormsAuthentication.RedirectFromLoginPage(userName, false);
            }
            else
            {
                lblError.Text = "Email / Password combination incorrect";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                refreshManufacturerEDS();

                string userName = "";
                System.Security.Principal.IPrincipal User = HttpContext.Current.User;
                userName = User.Identity.Name.ToUpper();

                if (userName == "ADMIN")
                {
                    AdminSection.Visible = true;
                }
                else
                {
                    AdminSection.Visible = false;
                }

                if (Request["mode"].ToString() == "edit")
                {
                    using (GESEntities db = new GESEntities())
                    {
                        try
                        {
                            int machineID = 0;
                            try
                            {
                                Int32.TryParse(Request["machineID"].ToString(), out machineID);
                            }
                            catch
                            {
                                machineID = 0;
                            }

                            //show machine data
                            var getmachineRow = (from p in db.Machines where p.MachineID == machineID select p).FirstOrDefault();

                            if (getmachineRow != null)
                            {
                                lbManufacturer.SelectedValue = getmachineRow.ManufacturerID.Value.ToString();
                                tbModel.Text = getmachineRow.ModelName.ToString();
                                txtMachineDescription.Text = getmachineRow.MachineDescription;
                                txtMachineGrade.Text = getmachineRow.MachineGrade;
                                txtSerial.Text = getmachineRow.SerialNo;
                                txtYear.Text = getmachineRow.Year;
                                txtMileage.Text = getmachineRow.Mileage;
                                txtLocation.Text = getmachineRow.Location;
                                txtContactPerson.Text = getmachineRow.ContactPerson;
                                txtEmailAddress.Text = getmachineRow.EmailAddress;
                                txtContactNumber.Text = getmachineRow.ContactNumber;
                                txtCostPrice.Text = getmachineRow.CostPrice.ToString();
                                txtSalesPrice.Text = getmachineRow.SellPrice.ToString();
                                listStatus.SelectedValue = getmachineRow.Status.ToString();
                            }

                        }
                        catch (Exception exp)
                        {
                            if (exp.Message == "")
                            {
                                throw new Exception("ERROR: Unable to Submit Enquiry - " + exp.InnerException.ToString(), exp);
                            }
                            else
                            {
                                throw new Exception("ERROR: Unable to Submit Enquiry - " + exp.Message.ToString(), exp);
                            }
                        }
                    }
                }
            }
        }