示例#1
0
        private void Update()
        {
            List <string> lstFile = null;

            lstFile = FTPAction.getListFiles(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword, AppConfig.releaseLocation, string.Empty);
            if (lstFile != null)
            {
                if (lstFile.Count > 0)
                {
                    //Backup các file cũ
                    if (!Directory.Exists(Application.StartupPath + "/tmp"))
                    {
                        Directory.CreateDirectory(Application.StartupPath + "/tmp");
                    }
                    int index = 0;
                    foreach (var item in lstFile)
                    {
                        SetStatustoLable(lb_process, "Backup file: " + item);
                        SetProcessBar(progress_update, 60 * ((index * 2) / (lstFile.Count * 2)));
                        //Backup các file cũ
                        try
                        {
                            File.Copy(Application.StartupPath + "/" + item, Application.StartupPath + "/tmp/" + item);
                            File.Delete(Application.StartupPath + "/" + item);
                        }
                        catch { }

                        SetStatustoLable(lb_process, "Get file: " + item);
                        SetProcessBar(progress_update, 60 * ((index * 2 + 1) / (lstFile.Count * 2)));
                        //Get các file mới
                        if (!FTPAction.getFile(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword, AppConfig.releaseLocation, item, Application.StartupPath, item))
                        {
                            SetStatustoLable(lb_process, "Rollback previous Version");
                            SetProcessBar(progress_update, 0);
                            //Rollback phiên bản cũ
                            Rollback();
                            SetStatustoLable(lb_process, "UpdateFail");
                            SetProcessBar(progress_update, 0);
                            throw new Exception("Lỗi trong quá trình lấy file");
                        }
                        index++;
                    }
                    SetStatustoLable(lb_process, "Delete tmp file");
                    SetProcessBar(progress_update, 60);
                    DeleteTmp();

                    SetStatustoLable(lb_process, "UpdateSucess");
                    SetProcessBar(progress_update, 100);
                }
                else
                {
                    throw new Exception("Không có file nào để update");
                }
            }
            else
            {
                throw new Exception("Không thể kết nối đến server FTP");
            }
        }
        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 InitData()
        {
            pn_color.BackColor       = product_color.Colors;
            pn_style.BackgroundImage = Image.FromFile(Application.StartupPath + "/ImageModel/s" + order.style_id + ".png");
            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)
                    {
                        pic_design.Image = i;
                        string style_desgn = Functions.getValueinJoin(product.style_design, "t");
                        if (style_desgn.Equals(string.Empty))
                        {
                            pic_design.Visible = false;
                        }
                        else
                        {
                            pic_design.Location = new Point(Int32.Parse(style_desgn.Split('@')[0].Split('!')[0]) / 2,
                                                            Int32.Parse(style_desgn.Split('@')[0].Split('!')[1]) / 2);
                            pic_design.Size = new Size(Int32.Parse(style_desgn.Split('@')[1].Split('!')[0]) / 2,
                                                       Int32.Parse(style_desgn.Split('@')[1].Split('!')[1]) / 2);
                        }
                    }
                    else
                    {
                        pic_design.Visible = false;
                    }
                }
                else
                {
                    pic_design.Visible = false;
                }
            }
            else
            {
                pic_design.Visible = false;
            }


            llb_product_link.Text         = product.product_link;
            llb_product_link.LinkClicked += Llb_product_link_LinkClicked;
            lb_quantity.Text              = "Số lượng: " + order.quantity;
            lb_user.Text          = "User: "******"Thời gian: " + order.createDate.ToString("yyyy-MM-dd HH:mm:ss");
            lb_email.Text         = "Email: " + order.email;
            lb_firstname.Text     = "Họ: " + order.firstname;
            lb_lastname.Text      = "Tên: " + order.lastname;
            lb_streetaddress.Text = "địa chỉ: " + order.street_address;
            lb_optional.Text      = "Địa chỉ (optional): " + order.apt_suite_other;
            lb_city.Text          = "Thành phố: " + order.city;
            lb_postcode.Text      = "Mã bưu chính: " + order.postal_code;
            lb_country.Text       = "Quốc gia: " + ((controller.getCountrybyId(order.country_id) == null) ? string.Empty : controller.getCountrybyId(order.country_id).country_name);
            lb_phonenum.Text      = "Số điện thoại: " + order.phone_number;
            lb_provine.Text       = "Bang: " + order.province;
        }