예제 #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            StationId = wasteTrackerStationsComboBox.SelectedIndex;
            MenuItem  = menuItemTextBox.Text;
            Par       = decimal.Parse(parTextBox.Text);
            IsActive  = true;
            UoM       = uomCombobox.SelectedValue.ToString();

            SandboxDataSetTableAdapters.WasteTrackerDBTableAdapter da = new SandboxDataSetTableAdapters.WasteTrackerDBTableAdapter();

            try
            {
                //Custom Insert Statement to insert new menu items into MenuItems Table
                da.InsertQuery(StationId, MenuItem, Par, UoM, IsActive);
                BIMessageBox.Show("New Menu Item Added");
            }
            catch (Exception ex)
            {
                BIMessageBox.Show("Oops there was a problem, please contact Business Intelligence \n" + ex.Message);
            }
            #endregion
            #region Reset Combobox to 0 and clear TextBoxes
            //clear textbox
            wasteTrackerStationsComboBox.SelectedIndex = 0;
            menuItemTextBox.Clear();
            parTextBox.Clear();
            uomCombobox.SelectedIndex = 0;
        }
예제 #2
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            SandboxDataSet ds = ((SandboxDataSet)(FindResource("sandboxDataSet")));

            SandboxDataSetTableAdapters.WasteTrackerDBTableAdapter da = new SandboxDataSetTableAdapters.WasteTrackerDBTableAdapter();

            DateTime?Date = dateDatePicker.SelectedDate;

            SqlConnection conn = ConnectionHelper.GetConn();

            conn.Open();

            //iterate over datagrid, update values
            foreach (DataRow dr in ds.WasteTrackerDB.Rows)
            {
                string sqlString = "UPDATE WasteTrackerDB SET LeftOver = @LeftOver, Ordered = @Ordered WHERE MenuItem = @MenuItem AND Date = @Date";
                Cmd = new SqlCommand(sqlString, conn);
                Cmd.Parameters.AddWithValue("@MenuItem", dr[2]);
                Cmd.Parameters.AddWithValue("@LeftOver", dr[3]);
                Cmd.Parameters.AddWithValue("@Ordered", dr[8]);
                Cmd.Parameters.AddWithValue("@Date", Date);
                Cmd.ExecuteNonQuery();
            }
            BIMessageBox.Show("Leftover values have been updated");
            conn.Close();
        }
예제 #3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            SandboxDataSet ds = ((SandboxDataSet)(FindResource("sandboxDataSet")));

            try
            {
                SqlConnection conn = ConnectionHelper.GetConn();
                conn.Open();

                //iterate over datagrid, update values
                foreach (DataRow dr in ds.MenuItems.Rows)
                {
                    string sqlString = "UPDATE MenuItems SET Par = @Par, UoM = @UoM, IsActive = @IsActive WHERE MenuItem = @MenuItem AND @StationId = StationId";
                    Cmd = new SqlCommand(sqlString, conn);
                    Cmd.Parameters.AddWithValue("@StationId", dr[1]);
                    Cmd.Parameters.AddWithValue("@MenuItem", dr[2]);
                    Cmd.Parameters.AddWithValue("@Par", dr[3]);
                    Cmd.Parameters.AddWithValue("@UoM", dr[4]);
                    Cmd.Parameters.AddWithValue("@IsActive", dr[5]);

                    //get par cell for data validation
                    string  _par = dr[3].ToString();
                    decimal par;
                    par = decimal.Parse(_par);

                    if (par < 0)
                    {
                        BIMessageBox.Show("Please a positive number for the Par Amount.");
                        return;
                    }
                    else
                    {
                        Cmd.ExecuteNonQuery();
                    }
                }
                conn.Close();
                BIMessageBox.Show("Par level has been updated.");
            }
            catch (Exception ex)
            {
                BIMessageBox.Show("Oops there was a problem, please contact Business Intelligence \n" + ex);
            }
        }
예제 #4
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            SandboxDataSet ds = ((SandboxDataSet)(FindResource("sandboxDataSet")));

            SqlConnection conn = ConnectionHelper.GetConn();

            conn.Open();

            foreach (DataRow dr in ds.MenuItems.Rows)
            {
                string sqlString = "UPDATE MenuItems SET IsActive = @IsActive WHERE MenuItem = @MenuItem";
                Cmd = new SqlCommand(sqlString, conn);
                Cmd.Parameters.AddWithValue("@MenuItem", dr[2]);
                Cmd.Parameters.AddWithValue("@IsActive", dr[5]);
                Cmd.ExecuteNonQuery();
            }
            BIMessageBox.Show("Item is Active Again");
            conn.Close();
        }
예제 #5
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            SandboxDataSet ds = ((SandboxDataSet)(FindResource("sandboxDataSet")));

            SandboxDataSetTableAdapters.WasteTrackerDBTableAdapter da = new SandboxDataSetTableAdapters.WasteTrackerDBTableAdapter();
            DateTime?Date = dateDatePicker.SelectedDate;

            //if there is a date selected
            if (Date != null)
            {
                try
                {
                    //use SQL command to insert into DB
                    SqlConnection conn = ConnectionHelper.GetConn();
                    conn.Open();
                    decimal LeftOver;
                    decimal Ordered;

                    //iterate over each row of DataGrid, get values of each cell, and insert into DB
                    foreach (DataRow dr in ds.WasteTrackerDB.Rows)
                    {
                        string sqlString = "INSERT INTO WasteTrackerDB VALUES (@StationId, @MenuItem, @LeftOver, @Par, @UoM, @Date, @IsActive, @Ordered, @Notes)";
                        Cmd = new SqlCommand(sqlString, conn);
                        Cmd.Parameters.AddWithValue("@StationId", dr[1]);
                        Cmd.Parameters.AddWithValue("@MenuItem", dr[2]);
                        Cmd.Parameters.AddWithValue("@LeftOver", dr[3]);
                        Cmd.Parameters.AddWithValue("@Par", dr[4]);
                        Cmd.Parameters.AddWithValue("@UoM", dr[5]);
                        Cmd.Parameters.AddWithValue("@Date", Date);
                        Cmd.Parameters.AddWithValue("@IsActive", 1);
                        Cmd.Parameters.AddWithValue("@Ordered", dr[8]);
                        Cmd.Parameters.AddWithValue("@Notes", dr[12]);

                        string leftOver = dr[3].ToString();
                        string ordered  = dr[8].ToString();

                        if (leftOver == "" || ordered == "")
                        {
                            BIMessageBox.Show("Please enter a valid number between 0 and 99999999");
                            return;
                        }
                        else
                        {
                            LeftOver = decimal.Parse(leftOver);
                            Ordered  = decimal.Parse(ordered);
                            if (LeftOver < 0 || Ordered < 0 || LeftOver == -1 || Ordered == -1)
                            {
                                BIMessageBox.Show("Please enter a valid number between 0 and 9999999999");
                                return;
                            }
                            else
                            {
                                Cmd.ExecuteNonQuery();
                            }
                        }
                    }
                    BIMessageBox.Show("Leftover values have been added");
                    conn.Close();
                }
                catch (Exception ex)
                {
                    BIMessageBox.Show("Oops there was a problem, please contact Business Intelligence \n" + ex);
                }
            }
            //oops there was no date selected
            else
            {
                BIMessageBox.Show("Please Enter a Date");
                return;
            }
        }