Beispiel #1
0
        private void UpdateProdSupTopps(int pkgId)
        {
            Prod_Suppliers prodsup = new Prod_Suppliers();
            Products       prod    = ProductDB.GetProductsbyName(cbProducts.Text);

            prodsup.nProdId = prod.nProdId;//cbProducts.SelectedValue);
            Suppliers sup = SupplierDB.GetSuppliersbyName(cbSups.Text);

            prodsup.nSupId = sup.nSupId;// Convert.ToInt32(cbSups.SelectedValue);
            DataTable dt        = Prod_SuppliersDB.GetProd_SupbyPsId(prodsup.nProdId, prodsup.nSupId);
            int       prodsupid = 0;

            if (dt.Rows.Count > 0)
            {
                prodsupid = Convert.ToInt32(dt.Rows[0]["ProductSupplierId"]);
            }

            if (prodsupid > 0)
            {
                Pkg_Product_Suppliers pps = new Pkg_Product_Suppliers();
                pps.prodSupId = prodsupid;
                pps.pkgId     = pkgId;
                Pkg_Product_SuppliersDB.AddPPSData(pps);

                refreshitems();
            }
            else
            {
                CustMesg custMesg = new CustMesg();
                custMesg.Showmsg("There is no supplier information in database! \n Please select other products!");
                custMesg.Show();
            }
        }
Beispiel #2
0
        //private void BindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        //{
        //    dgvPkgProd.DataSource = null;
        //    dgvPkgProd.ColumnCount = 1;
        //    dgvPkgProd.Columns[0].Name = "ProdName";
        //}

        private void BtnDeductProdfromPkg_Click(object sender, EventArgs e)
        {
            //if pkg with prod_sup
            //update pkg_prod_sup delete record
            if (dgvPkgProd.Rows.Count > 0)
            {
                if (packageIdTextBox.Text == "" || packageIdTextBox.Text == "-1")
                {
                    //if new package
                    //remove row
                    if (dgvPkgProd.SelectedRows.Count > 0)
                    {
                        for (int i = 0; i < dgvPkgProd.SelectedRows.Count; i++)
                        {
                            dgvPkgProd.Rows.RemoveAt(dgvPkgProd.SelectedRows[i].Index);
                            dgvPkgProd.Refresh();
                        }
                    }
                }
                else if (packageIdTextBox.Text != "" && packageIdTextBox.Text != "-1")
                {
                    //if pkg with prod_sup
                    //update pkg_prod_sup delete record
                    int       pkgId = Convert.ToInt32(packageIdTextBox.Text);
                    DataTable dt    = Pkg_Product_SuppliersDB.GetAllPsDatabyPkgId(pkgId);
                    if (dgvPkgProd.SelectedRows.Count > 0)
                    {
                        for (int i = 0; i < dgvPkgProd.SelectedRows.Count; i++)
                        {
                            //delete pkg_prod_sup record according to datagridview prodname and supname
                            int prodId = ProductDB.GetProductsbyName(dgvPkgProd.SelectedRows[i].Cells[0].Value.ToString()).nProdId;
                            int supId  = SupplierDB.GetSuppliersbyName(dgvPkgProd.SelectedRows[i].Cells[1].Value.ToString()).nSupId;

                            DataTable dtps = Prod_SuppliersDB.GetProd_SupbyPsId(prodId, supId);
                            for (int m = 0; m < dtps.Rows.Count; m++)
                            {
                                int prodsupId = Convert.ToInt32(dtps.Rows[m]["ProductSupplierId"]);
                                for (int j = 0; j < dt.Rows.Count; j++)
                                {
                                    int ppspsId = Convert.ToInt32(dt.Rows[j]["ProductSupplierId"]);
                                    if (prodsupId == ppspsId)
                                    {
                                        Pkg_Product_Suppliers pps = new Pkg_Product_Suppliers();
                                        pps.pkgId     = pkgId;
                                        pps.prodSupId = prodsupId;
                                        Pkg_Product_SuppliersDB.DeletePPSbypps(pps);
                                    }
                                }
                            }
                        }
                        refreshitems();
                    }
                }
            }
        }
Beispiel #3
0
 private void BindingNavigatorDeleteItem_Click(object sender, EventArgs e)
 {
     if (Validation())
     {
         if (txtProdSupID.Text != "-1")
         {
             int            nprodId = ProductDB.GetProductsbyName(cbProducts.Text).nProdId;
             int            nsupId  = SupplierDB.GetSuppliersbyName(cbSuppliers.Text).nSupId;
             Prod_Suppliers ps      = new Prod_Suppliers();
             ps.nProdId = nprodId;
             ps.nSupId  = nsupId;
             int prodsupID = Convert.ToInt32(txtProdSupID.Text);
             ps.nProdSupId = prodsupID;
             if (!Pkg_Product_SuppliersDB.CheckDataInusebyPSID(prodsupID) && !BookingDetailsDB.CheckProdSupInuse(prodsupID))
             {
                 Prod_SuppliersDB.DeleteRec(ps);
                 refreshitems();
             }
             else
             {
                 CustMesg custMesg = new CustMesg();
                 custMesg.Showmsg("The Product_Supplier record is in use in Pkg_Product_Supplier table,\n Please delete record in Pkg_Product_Supplier table first!");
                 custMesg.Show();
                 refreshitems();
                 BindingSource psbindsource = new BindingSource();
                 psbindsource.DataSource          = Prod_SuppliersDB.GetAllDatabyName();
                 bindingNavigatorPS.BindingSource = psbindsource;
             }
         }
         else
         {
             CustMesg msgfrm = new CustMesg();
             msgfrm.Showmsg("Not a valid record!");
             msgfrm.Show();
             refreshitems();
             BindingSource psbindsource = new BindingSource();
             psbindsource.DataSource          = Prod_SuppliersDB.GetAllDatabyName();
             bindingNavigatorPS.BindingSource = psbindsource;
             //MessageBox.Show("Not a valid record!");
         }
     }
     else
     {
         refreshitems();
         BindingSource psbindsource = new BindingSource();
         psbindsource.DataSource          = Prod_SuppliersDB.GetAllDatabyName();
         bindingNavigatorPS.BindingSource = psbindsource;
     }
 }
Beispiel #4
0
        private void InsertProdSupTopps(int pkgId)
        {
            Prod_Suppliers prodsup = new Prod_Suppliers();
            Products       prod    = ProductDB.GetProductsbyName(cbProducts.Text);

            prodsup.nProdId = prod.nProdId;//cbProducts.SelectedValue);
            Suppliers sup = SupplierDB.GetSuppliersbyName(cbSups.Text);

            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"]);
            Pkg_Product_Suppliers pps       = new Pkg_Product_Suppliers();

            pps.prodSupId = prodsupid;
            pps.pkgId     = pkgId;
            Pkg_Product_SuppliersDB.AddPPSData(pps);

            refreshitems();
        }
Beispiel #5
0
 private void ToolStripButton1_Click(object sender, EventArgs e)
 {
     //Save
     if (Validation())
     {
         int            nprodId = ProductDB.GetProductsbyName(cbProducts.Text).nProdId;
         int            nsupId  = SupplierDB.GetSuppliersbyName(cbSuppliers.Text).nSupId;
         Prod_Suppliers ps      = new Prod_Suppliers();
         ps.nProdId = nprodId;
         ps.nSupId  = nsupId;
         if (txtProdSupID.Text == "-1")
         {
             if (Prod_SuppliersDB.GetProd_SupbyPsId(nprodId, nsupId).Rows.Count <= 0)
             {
                 Prod_SuppliersDB.AddRecord(ps);
             }
             else
             {
                 CustMesg msgfrm = new CustMesg();
                 msgfrm.Showmsg("Record exist already!");
                 msgfrm.Show();
                 //MessageBox.Show("Record exist already!");
             }
         }
         else
         {
             int prodsupID = Convert.ToInt32(txtProdSupID.Text);
             ps.nProdSupId = prodsupID;
             Prod_SuppliersDB.UpdateRecord(ps, ps);
         }
         refreshitems();
         BindingSource psbindsource = new BindingSource();
         psbindsource.DataSource          = Prod_SuppliersDB.GetAllDatabyName();
         bindingNavigatorPS.BindingSource = psbindsource;
     }
 }
Beispiel #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();
            }
        }