Esempio n. 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();
            }
        }
Esempio n. 2
0
 private void BtnChangePwd_Click(object sender, EventArgs e)
 {
     if (validation())
     {
         AgentLogin agent = new AgentLogin();
         agent.nAgentId    = Convert.ToInt32(txtUsrID.Text);
         agent.strPassword = GetHashString(txtPwd.Text);
         if (AgentLogInDB.CheckIDexist(agent.nAgentId))
         {
             AgentLogInDB.UpdateAgentLogin(agent, agent);
             CustMesg msgfrm = new CustMesg();
             msgfrm.Showmsg("Password updated!");
             msgfrm.Show();
             //MessageBox.Show("Password updated!");
         }
         else if (AgentsDB.CheckAgentIDExist(agent.nAgentId))
         {
             AgentLogInDB.AddAgentLogIn(agent);
             CustMesg msgfrm = new CustMesg();
             msgfrm.Showmsg("Account created!");
             msgfrm.Show();
             //MessageBox.Show("Account created!");
         }
         else
         {
             txtUsrID.Text = "";
             txtPwd.Text   = "";
             CustMesg msgfrm = new CustMesg();
             msgfrm.Showmsg("AgentId does not exist, Please refill the form!");
             msgfrm.Show();
             //MessageBox.Show("AgentId does not exist, Please refill the form!");
         }
     }
 }
Esempio n. 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;
     }
 }
Esempio n. 4
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;
            }
        }
Esempio n. 5
0
 private void BindingNavigatorDeleteItem_Click(object sender, EventArgs e)
 {
     if (Validation())
     {
         if (txtProdId.Text == "-1" || txtProdId.Text == "")
         {
             CustMesg msgfrm = new CustMesg();
             msgfrm.Showmsg("Not a valid Product!");
             msgfrm.Show();
             refreshitems();
             BindingSource prodbindsource = new BindingSource();
             prodbindsource.DataSource          = ProductDB.GetData();
             bindingNavigatorProd.BindingSource = prodbindsource;
         }
         else
         {
             int      prodId = Convert.ToInt32(txtProdId.Text);
             Products prod   = new Products();
             prod.nProdId     = prodId;
             prod.strProdName = txtProdName.Text;
             if (!Prod_SuppliersDB.CheckProdInusebyProdId(prodId))
             {
                 ProductDB.DeleteProduct(prod);
                 refreshitems();
             }
             else
             {
                 CustMesg custMesg = new CustMesg();
                 custMesg.Showmsg("The Product is in use in Product_Supplier table,\n Please delete record in Product_Supplier table first!");
                 custMesg.Show();
                 refreshitems();
                 BindingSource prodbindsource = new BindingSource();
                 prodbindsource.DataSource          = ProductDB.GetData();
                 bindingNavigatorProd.BindingSource = prodbindsource;
             }
         }
     }
     else
     {
         refreshitems();
         BindingSource prodbindsource = new BindingSource();
         prodbindsource.DataSource          = ProductDB.GetData();
         bindingNavigatorProd.BindingSource = prodbindsource;
     }
 }
Esempio n. 6
0
        private void ToolStripBtnSave_Click(object sender, EventArgs e)
        {
            if (Validation())
            {
                if (txtProdId.Text != "")
                {
                    int      prodId = Convert.ToInt32(txtProdId.Text);
                    Products prod   = new Products();
                    prod.nProdId     = prodId;
                    prod.strProdName = txtProdName.Text;
                    if (txtProdId.Text == "-1")
                    {
                        //insert new
                        if (ProductDB.CheckProductsExistbyName(txtProdName.Text))
                        {
                            CustMesg msgfrm = new CustMesg();
                            msgfrm.Showmsg("Products Exist already!");
                            msgfrm.Show();
                            //MessageBox.Show("Products Exist already!");
                        }
                        else
                        {
                            ProductDB.AddProduct(prod);
                        }
                    }
                    else
                    {
                        //update

                        ProductDB.UpdateProduct(prod, prod);
                    }
                    refreshitems();

                    BindingSource prodbindsource = new BindingSource();
                    prodbindsource.DataSource          = ProductDB.GetData();
                    bindingNavigatorProd.BindingSource = prodbindsource;
                }
            }
        }
Esempio n. 7
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;
                }
            }
        }
Esempio n. 8
0
 private void BtnLogin_Click(object sender, EventArgs e)
 {
     if (validation())
     {
         AgentLogin agent = new AgentLogin();
         agent.nAgentId    = Convert.ToInt32(txtUsrID.Text);
         agent.strPassword = GetHashString(txtPwd.Text);
         if (AgentLogInDB.CheckIDexist(agent.nAgentId))
         {
             if (AgentLogInDB.CheckPwdMatch(agent))
             {
                 MainFrm mainfrm = new MainFrm();
                 if (!FrmValid.checkformopen(mainfrm.Text))
                 {
                     FrmValid.AgentId = agent.nAgentId;
                     //this.Close();
                     mainfrm.Show();
                     this.Visible = false;
                 }
             }
             else
             {
                 CustMesg msgfrm = new CustMesg();
                 msgfrm.Showmsg("Password Wrong!");
                 msgfrm.Show();
                 //MessageBox.Show("Password Wrong!");
             }
         }
         else
         {
             CustMesg msgfrm = new CustMesg();
             msgfrm.Showmsg("User is not exist!");
             msgfrm.Show();
             //MessageBox.Show("User is not exist!");
         }
     }
 }
Esempio n. 9
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;
     }
 }
Esempio n. 10
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();
            }
        }
Esempio n. 11
0
        private void BtnAddProdSup_Click(object sender, EventArgs e)
        {
            if (validateprodSup())
            {
                //if current pkg have prod sup already change current package prod supplier
                //update pkg_prod_supplier
                //if current no prod sup
                //add new recordd into pkg_prod_supplier
                //if add to new package
                //reemove binding souce of datagridview(done by package add button already) and just add row
                int pkgId = Convert.ToInt32(packageIdTextBox.Text);
                if (pkgId == -1)//new package
                {
                    //create new package
                    //if no prod_supplier info then insert only package info
                    //if have prod_supplier info then insert package and package_product_supplier info
                    if (dgvPkgProd.Rows.Count > 0)
                    {
                        //have prod_supplier info then insert package and package_product_supplier info
                        List <Prod_Suppliers> prodlist = new List <Prod_Suppliers>();
                        for (int j = 0; j < dgvPkgProd.Rows.Count; j++)
                        {
                            Prod_Suppliers prodsup = new Prod_Suppliers();
                            prodsup.strProdName = dgvPkgProd.Rows[j].Cells[0].Value.ToString();
                            prodsup.strSupName  = dgvPkgProd.Rows[j].Cells[1].Value.ToString();
                            prodlist.Add(prodsup);
                        }

                        for (int j = 0; j < prodlist.Count; j++)
                        {
                            if ((cbProducts.Text == prodlist[j].strProdName) && (cbSups.Text == prodlist[j].strSupName))
                            {
                                prodlist.RemoveAt(j);
                                break;
                            }
                            else
                            {
                                continue;
                            }
                        }
                        if (prodlist.Count > 0)
                        {
                            for (int i = 0; i < prodlist.Count; i++)
                            {
                                DataGridViewRow newrow = (DataGridViewRow)dgvPkgProd.Rows[0].Clone();;
                                newrow.Cells[0].Value = cbProducts.Text;
                                newrow.Cells[1].Value = cbSups.Text;
                                dgvPkgProd.Rows.Add(newrow);
                            }
                        }
                    }
                    else
                    {
                        //No prod_supplier info, only insert package information into package table
                        DataGridViewRow newrow = new DataGridViewRow();
                        //(DataGridViewRow)dgvPkgProd.Rows;

                        newrow.Cells[0].Value = cbProducts.Text;
                        newrow.Cells[1].Value = cbSups.Text;
                        dgvPkgProd.Rows.Add(newrow);
                    }
                }
                else if (dgvPkgProd.Rows.Count > 0)
                {
                    //if combobox content already in datagridview
                    //do nothing
                    //if not in datagridview
                    //update pkg_prod_sup insert record
                    List <Prod_Suppliers> prodlist = new List <Prod_Suppliers>();
                    bool bexist = false;
                    //take current data in table into list
                    for (int j = 0; j < dgvPkgProd.Rows.Count; j++)
                    {
                        Prod_Suppliers prodsup = new Prod_Suppliers();
                        prodsup.strProdName = dgvPkgProd.Rows[j].Cells[0].Value.ToString();
                        prodsup.strSupName  = dgvPkgProd.Rows[j].Cells[1].Value.ToString();
                        prodlist.Add(prodsup);
                    }

                    for (int j = 0; j < prodlist.Count; j++)
                    {
                        if ((cbProducts.Text == prodlist[j].strProdName) && (cbSups.Text == prodlist[j].strSupName))
                        {
                            //if the product and supplier already in table then remove from the list
                            prodlist.RemoveAt(j);
                            CustMesg custMesg = new CustMesg();
                            custMesg.Showmsg("Product_Supplier Info already in table!");
                            custMesg.Show();
                            //lblAddDelMsg.Text = "Product_Supplier Info already in table!";
                            bexist = true;
                            break;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    //check data in prod_supplier table? if exist then just show info in gridview, else insert into prod_supplier table
                    //update data in package and pkg_prod_supplier
                    if (!bexist)
                    {
                        UpdateProdSupTopps(pkgId);
                    }
                }
                else
                {
                    //package no prod_supplier yet
                    InsertProdSupTopps(pkgId);
                }
            }
        }