Exemple #1
0
        private void BtnApply_Click(object sender, EventArgs e)
        {
            try
            {
                int      PackageId            = selectedPackage;
                string   PkgName              = txtPackageName.Text;
                DateTime PkgStartDate         = dateTimePackageStart.Value;
                DateTime PkgEndDate           = dateTimePackageEnd.Value;
                string   PkgDesc              = txtPackageDescription.Text;
                double   PkgBasePrice         = double.Parse(txtPackagePrice.Text);
                double   PkgAgencyCommission  = double.Parse(txtPackageAgency.Text);
                string   PackageImageLocation = "";
                if (!newImage)
                {
                    PackageImageLocation = txtFilePath.Text;
                }
                else if (txtFilePath.Text == "")
                {
                    PackageImageLocation = null;
                }
                else
                {
                    //string image = ConfigurationManager.AppSettings["PathToProject"];
                    PackageImageLocation = @"\Content\img\" + Path.GetFileName(txtFilePath.Text);
                    //File.Copy(txtFilePath.Text, image + PackageImageLocation);
                    string host = "ftp://mikebublitz.com/Content/img/" + Path.GetFileName(txtFilePath.Text);

                    FileInfo      toUpload = new FileInfo(txtFilePath.Text);
                    FtpWebRequest request  = (FtpWebRequest)WebRequest.Create(host);
                    request.Credentials = new NetworkCredential("mwbublit", "ftppassword");
                    request.Method      = WebRequestMethods.Ftp.UploadFile;
                    Stream     ftpStream = request.GetRequestStream();
                    FileStream file      = File.OpenRead(txtFilePath.Text);
                    int        length    = 1024;
                    byte[]     buffer    = new byte[length];
                    int        bytesRead = 0;
                    do
                    {
                        bytesRead = file.Read(buffer, 0, length);
                        ftpStream.Write(buffer, 0, bytesRead);
                    }while (bytesRead != 0);
                    file.Close();
                    ftpStream.Close();
                }

                List <int> productsList = new List <int>();
                for (int i = 0; i < gridProductSupplierRemove.Rows.Count; i++)
                {
                    int product = Convert.ToInt32(gridProductSupplierRemove.Rows[i].Cells["ProductSupplierId"].Value);
                    productsList.Add(product);
                }

                TravelWinRepository package = new TravelWinRepository();
                package.UpdatePackage(PackageId, PkgName, PkgStartDate, PkgEndDate, PkgDesc, PkgBasePrice, PkgAgencyCommission, PackageImageLocation, productsList);
                callRefreshData();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }