コード例 #1
0
ファイル: AddProduct.cs プロジェクト: Mason-DEV/C698Project
        private void saveButton_Click(object sender, EventArgs e)
        {
            bool pass = validation();

            if (pass)
            {
                //Add Prodocut then add associatedPart
                String productName = productNameTextbox.Text;

                Double productPrice = Convert.ToDouble(priceTextbox.Text);

                int productInStock = Convert.ToInt32(invTextbox.Text);

                int productMin = Convert.ToInt32(minTextbox.Text);

                int productMax = Convert.ToInt32(maxTextbox.Text);



                productID = productID + 1;
                Console.WriteLine("product set" + productID);
                productToAdd.setProductID(productID);
                productToAdd.setName(productName);
                productToAdd.setPrice(productPrice);
                productToAdd.setinStock(productInStock);
                productToAdd.setMin(productMin);
                productToAdd.setMax(productMax);

                Inventory newProduct = new Inventory();
                newProduct.addProduct(productToAdd);

                foreach (DataGridViewRow row in partsAssociatedDataGrid.Rows)
                {
                    Part assocPart = new Part();
                    assocPart.setPartID(Convert.ToInt32(row.Cells[0].Value));
                    assocPart.setName(Convert.ToString(row.Cells[1].Value));
                    assocPart.setinStock(Convert.ToInt32(row.Cells[2].Value));
                    assocPart.setPrice(Convert.ToDouble(row.Cells[3].Value));
                    Console.WriteLine("adding assoc Part" + assocPart.getParttID());
                    productToAdd.addAssociatedPart(assocPart);
                }


                this.Close();
                MainScreen main = new MainScreen();
                main.Show();
            }
        }
コード例 #2
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            bool pass = validation();

            if (pass)
            {
                //Add Prodocut then add associatedPart
                String productName = productNameTextbox.Text;

                Double productPrice = Convert.ToDouble(priceTextbox.Text);

                int productInStock = Convert.ToInt32(invTextbox.Text);

                int productMin = Convert.ToInt32(minTextbox.Text);

                int productMax = Convert.ToInt32(maxTextbox.Text);



                productID = productID + 1;
                Console.WriteLine("product set" + productID);
                modifyProduct.setProductID(productID);
                modifyProduct.setName(productName);
                modifyProduct.setPrice(productPrice);
                modifyProduct.setinStock(productInStock);
                modifyProduct.setMin(productMin);
                modifyProduct.setMax(productMax);

                Inventory newProduct = new Inventory();
                newProduct.updateProduct(productID, modifyProduct);

                //first we want to delete all assoicated parts for this product
                SqlConnection con     = new System.Data.SqlClient.SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB; AttachDbFilename=" + Application.StartupPath + "\\DB.mdf; Integrated Security=True");
                SqlCommand    command = con.CreateCommand();
                con.Open();
                SqlTransaction transaction;
                // Start a local transaction.
                transaction = con.BeginTransaction("SampleTransaction");

                // Must assign both transaction object and connection
                // to Command object for a pending local transaction
                command.Connection  = con;
                command.Transaction = transaction;
                command.CommandText =
                    "DELETE FROM[dbo].[associatedParts] WHERE productID = @productID";
                command.Parameters.AddWithValue("@productID", productID);

                command.ExecuteNonQuery();
                transaction.Commit();
                con.Close();



                foreach (DataGridViewRow row in assocPartsDataGridView.Rows)
                {
                    Part assocPart = new Part();
                    assocPart.setPartID(Convert.ToInt32(row.Cells[0].Value));
                    modifyProduct.removeAssociatedPart(Convert.ToInt32(row.Cells[0].Value));
                    assocPart.setName(Convert.ToString(row.Cells[1].Value));
                    assocPart.setinStock(Convert.ToInt32(row.Cells[2].Value));
                    assocPart.setPrice(Convert.ToDouble(row.Cells[3].Value));
                    //First remove all assoc parts from associatedParts table
                    modifyProduct.addAssociatedPart(assocPart);
                }


                this.Close();
                MainScreen main = new MainScreen();
                main.Show();
            }
        }
コード例 #3
0
ファイル: AddPart.cs プロジェクト: Mason-DEV/C698Project
        private void saveButton_Click(object sender, EventArgs e)
        {
            bool pass = validation();

            if (pass)
            {
                String partName = partNameTextbox.Text;

                Double partPrice = Convert.ToDouble(priceCostTextbox.Text);

                int partInStock = Convert.ToInt32(invTextbox.Text);

                int partMin = Convert.ToInt32(minTextbox.Text);

                int partMax = Convert.ToInt32(maxTextbox.Text);

                bool inHouse = inHouseRadio.Checked;

                bool outsourced = outsourcedRadio.Checked;
                //Need to set inHouse&outsource to 0 or 1 depending if T or F


                if (inHouse)
                {
                    inHouseValue    = 1;
                    outSourcedValue = 0;
                    machineID       = Convert.ToInt32(variableTextbox.Text);
                }
                else
                {
                    inHouseValue    = 0;
                    outSourcedValue = 1;
                    companyName     = variableTextbox.Text;
                }



                SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB; AttachDbFilename=" + Application.StartupPath + "\\DB.mdf; Integrated Security=True");

                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = con;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "SELECT MAX(partID) FROM partTable;";
                con.Open();
                int partID;
                try
                {
                    partID = (Int32)cmd.ExecuteScalar();
                }
                catch
                {
                    partID = 0;
                }

                Console.WriteLine("sql  " + partID);
                partID = partID + 1;
                con.Close();
                Console.WriteLine("Setting partID to " + partID);
                Part newPart = new Part();
                newPart.setName(partName);
                newPart.setPrice(partPrice);
                newPart.setinStock(partInStock);
                newPart.setMin(partMin);
                newPart.setMax(partMax);
                newPart.setPartID(partID);
                if (inHouse)
                {
                    newPart.getPartINFO(inHouseValue, outSourcedValue, companyName, machineID);
                    //Inhouse mach = new Inhouse();
                    //mach.setMachineID(machineID);
                    //mach.setInhouse(inHouseValue);
                    //mach.setoutsourced(outSourcedValue);
                }
                else
                {
                    newPart.getPartINFO(inHouseValue, outSourcedValue, companyName, machineID);
                }


                newPart.addThePart();

                this.Close();
                MainScreen main = new MainScreen();
                main.Show();
            }
        }
コード例 #4
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            bool pass = validation();

            if (pass)
            {
                //Grab ID for the part we are changing
                int id = modifyPart.getParttID();
                //Grab fields on form and set those to Modify Part
                String partName = partNameTextbox.Text;

                Double partPrice = Convert.ToDouble(priceCostTextbox.Text);

                int partInStock = Convert.ToInt32(invTextbox.Text);

                int partMin = Convert.ToInt32(minTextbox.Text);

                int partMax = Convert.ToInt32(maxTextbox.Text);

                bool inHouse = inHouseRadio.Checked;

                bool outsourced = outsourcedRadio.Checked;

                if (inHouse)
                {
                    Console.WriteLine("Updateding inHouse");

                    modifyOutSource.setInhouse(1);
                    modifyOutSource.setoutsourced(0);

                    modifyInHouse.setInhouse(1);
                    modifyInHouse.setoutsourced(0);
                    modifyInHouse.setMachineID(Convert.ToInt32(variableTextbox.Text));
                }
                else
                {
                    Console.WriteLine("Updateding outSourced");

                    modifyInHouse.setInhouse(0);
                    modifyInHouse.setoutsourced(1);

                    modifyOutSource.setInhouse(0);
                    modifyOutSource.setoutsourced(1);
                    modifyOutSource.setCompanyName(Convert.ToString(variableTextbox.Text));
                }

                modifyPart.setMax(partMax);
                modifyPart.setMin(partMin);
                modifyPart.setinStock(partInStock);
                modifyPart.setName(partName);
                modifyPart.setPrice(partPrice);


                //Call updatePart passing in ID and modifyPart
                Inventory modify = new Inventory();
                //adds inhouse or outsourced info
                if (inHouse)
                {
                    modify.houseInfo(modifyInHouse);
                }
                else
                {
                    modify.outSourceInfo(modifyOutSource);
                }

                modify.updatePart(id, modifyPart);

                this.Close();
                MainScreen main = new MainScreen();
                main.Show();
            }
        }