예제 #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();
            }
        }
예제 #2
0
        private void refreshitems()
        {
            DataTable dtsup = SupplierDB.GetData();

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

            txtSupId.Text   = dtsup.Rows[nindex]["SupplierId"].ToString();
            txtSupName.Text = dtsup.Rows[nindex]["SupName"].ToString();


            dgvSups.DataSource = SupplierDB.GetData();


            if (dgvSups.DataSource != null)
            {
                for (int i = 0; i < dgvSups.Rows.Count; i++)
                {
                    dgvSups.Rows[i].Selected = false;
                    dgvSups.Rows[i].DefaultCellStyle.BackColor = Color.White;
                }
                if (nindex < dgvSups.Rows.Count)
                {
                    dgvSups.Rows[nindex].Selected = true;
                    dgvSups.Rows[nindex].DefaultCellStyle.BackColor = Color.LightYellow;
                }
            }
        }
예제 #3
0
        private void SupplierFrm_Load(object sender, EventArgs e)
        {
            BindingSource supbindsource = new BindingSource();

            supbindsource.DataSource          = SupplierDB.GetData();
            bindingNavigatorSup.BindingSource = supbindsource;
            refreshitems();
        }
예제 #4
0
        private void BindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            BindingSource supbindsource = new BindingSource();

            supbindsource.DataSource          = SupplierDB.GetData();
            bindingNavigatorSup.BindingSource = supbindsource;

            txtSupId.Text   = "-1";
            txtSupName.Text = "";
        }
예제 #5
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();
                    }
                }
            }
        }
예제 #6
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;
     }
 }
예제 #7
0
        private void BindingNavigatorDeleteItem_Click(object sender, EventArgs e)
        {
            if (Validation())
            {
                if (txtSupId.Text == "-1" || txtSupId.Text == "")
                {
                    CustMesg msgfrm = new CustMesg();
                    msgfrm.Showmsg("Not a valid Supplier!");
                    msgfrm.Show();
                    refreshitems();
                    BindingSource supbindsource = new BindingSource();
                    supbindsource.DataSource          = SupplierDB.GetData();
                    bindingNavigatorSup.BindingSource = supbindsource;
                    //MessageBox.Show("Not a valid Supplier!");
                }
                else
                {
                    int       supId = Convert.ToInt32(txtSupId.Text);
                    Suppliers sup   = new Suppliers();
                    sup.nSupId     = supId;
                    sup.strSupName = txtSupName.Text;
                    if (!Prod_SuppliersDB.CheckSupInusebySupId(supId) && !SupplierContactsDB.CheckSupplierInuse(supId))
                    {
                        //if the supplier information is not in use in Prod_supplier table
                        SupplierDB.DeleteSupplier(sup);
                        refreshitems();
                    }
                    else
                    {
                        //if the supplier info is using in Prod_supplier table
                        CustMesg custMesg = new CustMesg();
                        custMesg.Showmsg("The Supplier is in use in Product_Supplier table,\n Please delete record in Product_Supplier table first!");
                        custMesg.Show();

                        refreshitems();
                        BindingSource supbindsource = new BindingSource();
                        supbindsource.DataSource          = SupplierDB.GetData();
                        bindingNavigatorSup.BindingSource = supbindsource;
                    }
                }
            }
            else
            {
                refreshitems();
                BindingSource supbindsource = new BindingSource();
                supbindsource.DataSource          = SupplierDB.GetData();
                bindingNavigatorSup.BindingSource = supbindsource;
            }
        }
예제 #8
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();
        }
예제 #9
0
        private void refreshitems()
        {
            DataTable dtps = Prod_SuppliersDB.GetAllDatabyName();

            //bindingNavigatorPS.PositionItem.Text = dtps.Rows.Count.ToString();
            int nindex = Convert.ToInt32(bindingNavigatorPS.PositionItem.Text) - 1;

            if (nindex < dtps.Rows.Count)
            {
                txtProdSupID.Text = dtps.Rows[nindex]["ProductSupplierId"].ToString();

                cbProducts.DisplayMember  = "ProdName";
                cbProducts.ValueMember    = "ProductId";
                cbProducts.DataSource     = ProductDB.GetData();
                cbSuppliers.DisplayMember = "SupName";
                cbSuppliers.ValueMember   = "SupplierId";
                cbSuppliers.DataSource    = SupplierDB.GetData();

                cbProducts.Text  = dtps.Rows[nindex]["ProdName"].ToString();
                cbSuppliers.Text = dtps.Rows[nindex]["SupName"].ToString();
            }
            //if (dgvProdSup.DataSource==null)
            {
                dgvProdSup.DataSource = Prod_SuppliersDB.GetAllDatabyName();
            }
            if (dgvProdSup.DataSource != null)
            {
                for (int i = 0; i < dgvProdSup.Rows.Count; i++)
                {
                    dgvProdSup.Rows[i].Selected = false;
                    dgvProdSup.Rows[i].DefaultCellStyle.BackColor = Color.White;
                }
                if (nindex < dgvProdSup.Rows.Count)
                {
                    dgvProdSup.Rows[nindex].Selected = true;
                    dgvProdSup.Rows[nindex].DefaultCellStyle.BackColor = Color.LightYellow;
                }
            }
        }
예제 #10
0
        private void ToolStripBtnSave_Click(object sender, EventArgs e)
        {
            if (Validation())
            {
                if (txtSupId.Text != "")
                {
                    int       supId = Convert.ToInt32(txtSupId.Text);
                    Suppliers sup   = new Suppliers();
                    sup.nSupId     = supId;
                    sup.strSupName = txtSupName.Text;
                    if (txtSupId.Text == "-1")
                    {
                        //insert new
                        if (SupplierDB.CheckSuppliersExistbyName(txtSupName.Text))
                        {
                            CustMesg msgfrm = new CustMesg();
                            msgfrm.Showmsg("Supplier exist already!");
                            msgfrm.Show();
                            //MessageBox.Show("Supplier exist already!");
                        }
                        else
                        {
                            SupplierDB.AddSupplier(sup);
                        }
                    }
                    else
                    {
                        //update

                        SupplierDB.UpdateSupplier(sup, sup);
                    }
                    refreshitems();

                    BindingSource supbindsource = new BindingSource();
                    supbindsource.DataSource          = SupplierDB.GetData();
                    bindingNavigatorSup.BindingSource = supbindsource;
                }
            }
        }
예제 #11
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;
     }
 }
예제 #12
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();
            }
        }