Beispiel #1
0
 public OtherContentDetailPage()
 {
     this._constantCollection  = new ConstantCollection();
     this._otherContentRT      = new OtherContentRT();
     this._pictureRT           = new PictureRT();
     this._visitorIPMACAddress = new VisitorIPMACAddress();
 }
 public DetailPage()
 {
     this._constantCollection  = new ConstantCollection();
     this._customClientRT      = new CustomClientRT();
     this._pictureRT           = new PictureRT();
     this._visitorIPMACAddress = new VisitorIPMACAddress();
 }
Beispiel #3
0
        protected void btnDeleteSelectedImage_Click(object sender, EventArgs e)
        {
            try
            {
                if (Session["seMatPicTempFileName"] != null)
                {
                    List <string> urlList = new List <string>();
                    foreach (DataListItem item in datalistMatPic.Items)
                    {
                        if ((item.FindControl("chkImg") as CheckBox).Checked)
                        {
                            Image img = (Image)item.FindControl("imgMatTempImage");
                            urlList.Add(img.ImageUrl);
                        }
                    }
                    List <ControlAdmin.MaterialWF.ImageUrl> temp = (List <ControlAdmin.MaterialWF.ImageUrl>)Session["seMatPicTempFileName"];
                    foreach (var url in urlList)
                    {
                        if (url != "App_Themes/Default/images/interface/no-picture.png")
                        {
                            File.Delete(Server.MapPath(url));
                        }
                        if (!url.StartsWith("~/Image/MatTempImage"))
                        {
                            using (PictureRT aPictureRt = new PictureRT())
                            {
                                aPictureRt.DeletePictureByUrl(url);
                            }
                        }

                        temp.Remove(temp.FirstOrDefault(x => x.ImageUrlTemp == url));
                    }

                    Session["seMatPicTempFileName"] = temp;
                    datalistMatPic.DataSource       = temp;
                    datalistMatPic.DataBind();
                    if (temp.Count == 0)
                    {
                        Session["seMatPicTempFileName"] = null;
                        btnDeleteImageTemp.Visible      = false;
                    }
                }
                labelMessage.Text = string.Empty;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
Beispiel #4
0
        private void FillMaterialFormForEdit(Int64 materialIID)
        {
            try
            {
                using (MaterialRT rt = new MaterialRT())
                {
                    hdMaterialID.Value = materialIID.ToString();

                    Material material = rt.GetMaterialByIID(materialIID);

                    if (material == null)
                    {
                        Response.Redirect("~/ManageYourAds.aspx");
                    }

                    if (!(material.BrandID == 0 || material.BrandID == null))
                    {
                        txtBrandID.Text = material.BrandID.ToString();
                        using (BrandRT brandRt = new BrandRT())
                        {
                            txtBrand.Text = brandRt.GetBrandByID((long)material.BrandID).Name;
                        }
                    }

                    if (!(material.ModelID != 0 || material.ModelID != null))
                    {
                        using (ModelRT aModelRt = new ModelRT())
                        {
                            txtModel.Text = aModelRt.GetModelByID((int)material.ModelID).Name;
                        }
                    }

                    if (!(material.ColorID != 0 || material.ColorID != null))
                    {
                        using (ColorRT aColorRt = new ColorRT())
                        {
                            txtModel.Text = aColorRt.GetColorByID((int)material.ColorID).Name;
                        }
                    }

                    using (AdGiverRT adGiverRt = new AdGiverRT())
                    {
                        txtUserID.Text = material.AdGiverID != 0 ? adGiverRt.GetAdGiverByIID((long)material.AdGiverID).EmailID : string.Empty;
                    }
                    txtTitleName.Text = material.TitleName;
                    txtPrice.Text     = material.Price.ToString();

                    txtDescription.Text   = material.Description;
                    txtCode.Text          = material.Code;
                    txtWeburl.Text        = material.WebSiteUrl;
                    txtYoutubeUrl.Text    = material.YoutubeUrl;
                    txtPhoneNumber.Text   = material.UserPhoneNumber;
                    chkNegotiable.Checked = material.IsNegotiablePrice;

                    dropDownCategory.SelectedValue = material.CategoryID.ToString();



                    using (LocationRT aLocationRt = new LocationRT())
                    {
                        txtLocationID.Text = material.LocationID.ToString();

                        long   districtID = 0, policeStationID = 0;
                        string districtName = string.Empty, polStationName = string.Empty, locationName = string.Empty;
                        bool   isReceiveInfo = aLocationRt.GetLocationInfoByIID(material.LocationID, ref districtID, ref districtName, ref policeStationID, ref polStationName, ref locationName);
                        if (isReceiveInfo)
                        {
                            txtDistrictID.Text      = districtID.ToString();
                            txtDistrict.Text        = districtName.ToString();
                            txtPoliceStationID.Text = policeStationID.ToString();
                            txtPoliceStation.Text   = polStationName.ToString();
                            txtLocation.Text        = locationName.ToString();
                        }
                    }

                    DateTime addDate            = material.AdDate;
                    DateTime adDisplayLastDate  = (DateTime)(material.AdDisplayLastDate ?? material.AdDate);
                    int      adDisplayTotalDate = (int)(adDisplayLastDate - addDate).TotalDays;
                    txtPostVisibilityDay.Text = adDisplayTotalDate.ToString();


                    List <ControlAdmin.MaterialWF.ImageUrl> matPicTempFileUrlList = new List <ControlAdmin.MaterialWF.ImageUrl>();
                    using (PictureRT aPictureRt = new PictureRT())
                    {
                        List <Picture> picList = new List <Picture>();
                        picList = aPictureRt.GetPictureByMaterialIID(Convert.ToInt64(materialIID));

                        if (picList.Count > 0)
                        {
                            foreach (var picture in picList)
                            {
                                ControlAdmin.MaterialWF.ImageUrl aImageUrl = new ControlAdmin.MaterialWF.ImageUrl();
                                aImageUrl.ImageUrlTemp = picture.UrlAddress;
                                matPicTempFileUrlList.Add(aImageUrl);
                            }
                        }
                    }
                    Session["seMatPicTempFileName"] = matPicTempFileUrlList;
                    datalistMatPic.DataSource       = matPicTempFileUrlList;
                    datalistMatPic.DataBind();

                    Session[sessMaterial] = material;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
Beispiel #5
0
        protected void btnMatPicUpload_Click(object sender, EventArgs e)
        {
            try
            {
                if (Session["seMatPicTempFileName"] == null)
                {
                    Session["seMatPicTempFileName"] = new List <ControlAdmin.MaterialWF.ImageUrl>();
                }

                List <ControlAdmin.MaterialWF.ImageUrl> matPicTempFileUrlList = new List <ControlAdmin.MaterialWF.ImageUrl>();
                using (PictureRT aPictureRt = new PictureRT())
                {
                    List <Picture> picList = new List <Picture>();
                    picList = aPictureRt.GetPictureByMaterialIID(Convert.ToInt64(Session["adGiverMatIID"]));

                    if (picList.Count > 0)
                    {
                        foreach (var picture in picList)
                        {
                            ControlAdmin.MaterialWF.ImageUrl aImageUrl = new ControlAdmin.MaterialWF.ImageUrl();
                            aImageUrl.ImageUrlTemp = picture.UrlAddress;
                            matPicTempFileUrlList.Add(aImageUrl);
                        }
                    }
                }


                if (MatPicUpload.HasFile)
                {
                    foreach (var file in MatPicUpload.PostedFiles)
                    {
                        string now = "";
                        now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff", CultureInfo.InvariantCulture);

                        //take only letter or digit
                        var sb = new StringBuilder();
                        foreach (char t in now.Where(char.IsLetterOrDigit))
                        {
                            sb.Append(t);
                        }

                        now = sb.ToString();//save to now string
                        var rnd = new Random(100000);
                        var tempMatImageName = now + rnd.Next();

                        matPicTempFileUrlList = (List <ControlAdmin.MaterialWF.ImageUrl>)Session["seMatPicTempFileName"];//read from sess

                        string path = Server.MapPath("~/Image/MatTempImage/");
                        FileUploadHelper.BindImage(file, path, tempMatImageName);


                        ControlAdmin.MaterialWF.ImageUrl imageUrl = new ControlAdmin.MaterialWF.ImageUrl();
                        imageUrl.ImageUrlTemp = "~/Image/MatTempImage/" + tempMatImageName + Path.GetExtension(file.FileName);
                        matPicTempFileUrlList.Add(imageUrl);
                        Session["seMatPicTempFileName"] = matPicTempFileUrlList;//write to sess


                        labelMessage.Text = "File uploaded!";
                    }
                    datalistMatPic.DataSource = matPicTempFileUrlList;
                    datalistMatPic.DataBind();
                    btnDeleteImageTemp.Visible = true;
                }
                else
                {
                    labelMessage.Text      = "Please browse image(s)....";
                    labelMessage.ForeColor = System.Drawing.Color.Yellow;
                    labelMessage.Focus();
                }
            }
            catch (Exception ex)
            {
                labelMessage.Text = "error: " + ex.Message;
            }
        }
Beispiel #6
0
        protected void btnUpdatePost_Click(object sender, EventArgs e)
        {
            try
            {
                hdIsEdit.Value = "true";
                int    imgCount   = 0;
                int    materialID = 0;
                string matCode    = string.Empty;
                if (!TextControlCheckBeforeSave())
                {
                    return;
                }
                Material material = CreateMaterial();
                if (material == null)
                {
                    return;
                }
                List <ControlAdmin.MaterialWF.ImageUrl> matPicUrlList = new List <ControlAdmin.MaterialWF.ImageUrl>();

                btnMatPicUpload_Click(sender, e);

                var matPicListForTempUrl = (List <ControlAdmin.MaterialWF.ImageUrl>)Session["seMatPicTempFileName"];
                matPicUrlList = matPicListForTempUrl.Where(url => url.ImageUrlTemp.StartsWith("~/Image/MatTempImage")).ToList();//Set for temp img update
                List <Picture> pictureColl = new List <Picture>();
                matCode = material.Code;

                if (matPicUrlList.Count == 0)
                {
                    Picture aPicture = new Picture();
                    aPicture.MaterialID = material.IID;
                    string permanentImagePath = new ConstantCollection().noImageUrl;
                    aPicture.UrlAddress = permanentImagePath;
                    pictureColl.Add(aPicture);
                }
                else if (matPicUrlList.Count > 0)
                {
                    int tempImgCount = 0;
                    using (PictureRT aPictureRt = new PictureRT())
                    {
                        try
                        {
                            var imgList = aPictureRt.GetAllPicturesAccordingToMaterialID(material.IID).ToList();
                            if (imgList.Count > 0)
                            {
                                var picCount =
                                    (Path.GetFileNameWithoutExtension(
                                         Server.MapPath(
                                             aPictureRt.GetAllPicturesAccordingToMaterialID(material.IID)
                                             .OrderByDescending(pic => pic.UrlAddress)
                                             .FirstOrDefault()
                                             .UrlAddress)).Substring(13));

                                imgCount     = Convert.ToInt32(picCount) + 1;
                                tempImgCount = imgCount;
                            }
                            else
                            {
                                imgCount = 1;//set image number if no image found
                            }
                        }
                        catch (Exception exception)
                        {
                            throw new Exception(exception.Message, exception);
                        }
                    }

                    foreach (var imageUrl in matPicUrlList)
                    {
                        Picture aPicture = new Picture();
                        aPicture.MaterialID = material.IID;
                        // string permanentImagePathToSave = Server.MapPath("~/Image/MatImage/") + matCode + "_" + count + (Path.GetExtension(imageUrl.ImageUrlTemp));//image path to save folder
                        string permanentImagePath = "~/Image/MatImage/" + matCode + "_" + imgCount + (Path.GetExtension(Server.MapPath(imageUrl.ImageUrlTemp)));//image path to save db
                        aPicture.UrlAddress = permanentImagePath;
                        // File.Move(Server.MapPath(imageUrl.ImageUrlTemp), permanentImagePathToSave);//move pic to permanent folder from tempPic folder
                        pictureColl.Add(aPicture);
                        imgCount++;
                    }
                    imgCount = tempImgCount;
                }

                if (material.AdGiverID != -1)
                {
                    using (MaterialRT aMaterialRt = new MaterialRT())
                    {
                        aMaterialRt.UpdateMaterial(material);
                    }


                    if (matPicUrlList.Count > 0)
                    {
                        using (PictureRT aPictureRt = new PictureRT())
                        {
                            foreach (var pic in pictureColl)
                            {
                                aPictureRt.AddMaterialPicture(pic);
                            }
                        }


                        foreach (var imageUrl in matPicUrlList)
                        {
                            Picture aPicture = new Picture();
                            aPicture.MaterialID = material.IID;
                            string permanentImagePathToSave = Server.MapPath("~/Image/MatImage/") + matCode + "_" + imgCount + (Path.GetExtension(imageUrl.ImageUrlTemp)); //image path to save folder
                            string permanentImagePath       = "~/Image/MatImage/" + matCode + "_" + imgCount + (Path.GetExtension(Server.MapPath(imageUrl.ImageUrlTemp))); //image path to save db
                            aPicture.UrlAddress = permanentImagePath;
                            File.Move(Server.MapPath(imageUrl.ImageUrlTemp), permanentImagePathToSave);                                                                    //move pic to permanent folder from tempPic folder
                            imgCount++;
                        }
                    }
                    Session["seMatPicTempFileName"] = null;
                    Response.Redirect("~/ManageYourAds.aspx");
                    //labelMessage.Text = "Your post is successfully added, Your Post Code is " + matCode + " ..!!";
                    //labelMessage.ForeColor = System.Drawing.Color.Green;
                    //labelMessage.Focus();
                    ClearField();
                }
                else
                {
                    labelMessage.Text = String.Format("Please register frist. You can register here. <a href=\"{0}\">{1}</a>",
                                                      HttpUtility.HtmlEncode("UserRegistrationPage.aspx"), HttpUtility.HtmlEncode("Register now"));

                    labelMessage.ForeColor = System.Drawing.Color.Red;
                    labelMessage.Focus();
                }
            }
            catch (Exception ex)
            {
                labelMessage.Text      = "Error : " + ex.Message;
                labelMessage.ForeColor = System.Drawing.Color.Red;
                labelMessage.Focus();
            }
        }