private void AddItem()
        {
            Item   item = new Item();
            string orderID;

            item.ItemDescription = BoxName.Text;
            item.Location        = BoxLocation.Text;
            item.Material        = !BoxTool.Checked;
            item.QuantityStored  = int.Parse(BoxQuantity.Text);
            item.UnitValue       = float.Parse(BoxValue.Text);
            item.SupplierID      = (int)comboSuppliers.SelectedValue;
            if (BoxOrder.Checked)
            {
                orderID = BoxOrderNum.Text;
            }
            else
            {
                orderID = null;
            }
            if (newSupplier)
            {
                Supplier supplier = new Supplier();
                supplier.Name    = BoxSupplierName.Text;
                supplier.Phone   = BoxSupplierNumber.Text;
                supplier.Website = BoxSupplierWebsite.Text;
                DatabaseTools.addItem(item, true, supplier, BoxOrderNum.Text);
            }
            else
            {
                DatabaseTools.addItem(item, false, null, BoxOrderNum.Text);
            }
            instance.Dispose();
            MessageBox.Show("ITEM ADDED SUCCESFULLY");
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (BoxName.Text == "")
            {
                MessageBox.Show("Name/description cannot be empty!");
            }
            else
            {
                if (BoxOrder.Checked)
                {
                    int orderValidity = DatabaseTools.AddOrder(BoxOrderNum.Text, dateOrder.Value, jobID);
                    switch (orderValidity)
                    {
                    case 2:
                        //Order didn't exist but has been added
                        AddItem();
                        break;

                    case 1:
                        //Order exists but date/job don't match
                        MessageBox.Show("Order number exists but input date and/or job does not match what is stored!");
                        break;

                    case 0:
                        //Order exists
                        AddItem();
                        break;
                    }
                }
                else
                {
                    AddItem();
                }
            }
        }
Ejemplo n.º 3
0
 private void MainUserControl_Load(object sender, EventArgs e)
 {
     isAdmin = bool.Parse(DatabaseTools.GetValueFromKey("Employee", "Is Manager?", Main.userID, "Employee Code"));
     if (isAdmin)
     {
         panelManagers.Show();
     }
     else
     {
         panelManagers.Hide();
     }
 }
        public AddItemUserControl()
        {
            InitializeComponent();
            DataTable suppliers = DatabaseTools.GetAllValues("SupplierID, [Supplier Name]", "Supplier");
            DataRow   other     = suppliers.NewRow();

            other["SupplierID"]    = -1;
            other["Supplier Name"] = "Other";
            suppliers.Rows.Add(other);
            comboSuppliers.DisplayMember = "Supplier Name";
            comboSuppliers.ValueMember   = "SupplierID";
            comboSuppliers.DataSource    = suppliers;
        }
Ejemplo n.º 5
0
 private void ButtonSubmit_Click(object sender, EventArgs e)
 {
     if (DatabaseTools.IsInDatabase("Employee", "Employee Code", BoxID.Text))
     {
         LabelError.Hide();
         userID = BoxID.Text;
         Main main = new Main(userID);
         main.Show();
         this.Hide();
         BoxID.Clear();
     }
     else
     {
         LabelError.Show();
     }
 }
Ejemplo n.º 6
0
        private void Main_Load(object sender, EventArgs e)
        {
            PanelContent.Controls.Add(MainUserControl.Instance);
            MainUserControl.Instance.Dock = DockStyle.Fill;
            MainUserControl.Instance.BringToFront();

            name           = DatabaseTools.GetValueFromKey("Employee", "Employee Name", userID, "Employee Code");
            LabelName.Text = "Welcome, " + name;

            MainUserControl.Instance.SearchStarted     += new EventHandler(OpenSearchResults);
            MainUserControl.Instance.SuppliersView     += new EventHandler(ViewSuppliers);
            MainUserControl.Instance.EditsView         += new EventHandler(ViewEdits);
            MainUserControl.Instance.AddOpen           += new EventHandler(OpenAdd);
            SearchResultsUserControl.Instance.AddOpen  += MainUserControl.Instance.AddOpen;
            SearchResultsUserControl.Instance.EditOpen += new EventHandler(OpenEdit);

            setEvents(this);

            actionStack.Push(actions.Main);
        }
Ejemplo n.º 7
0
        private static void outputReport()
        {
            int    row = 0, col = 0;
            string formatString;

            Excel.Application excelApp = new Excel.Application();
            if (excelApp == null)
            {
                MessageBox.Show("WANRNING!\n<< TRIED TO CREATE REPORT BUT EXCEL IS NOT INSTALLED! >>");
            }
            else
            {
                Excel.Workbook  workbook      = excelApp.Workbooks.Open(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Reports.xlsx");
                Excel.Worksheet DataWorksheet = workbook.Worksheets[workbook.Worksheets.Count];
                try
                {
                    DataWorksheet.Name = "Data";
                    DataTable data = DatabaseTools.getReportData();
                    foreach (DataColumn dataColumn in data.Columns)
                    {
                        DataWorksheet.Range["A1"].Offset[0, col].Value = dataColumn.ColumnName;
                        switch (dataColumn.DataType.ToString())
                        {
                        case "System.Decimal":
                            formatString = "_-[$£-en-GB]* #,##0.00_-;-[$£-en-GB]* #,##0.00_-;_-[$£-en-GB]* \" - \"??_-;_-@_-";
                            break;

                        case "System.Int32":
                            formatString = "0";
                            break;

                        case "System.DateTime":
                            formatString = "dd/mm/yyyy";
                            break;

                        default:
                            formatString = "@";
                            break;
                        }
                        DataWorksheet.Range["A1"].Offset[0, col].EntireColumn.NumberFormat = formatString;
                        col++;
                    }
                    row = 2;
                    foreach (DataRow dataRow in data.Rows)
                    {
                        for (col = 0; col < data.Columns.Count; col++)
                        {
                            DataWorksheet.Cells[row, col + 1] = dataRow[col] == DBNull.Value ? string.Empty : dataRow[col].ToString();
                        }
                        row++;
                    }
                    DataWorksheet.Columns.AutoFit();
                    Excel.Worksheet PivotSheet = workbook.Worksheets.Add();
                    PivotSheet.Name = DateTime.Now.ToLongDateString();

                    Excel.Range      dataRange = DataWorksheet.UsedRange;
                    Excel.PivotCache cache     = workbook.PivotCaches().Create(Excel.XlPivotTableSourceType.xlDatabase, dataRange);

                    Excel.PivotCaches pivotCaches = workbook.PivotCaches();
                    pivotCaches.Create(Excel.XlPivotTableSourceType.xlDatabase, dataRange).CreatePivotTable(PivotSheet.Cells[1, 1], "Table");
                    Excel.PivotTable pivotTable = PivotSheet.PivotTables("Table");

                    Excel.PivotField field = pivotTable.PivotFields("Job Name");
                    field.Orientation      = Excel.XlPivotFieldOrientation.xlRowField;
                    field.LayoutCompactRow = false;
                    field.Subtotals        = new bool[12] {
                        false, false, false, false, false, false, false, false, false, false, false, false
                    };

                    field             = pivotTable.PivotFields("Order Number");
                    field.Orientation = Excel.XlPivotFieldOrientation.xlRowField;
                    field.Subtotals   = new bool[12] {
                        false, false, false, false, false, false, false, false, false, false, false, false
                    };

                    field             = pivotTable.PivotFields("Total Value");
                    field.Orientation = Excel.XlPivotFieldOrientation.xlDataField;
                    field.Caption     = "Total Values";

                    field             = pivotTable.PivotFields("Average Value");
                    field.Orientation = Excel.XlPivotFieldOrientation.xlDataField;
                    field.Caption     = "Average Values";

                    PivotSheet.UsedRange.Columns.AutoFit();

                    pivotTable.MergeLabels   = true;
                    pivotTable.ShowValuesRow = false;

                    pivotTable.ColumnGrand = false;
                    pivotTable.RowGrand    = false;
                }
                catch (Exception e)
                {
                    MessageBox.Show(string.Format(e.Message + "\n" + e.InnerException + "\n" + e.Data));
                }
                finally
                {
                    workbook.Save();
                    workbook.Close();
                    excelApp.Quit();
                }
            }
        }