コード例 #1
0
        public PackageFrm()
        {
            InitializeComponent();
            BindingSource pkgbindsource = new BindingSource();

            pkgbindsource.DataSource = PackageDB.GetAllPkg();
            PackagesBindingNavigator.BindingSource = pkgbindsource;
        }
コード例 #2
0
 private void PackagesBindingNavigatorSaveItem_Click(object sender, EventArgs e)
 {
     if (Validation())
     {
         Package pkg = new Package();
         pkg.PkgName      = pkgNameTextBox.Text;
         pkg.pkgStDate    = pkgStartDateDateTimePicker.Value;
         pkg.pkgEndDate   = pkgEndDateDateTimePicker.Value;
         pkg.pkgDesc      = pkgDescTextBox.Text;
         pkg.pkgBasePrice = Convert.ToDouble(pkgBasePriceTextBox.Text);
         pkg.pkgAgentCom  = Convert.ToDouble(pkgAgencyCommissionTextBox.Text);
         PackageDB.AddPackage(pkg);
         this.Validate();
     }
 }
コード例 #3
0
        private void BindingNavigatorAddNewItem_Click_1(object sender, EventArgs e)
        {
            BindingSource pkgbindsource = new BindingSource();

            pkgbindsource.DataSource = PackageDB.GetAllPkg();
            PackagesBindingNavigator.BindingSource = pkgbindsource;

            packageIdTextBox.Text            = "-1";
            pkgNameTextBox.Text              = "";
            pkgStartDateDateTimePicker.Value = DateTime.Now;
            pkgEndDateDateTimePicker.Value   = DateTime.Now;
            pkgDescTextBox.Text              = "";
            pkgBasePriceTextBox.Text         = "";
            pkgAgencyCommissionTextBox.Text  = "";

            dgvPkgProd.DataSource            = null;
            dgvPkgProd.ColumnCount           = 2;
            dgvPkgProd.Columns[0].HeaderText = "ProdName";
            dgvPkgProd.Columns[1].HeaderText = "SupName";
        }
コード例 #4
0
        private void refreshitems()
        {
            DataTable dtpkg = PackageDB.GetAllPkg();

            int nindex = Convert.ToInt32(PackagesBindingNavigator.PositionItem.Text) - 1;

            packageIdTextBox.Text            = dtpkg.Rows[nindex]["PackageId"].ToString();
            pkgNameTextBox.Text              = dtpkg.Rows[nindex]["PkgName"].ToString();
            pkgStartDateDateTimePicker.Value = Convert.ToDateTime(dtpkg.Rows[nindex]["PkgStartDate"]);
            pkgEndDateDateTimePicker.Value   = Convert.ToDateTime(dtpkg.Rows[nindex]["PkgEndDate"]);
            pkgDescTextBox.Text              = dtpkg.Rows[nindex]["PkgDesc"].ToString();
            pkgBasePriceTextBox.Text         = dtpkg.Rows[nindex]["PkgBasePrice"].ToString();
            pkgAgencyCommissionTextBox.Text  = dtpkg.Rows[nindex]["PkgAgencyCommission"].ToString();

            if (packageIdTextBox.Text != "")
            {
                Package pkg = new Package();
                pkg.nPkgId = Convert.ToInt32(packageIdTextBox.Text);
                dgvPkgProd.Columns.Clear();
                dgvPkgProd.DataSource = Pkg_Product_SuppliersDB.GetAllPkgProdSupData(pkg.nPkgId);
                //dgvPkgSup.DataSource = Pkg_Product_SuppliersDB.GetAllPkgSupData(pkg.nPkgId);
            }
        }
コード例 #5
0
        private void BindingNavigatorDeleteItem_Click(object sender, EventArgs e)
        {
            if (packageIdTextBox.Text != "" && packageIdTextBox.Text != "-1")
            {
                int pkgId = Convert.ToInt32(packageIdTextBox.Text);
                //pkgId = Convert.ToInt32(packageIdTextBox.Text);
                if (Pkg_Product_SuppliersDB.CheckDatabyPkgID(pkgId))
                {
                    Package oldpkg = new Package();
                    oldpkg.nPkgId = pkgId;

                    if (pkgId != 0)
                    {
                        Pkg_Product_Suppliers pps = new Pkg_Product_Suppliers();
                        pps.pkgId = pkgId;
                        Pkg_Product_SuppliersDB.DeletePPSbyPkgId(pps);
                        if (!BookingDB.CheckPackageIdInuse(pkgId))
                        {
                            PackageDB.DeletePackage(oldpkg);
                        }
                        else
                        {
                            CustMesg cust = new CustMesg();
                            cust.Showmsg("Package is in use in Bookings table!");
                            cust.Show();
                        }
                    }
                    BindingSource pkgbindsource = new BindingSource();
                    pkgbindsource.DataSource = PackageDB.GetAllPkg();
                    PackagesBindingNavigator.BindingSource = pkgbindsource;
                    refreshitems();
                }
                else if (PackageDB.CheckPackIdExist(pkgId))
                {
                    Package oldpkg = new Package();
                    oldpkg.nPkgId = pkgId;
                    if (!BookingDB.CheckPackageIdInuse(pkgId))
                    {
                        PackageDB.DeletePackage(oldpkg);
                    }
                    else
                    {
                        CustMesg cust = new CustMesg();
                        cust.Showmsg("Package is in use in Bookings table!");
                        cust.Show();
                    }
                    BindingSource pkgbindsource = new BindingSource();
                    pkgbindsource.DataSource = PackageDB.GetAllPkg();
                    PackagesBindingNavigator.BindingSource = pkgbindsource;
                    refreshitems();
                }
                else
                {
                    //Pkg_Product_Suppliers pps = new Pkg_Product_Suppliers();
                    //pps.pkgId = pkgId;
                    //Pkg_Product_SuppliersDB.DeletePPSbyPkgId(pps);

                    //Package oldpkg = new Package();
                    //oldpkg.nPkgId = pkgId;
                    //PackageDB.DeletePackage(oldpkg);
                    //if (pkgId != 0)
                    //{
                    //    Pkg_Product_Suppliers pkgps = new Pkg_Product_Suppliers();
                    //    pps.pkgId = pkgId;
                    //    Pkg_Product_SuppliersDB.DeletePPSbyPkgId(pkgps);

                    //}
                    BindingSource pkgbindsource = new BindingSource();
                    pkgbindsource.DataSource = PackageDB.GetAllPkg();
                    PackagesBindingNavigator.BindingSource = pkgbindsource;
                    refreshitems();
                    CustMesg cust = new CustMesg();
                    cust.Showmsg("Not a valid record!");
                    cust.Show();

                    // MessageBox.Show("The Package is using in Package_Product_Supplier Table, Please delete record in Package_Product_Supplier Table First!");
                }
            }
            else
            {
                BindingSource pkgbindsource = new BindingSource();
                pkgbindsource.DataSource = PackageDB.GetAllPkg();
                PackagesBindingNavigator.BindingSource = pkgbindsource;
                refreshitems();
                CustMesg cust = new CustMesg();
                cust.Showmsg("Not a valid record!");
                cust.Show();
            }
        }
コード例 #6
0
        private void ToolStripBtnSave_Click(object sender, EventArgs e)
        {
            if (Validation())
            {
                int     pkgId = 0;
                Package pkg   = new Package();
                pkg.PkgName      = pkgNameTextBox.Text;
                pkg.pkgStDate    = pkgStartDateDateTimePicker.Value;
                pkg.pkgEndDate   = pkgEndDateDateTimePicker.Value;
                pkg.pkgDesc      = pkgDescTextBox.Text;
                pkg.pkgBasePrice = Convert.ToDouble(pkgBasePriceTextBox.Text);
                pkg.pkgAgentCom  = Convert.ToDouble(pkgAgencyCommissionTextBox.Text);
                if (packageIdTextBox.Text == "-1")
                {
                    pkgId = PackageDB.AddPackage(pkg);
                    if (pkgId != 0)
                    {
                        if (dgvPkgProd.Rows.Count > 0)
                        {
                            for (int i = 0; i < dgvPkgProd.Rows.Count; i++)
                            {
                                Prod_Suppliers prodsup = new Prod_Suppliers();
                                Products       prod    = ProductDB.GetProductsbyName(dgvPkgProd.Rows[i].Cells[0].Value.ToString());
                                prodsup.nProdId = prod.nProdId; //cbProducts.SelectedValue);
                                Suppliers sup = SupplierDB.GetSuppliersbyName(dgvPkgProd.Rows[i].Cells[1].Value.ToString());
                                prodsup.nSupId = sup.nSupId;    // Convert.ToInt32(cbSups.SelectedValue);
                                DataTable dt        = Prod_SuppliersDB.GetProd_SupbyPsId(prodsup.nProdId, prodsup.nSupId);
                                int       prodsupid = Convert.ToInt32(dt.Rows[0]["ProductSupplierId"]);
                                //int prodsupid = Prod_SuppliersDB.AddRecord(prodsup);
                                Pkg_Product_Suppliers pps = new Pkg_Product_Suppliers();
                                pps.prodSupId = prodsupid;
                                pps.pkgId     = pkgId;
                                Pkg_Product_SuppliersDB.AddPPSData(pps);
                            }
                        }
                    }
                }
                else
                {
                    //update package
                    pkgId = Convert.ToInt32(packageIdTextBox.Text);

                    if (pkgId != 0)
                    {
                        Package oldpkg = new Package();
                        oldpkg.nPkgId = pkgId;
                        PackageDB.UpdatePkg(oldpkg, pkg);
                        DataTable dtprodsup = Pkg_Product_SuppliersDB.GetAllPkgProdSupData(pkgId);

                        if (dgvPkgProd.Rows.Count > 0)
                        {
                            for (int i = 0; i < dgvPkgProd.Rows.Count; i++)
                            {
                                string strprodname = dgvPkgProd.Rows[i].Cells[0].Value.ToString();
                                string strsupName  = dgvPkgProd.Rows[i].Cells[1].Value.ToString();
                                for (int j = 0; j < dtprodsup.Rows.Count; j++)
                                {
                                    if (strprodname != dtprodsup.Rows[j]["ProdName"].ToString() && strsupName != dtprodsup.Rows[j]["SupName"].ToString())
                                    {
                                        Prod_Suppliers prodsup = new Prod_Suppliers();
                                        Products       prod    = ProductDB.GetProductsbyName(dgvPkgProd.Rows[i].Cells[0].Value.ToString());
                                        prodsup.nProdId = prod.nProdId; //cbProducts.SelectedValue);
                                        Suppliers sup = SupplierDB.GetSuppliersbyName(dgvPkgProd.Rows[i].Cells[1].Value.ToString());
                                        prodsup.nSupId = sup.nSupId;    // Convert.ToInt32(cbSups.SelectedValue);
                                        DataTable      dt         = Prod_SuppliersDB.GetProd_SupbyPsId(prodsup.nProdId, prodsup.nSupId);
                                        Prod_Suppliers newprodsup = new Prod_Suppliers();
                                        newprodsup.nProdSupId = Convert.ToInt32(dt.Rows[0]["ProductSupplierId"]);
                                        int prodsupid = newprodsup.nProdSupId;
                                        Pkg_Product_Suppliers oldpps = new Pkg_Product_Suppliers();
                                        Pkg_Product_Suppliers pps    = new Pkg_Product_Suppliers();
                                        pps.prodSupId = prodsupid;
                                        oldpps.pkgId  = pkgId;
                                        Pkg_Product_SuppliersDB.UpdatePkgData(oldpps, pps);
                                    }
                                }
                            }
                        }
                    }
                }
                BindingSource pkgbindsource = new BindingSource();
                pkgbindsource.DataSource = PackageDB.GetAllPkg();
                PackagesBindingNavigator.BindingSource = pkgbindsource;

                refreshitems();
            }
        }