Beispiel #1
0
        public Form1(int emp_ID)
        {
            InitializeComponent();

            table_Employees     = DatabaseHelper.GetTable("Employees");
            table_Persons       = DatabaseHelper.GetTable("Person");
            person_Id           = int.Parse(table_Employees.Rows[emp_ID - 1]["Person ID"].ToString());
            LoggedInEmployee.ID = person_Id;
            string name = LoggedInEmployee.EmployeeInformation()["First Name"].ToString() + " " + LoggedInEmployee.EmployeeInformation()["Last Name"].ToString();///table_Persons.Rows[person_Id - 1]["First Name"].ToString();

            lbl_Subtext.Text = "Welcome " + name;
        }
Beispiel #2
0
        private void PlaceOrder()
        {
            List <string> listStr = new List <string>();

            foreach (ProductItem item in flw_Products.Controls)
            {
                listStr.Add(item.comboBox2.SelectedItem.ToString());
            }

            var duplicateKeys = listStr.GroupBy(x => x)
                                .Where(group => group.Count() > 1)
                                .Select(group => group.Key);

            if (duplicateKeys.Count() > 0)
            {
                MessageBox.Show("There are duplicate products! Please fix this before continuing.");
                return;
            }

            //Create entry in Orders table
            int      empID     = LoggedInEmployee.ID;
            DateTime orderDate = DateTime.Now;
            DataRow  dataRow   = LoggedInEmployee.EmployeeInformation();

            this.lbl_servicedEmployee.Text = dataRow["First Name"].ToString() + " " + dataRow["Last Name"].ToString() + " (You)";
            int dealerID = dealerDict[cmb_Dealer.SelectedItem.ToString()];

            string orderQuery = "";

            if (btn_Place_Order.Text.Contains("Update"))
            {
                orderQuery = string.Format("UPDATE Orders SET [Dealer ID]={0}, [Order Date]=#{1}#, [Required Date]=#{2}#, [Required Time]={3}, [Last Updated By]={4} WHERE [Order ID] = {5}",
                                           dealerID, orderDate, dtp_Order_Date.Value.Date, cmb_Time.SelectedIndex, empID, this.orderID);
            }
            else
            {
                orderQuery =
                    string.Format("INSERT INTO Orders([Dealer ID],[Order Date], [Serviced Employee ID], [Required Date],[Required Time]) VALUES ({0},#{1}#,{2},#{3}#,{4})",
                                  dealerID, orderDate, empID, dtp_Order_Date.Value.Date, cmb_Time.SelectedIndex);
            }
            var rdr = DatabaseHelper.ExecuteQuery(orderQuery);

            DataTable orderTable = DatabaseHelper.GetTable("Orders", null, null, true);

            DataTable productTable = DatabaseHelper.GetTable("Products", null, null, true);
            int       orderID      = -1;

            if (btn_Place_Order.Text.Contains("Update"))
            {
                orderID = this.orderID;
            }
            else
            {
                orderID = int.Parse(orderTable.Rows[orderTable.Rows.Count - 1]["Order ID"].ToString());
            }

            List <string> productNames = new List <string>();

            foreach (ProductItem item in flw_Products.Controls)
            {
                string query = "";
                if (btn_Place_Order.Text.Contains("Update"))
                {
                    DataTable     tableCurrentProducts   = DatabaseHelper.GetTable(null, null, "SELECT [Product Name] FROM [Order Details] WHERE [Order ID]=" + orderID);
                    List <string> productItemsKappaPride = new List <string>();
                    foreach (DataRow rowowoow in tableCurrentProducts.Rows)
                    {
                        productItemsKappaPride.Add(rowowoow["Product Name"].ToString());
                    }
                    if (!productItemsKappaPride.Contains(item.comboBox2.SelectedItem))
                    {
                        query = string.Format(
                            "INSERT INTO [Order Details]([Order ID], [Product Name], Quantity) VALUES " +
                            "({0},'{1}', {2})", orderID, item.comboBox2.SelectedItem,
                            item.numericUpDown1.Value);
                    }
                    else
                    {
                        query = string.Format("UPDATE [Order Details] SET [Quantity]={0} WHERE [Order ID]={1} AND [Product Name]='{2}'",
                                              item.numericUpDown1.Value, orderID, item.comboBox2.SelectedItem);
                    }
                }
                else
                {
                    query =
                        string.Format(
                            "INSERT INTO [Order Details]([Order ID], [Product Name], Quantity) VALUES " +
                            "({0},'{1}', {2})", orderID, item.comboBox2.SelectedItem,
                            item.numericUpDown1.Value);
                }
                OleDbDataReader reader = DatabaseHelper.ExecuteQuery(query);
                productNames.Add(item.comboBox2.SelectedItem.ToString());
            }
            string    querya = "SELECT * FROM [Order Details] WHERE [Order ID]=" + orderID;
            DataTable dtb    = DatabaseHelper.GetTable(null, null, querya);

            foreach (DataRow productRow in dtb.Rows)
            {
                string productName = productRow["Product Name"].ToString();
                if (!productNames.Contains(productName))
                {
                    DatabaseHelper.ExecuteQuery("DELETE FROM [Order Details] WHERE [OrderDetails ID] =" + productRow["OrderDetails ID"].ToString());
                }
            }
            MessageBox.Show("Order Processed Succesfully");
        }
Beispiel #3
0
        private void frm_AddOrder_Load(object sender, EventArgs e)
        {
            cmb_Time.SelectedIndex = 0;
            table = DatabaseHelper.GetTable(null, null, "SELECT [Dealer ID], [First Name], [Last Name], Company FROM Dealer INNER JOIN Person ON Dealer.[Person ID] = Person.[Person ID]");
            List <string> list = new List <string>();

            for (int index = 0; index < table.Rows.Count; ++index)
            {
                string str1 = table.Rows[index]["First Name"].ToString();
                string str2 = table.Rows[index]["Last Name"].ToString();
                string str3 = table.Rows[index]["Company"].ToString();
                list.Add(str1 + " " + str2 + " (" + str3 + ")");
                dealerDict.Add(list[index], int.Parse(table.Rows[index]["Dealer ID"].ToString()));
            }
            this.cmb_Dealer.DataSource = list;
            DataRow dataRow = LoggedInEmployee.EmployeeInformation();

            this.lbl_servicedEmployee.Text = dataRow["First Name"].ToString() + " " + dataRow["Last Name"].ToString() + " (You)";
            if (orderID >= 0)
            {
                Text = "Updating Order #" + orderID;
                btn_Place_Order.Text = "Update Order";
                if (updateRow == null)
                {
                    MessageBox.Show("Lol u need a queery row tho");
                    return;
                }

                string dealerValue = dealerDict.FirstOrDefault(x =>
                {
                    string name    = updateRow.Cells["Dealer Name"].Value.ToString();
                    string company = updateRow.Cells["Company"].Value.ToString();
                    return(x.Key.Contains(name) && x.Key.Contains(company));
                }
                                                               ).Key;
                if (dealerValue != null && cmb_Dealer.Items.Contains(dealerValue))
                {
                    cmb_Dealer.SelectedItem = dealerValue;
                }

                cmb_Time.SelectedItem = updateRow.Cells["Required"].Value.ToString();
                string lastUpdatedBy = updateRow.Cells["Last Updated By"].Value.ToString();
                if (!string.IsNullOrEmpty(lastUpdatedBy) && int.Parse(lastUpdatedBy) > 0)
                {
                    DataRow lastUpdatedPersonRow = DatabaseHelper.GetPerson(int.Parse(lastUpdatedBy));
                    string  Name = lastUpdatedPersonRow["First Name"].ToString() + " " + lastUpdatedPersonRow["Last Name"].ToString();
                    if (!string.IsNullOrEmpty(lastUpdatedBy))
                    {
                        lbl_servicedEmployee.Text += " // Last Updated by " + Name;
                    }
                }
                foreach (DataRow detailRow in DatabaseHelper.GetTable("Order Details", null, null, true).Rows)
                {
                    if (detailRow["Order ID"].ToString() == orderID.ToString())
                    {
                        string productName = detailRow["Product Name"].ToString();
                        int    Quantity    = int.Parse(detailRow["Quantity"].ToString());
                        AddProduct(productName, Quantity);
                    }
                }
            }
        }