private void LoadData()
        {
            if (Obj != null)
            {
                LoadImageAttach();

                Obj.content     = Obj.content.Replace("<br/>", "\n");
                Obj.description = Obj.description.Replace("<br/>", "\n");

                rtb_description.Text = Obj.description;
                rtb_content.Text     = Obj.content;
                tb_name.Text         = Obj.name;
                tb_title.Text        = Obj.title;
                FeatureImage         = new ImageAttachModel()
                {
                    IsLocal = false,
                    Link    = Obj.featureimage
                };
                pic_feature.Load(AppConfig.WebUrl + "/" + Common.AppConfig.PathImageCollections + "/" + Obj.id + "/" + Obj.featureimage);

                for (int i = 0; i < chlb_catogary.Items.Count; i++)
                {
                    if ((chlb_catogary.Items[i] as Web_Menu_Model).id == Obj.relatedmenu)
                    {
                        chlb_catogary.SetItemChecked(i, true);
                    }
                }
            }
        }
        public void AddImage(ImageAttachModel imgM)
        {
            ImageAttachModelView view = new ImageAttachModelView();

            view.ImageAttach           = imgM;
            view.OnImageAttachChoosed += View_OnImageAttachChoosed;
            view.IsEnable              = IsEnable;
            pn_image.Controls.Add(view);
            OnAddorRemoveImage();
        }
 private void Btn_DeleteFrontImage_Click(object sender, EventArgs e)
 {
     if (pn_Image != null)
     {
         pn_Image.deleteFrontDesign();
         FrontDesign = new ImageAttachModel()
         {
             IsLocal = true,
             Link    = string.Empty
         };
     }
 }
 private void btn_browser_Click(object sender, EventArgs e)
 {
     using (OpenFileDialog ofd = new OpenFileDialog())
     {
         ofd.Multiselect = false;
         ofd.Filter      = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png";
         if (ofd.ShowDialog() == DialogResult.OK)
         {
             FeatureImage = new ImageAttachModel()
             {
                 IsLocal = true,
                 Link    = ofd.FileName
             };
             pic_feature.Image = Image.FromFile(ofd.FileName);
         }
     }
 }
 private void Btn_BrownFrontImage_Click(object sender, EventArgs e)
 {
     using (OpenFileDialog ofd = new OpenFileDialog())
     {
         ofd.Filter = "PNG files (*.png)|*.png";
         ofd.Title  = "Vui lòng chọn file";
         if (ofd.ShowDialog() == DialogResult.OK)
         {
             FrontDesign = new ImageAttachModel()
             {
                 IsLocal = true,
                 bm      = null,
                 Link    = ofd.FileName
             };
             if (pn_Image != null)
             {
                 pn_Image.setFrontDesign(FrontDesign.Link);
             }
         }
     }
 }
        private void LoadImageAttach()
        {
            List <string> lstImage = FTPAction.getListFiles(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword, FTPAction.localSourceWeb + "/" + Common.AppConfig.PathImageCollections + "/" + Obj.id, string.Empty);

            foreach (var item in lstImage)
            {
                if (item == Obj.featureimage)
                {
                    continue;
                }
                var ImageItem = new ImageAttachModel()
                {
                    IsLocal = false,
                    Link    = AppConfig.WebUrl + "/" + Common.AppConfig.PathImageCollections + "/" + Obj.id + "/" + item
                };
                pn_imageattach.AddImage(ImageItem);
                if (action != Resources.EnumClass.CollectionsAction.Detail)
                {
                    Obj.content = Obj.content.Replace(ImageItem.Link, "[~" + ImageItem.id.ToString() + "]");
                }
            }
        }
        public void InitData()
        {
            // Load Style
            clb_style.Items.Clear();
            clb_style.Items.AddRange(controller.getStyleList().ToArray());

            //Load Color
            lstColor = controller.getColorList();

            tb_TenSP.Text         = product.product_name;
            tb_LinkSP_direct.Text = product.product_link;
            tb_title.Text         = product.product_title;
            rtb_content.Text      = product.product_content.Replace("<br/>", "\n");

            //Fill Image design
            if (!product.product_image_design.Split(',')[0].Equals("None"))
            {
                byte[] data = null;
                if (FTPAction.getFile(AppConfig.FTPHost,
                                      AppConfig.FTPUser,
                                      AppConfig.FTPPassword,
                                      FTPAction.localPathDesign,
                                      product.product_image_design.Split(',')[0],
                                      ref data))
                {
                    Image i;
                    if ((i = Functions.getImage(data)) != null)
                    {
                        FrontDesign = new ImageAttachModel()
                        {
                            IsLocal = false,
                            bm      = (Bitmap)i,
                            Link    = string.Empty
                        };
                    }
                    else
                    {
                        FrontDesign = new ImageAttachModel()
                        {
                            IsLocal = true,
                            Link    = string.Empty
                        };
                    }
                }
                else
                {
                    FrontDesign = new ImageAttachModel()
                    {
                        IsLocal = true,
                        Link    = string.Empty
                    };
                }
            }
            else
            {
                FrontDesign = new ImageAttachModel()
                {
                    IsLocal = true,
                    Link    = string.Empty
                };
            }
            if (!product.product_image_design.Split(',')[1].Equals("None"))
            {
                byte[] data = null;
                if (FTPAction.getFile(AppConfig.FTPHost,
                                      AppConfig.FTPUser,
                                      AppConfig.FTPPassword,
                                      FTPAction.localPathDesign,
                                      product.product_image_design.Split(',')[0],
                                      ref data))
                {
                    Image i;
                    if ((i = Functions.getImage(data)) != null)
                    {
                        BehideDesign = new ImageAttachModel()
                        {
                            IsLocal = false,
                            bm      = (Bitmap)i,
                            Link    = string.Empty
                        };
                    }
                    else
                    {
                        BehideDesign = new ImageAttachModel()
                        {
                            IsLocal = true,
                            Link    = string.Empty
                        };
                    }
                }
                else
                {
                    BehideDesign = new ImageAttachModel()
                    {
                        IsLocal = true,
                        Link    = string.Empty
                    };
                }
            }
            else
            {
                BehideDesign = new ImageAttachModel()
                {
                    IsLocal = true,
                    Link    = string.Empty
                };
            }

            // Fill style and color
            var serializer = new JavaScriptSerializer();

            serializer.RegisterConverters(new[] { new DynamicJsonConverter() });

            string json = "{" + product.style_design.Substring(19, product.style_design.Length - 21).Replace(", }", "}") + "}";
            var    obj  = serializer.Deserialize <Dictionary <string, object> >(json);

            foreach (var kv in obj)
            {
                int style = Int32.Parse(kv.Key.Substring(1));
                for (int i = 0; i < clb_style.Items.Count; i++)
                {
                    if ((clb_style.Items[i] as Product_Style_Model).Id == style)
                    {
                        clb_style.SetItemChecked(i, true);
                        break;
                    }
                }

                foreach (var item in kv.Value as Dictionary <string, object> )
                {
                    if (item.Key.Equals("cl"))
                    {
                        pn_Image.setChoosenColorListbyId(Functions.GetList(item.Value.ToString(), ','), style);
                    }
                    if (item.Key.Equals("t"))
                    {
                        pn_Image.setLocationandSizeFrontDesignbyId(new Point(Int32.Parse(item.Value.ToString().Split('@')[0].Split('!')[0]),
                                                                             Int32.Parse(item.Value.ToString().Split('@')[0].Split('!')[1])),
                                                                   new Size(Int32.Parse(item.Value.ToString().Split('@')[1].Split('!')[0]),
                                                                            Int32.Parse(item.Value.ToString().Split('@')[1].Split('!')[1])),
                                                                   style);
                    }
                    if (item.Key.Equals("s"))
                    {
                        pn_Image.setLocationandSizeBehindDesignbyId(new Point(Int32.Parse(item.Value.ToString().Split('@')[0].Split('!')[0]),
                                                                              Int32.Parse(item.Value.ToString().Split('@')[0].Split('!')[1])),
                                                                    new Size(Int32.Parse(item.Value.ToString().Split('@')[1].Split('!')[0]),
                                                                             Int32.Parse(item.Value.ToString().Split('@')[1].Split('!')[1])),
                                                                    style);
                    }
                }
            }
        }
 private void Pn_imageattach_OnImageAttachDeleted(ImageAttachModel view)
 {
     rtb_content.Text = rtb_content.Text.Replace("[~" + view.id.ToString() + "]", string.Empty);
 }