Beispiel #1
0
        private void btnAddPack_Click(object sender, EventArgs e)
        {
            if (Validator.IsPresent(packageIdTextBox) &&
                Validator.IsCorrectLength(packageIdTextBox, 10) &&
                IsUniqueCode(packageIdTextBox) &&     // coded below in this form
                Validator.IsPresent(pkgNameTextBox) &&
                Validator.IsCorrectLength(pkgNameTextBox, 50) &&
                Validator.IsPresent(pkgDescTextBox) &&
                Validator.IsCorrectLength(pkgDescTextBox, 50) &&
                Validator.IsPresent(pkgBasePriceTextBox) &&
                Validator.IsDecimal(pkgBasePriceTextBox) &&
                Validator.IsNonNegativeDecimal(pkgBasePriceTextBox) &&
                Validator.IsPresent(pkgAgencyCommissionTextBox) &&
                Validator.IsDecimal(pkgAgencyCommissionTextBox) &&
                Validator.IsNonNegativeInt(pkgAgencyCommissionTextBox)
                )
            {
                Package newPckage = new Package // create Package using provided data
                {
                    PackageId           = Convert.ToInt32(packageIdTextBox.Text),
                    PkgName             = pkgNameTextBox.Text,
                    PkgStartDate        = Convert.ToDateTime(pkgStartDateDateTimePicker.Text),
                    PkgEndDate          = Convert.ToDateTime(pkgEndDateDateTimePicker.Text),
                    PkgDesc             = pkgDescTextBox.Text,
                    PkgBasePrice        = Convert.ToDecimal(pkgBasePriceTextBox.Text),
                    PkgAgencyCommission = Convert.ToDecimal(pkgAgencyCommissionTextBox.Text),
                };

                int SupId = (int)cboSupplies.SelectedValue;

                int cod       = 0;
                var codprosup = from prosup in dbContext.Products_Suppliers
                                join supplier in dbContext.Suppliers
                                on prosup.SupplierId equals supplier.SupplierId
                                where prosup.SupplierId == SupId
                                select new { prosup.ProductSupplierId };
                foreach (var item in codprosup)
                {
                    cod = item.ProductSupplierId;
                }
                // MessageBox.Show(cod.ToString());
                //LoadproSup(SupId);

                // insert through data context object from the main form
                dbContext.Packages.InsertOnSubmit(newPckage);
                dbContext.SubmitChanges(); // submit to the database


                Packages_Products_Supplier newPacksup = new Packages_Products_Supplier
                {
                    PackageId         = Convert.ToInt32(packageIdTextBox.Text),
                    ProductSupplierId = cod,
                };
                // insert through data context object from the main form
                dbContext.Packages_Products_Suppliers.InsertOnSubmit(newPacksup);
                dbContext.SubmitChanges(); // submit to the database
                DialogResult = DialogResult.OK;
            }
        }
Beispiel #2
0
        private void btnAddPack_Click(object sender, EventArgs e)
        {
            try
            {
                if (//Validator.IsPresent(packageIdTextBox) &&
                    //Validator.IsCorrectLength(packageIdTextBox, 10) &&
                    //IsUniqueCode(packageIdTextBox) && // coded below in this form
                    Validator.IsPresent(pkgNameTextBox) &&
                    Validator.IsCorrectLength(pkgNameTextBox, 50) &&
                    Validator.IsPresent(pkgDescTextBox) &&
                    Validator.IsCorrectLength(pkgDescTextBox, 50) &&
                    Validator.IsPresent(pkgBasePriceTextBox) &&
                    Validator.IsDecimal(pkgBasePriceTextBox) &&
                    Validator.IsNonNegativeDecimal(pkgBasePriceTextBox) &&
                    Validator.IsPresent(pkgAgencyCommissionTextBox) &&
                    Validator.IsDecimal(pkgAgencyCommissionTextBox) &&
                    Validator.IsNonNegativeInt(pkgAgencyCommissionTextBox) &&
                    //validate comission
                    ValidateCommission(pkgAgencyCommissionTextBox, pkgBasePriceTextBox) &&
                    //validate Endate
                    ValidateEndDate(pkgEndDateDateTimePicker, pkgStartDateDateTimePicker) &&
                    ValidateProducts(cboProducts)
                    )
                {
                    Package newPckage = new Package // create Package using provided data
                    {
                        //PackageId = Convert.ToInt32(packageIdTextBox.Text),
                        PkgName             = pkgNameTextBox.Text,
                        PkgStartDate        = Convert.ToDateTime(pkgStartDateDateTimePicker.Text),
                        PkgEndDate          = Convert.ToDateTime(pkgEndDateDateTimePicker.Text),
                        PkgDesc             = pkgDescTextBox.Text,
                        PkgBasePrice        = Convert.ToDecimal(pkgBasePriceTextBox.Text),
                        PkgAgencyCommission = Convert.ToDecimal(pkgAgencyCommissionTextBox.Text),
                    };

                    int SupId = (int)cboSupplies.SelectedValue;

                    int cod       = 0;
                    var codprosup = from prosup in dbContext.Products_Suppliers
                                    join supplier in dbContext.Suppliers
                                    on prosup.SupplierId equals supplier.SupplierId
                                    where prosup.SupplierId == SupId
                                    select new { prosup.ProductSupplierId };
                    foreach (var item in codprosup)
                    {
                        cod = item.ProductSupplierId;
                    }
                    // MessageBox.Show(cod.ToString());
                    //LoadproSup(SupId);

                    // insert through data context object from the main form
                    dbContext.Packages.InsertOnSubmit(newPckage);
                    dbContext.SubmitChanges(); // submit to the database

                    foreach (DataGridViewRow dgvRenglon in dgvProducts.Rows)
                    {
                        if (dgvRenglon.Cells[0].Value.ToString() != null)
                        {
                            MessageBox.Show(dgvRenglon.Cells[0].Value.ToString());
                        }

                        Packages_Products_Supplier newPacksup = new Packages_Products_Supplier
                        {
                            PackageId         = newPckage.PackageId,
                            ProductSupplierId = Convert.ToInt32(dgvRenglon.Cells[0].Value.ToString()),
                        };
                        dbContext.Packages_Products_Suppliers.InsertOnSubmit(newPacksup);
                        dbContext.SubmitChanges();
                    }

                    //Packages_Products_Supplier newPacksup = new Packages_Products_Supplier
                    //{
                    //    PackageId = GetKeyPack(),
                    //    ProductSupplierId = cod,
                    //};
                    // insert through data context object from the main form


                    //using (var scope = new TransactionScope())
                    //{
                    //    dbContext.SubmitChanges(); // submit to the database

                    //    scope.Complete();
                    //}

                    DialogResult = DialogResult.OK;

                    MessageBox.Show("Package was entry");
                    this.Refresh();
                    cleanForm();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 private void detach_Packages_Products_Suppliers(Packages_Products_Supplier entity)
 {
     this.SendPropertyChanging();
     entity.Products_Supplier = null;
 }
 partial void DeletePackages_Products_Supplier(Packages_Products_Supplier instance);
 private void attach_Packages_Products_Suppliers(Packages_Products_Supplier entity)
 {
     this.SendPropertyChanging();
     entity.Package = this;
 }
 partial void InsertPackages_Products_Supplier(Packages_Products_Supplier instance);