示例#1
0
 /// <summary>
 /// Inserts a new item into the database.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnAddItems_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         //Verify none of the item codes are currently being used by an invoice
         foreach (var element in Items)
         {
             if (element.ItemCode == txtItemCode.Text)
             {
                 MessageBox.Show("You cannot add this item, it is already exists", "Cannot add item", MessageBoxButton.OK, MessageBoxImage.Warning);
                 return;
             }
         }
         if (string.IsNullOrWhiteSpace(txtItemCode.Text) || string.IsNullOrWhiteSpace(txtItemDesc.Text) || string.IsNullOrWhiteSpace(txtItemCost.Text))
         {
             MessageBox.Show("Please enter information for the item.", "Cannot add item", MessageBoxButton.OK, MessageBoxImage.Warning);
             return;
         }
         //Make sure an item is selected
         else if (!string.IsNullOrWhiteSpace(txtItemCode.Text))
         {
             //Creates a new item in the database.
             DA.ExecuteNonQuery(itemsSQL.CreateItem(txtItemCode.Text, txtItemDesc.Text, txtItemCost.Text));
             FillBox();
         }
     }
     catch (System.Exception ex)
     {
         HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name,
                     MethodInfo.GetCurrentMethod().Name, ex.Message);
     }
 }
示例#2
0
        internal void SaveInvoice()
        {
            DataSet ds = new DataSet();

            clsData = new clsDataAccess();
            string sSQL;

            if (CurrentInvoice.Items != null && CurrentInvoice.Items.Count > 0)
            {
                if (CurrentInvoice.InvoiceNumber == null)
                {
                    sSQL = String.Format(clsMainSQL.SaveNewInvoice, CurrentInvoice.InvoiceDate, CurrentInvoice.Cost);
                    int incId = clsData.InsertNonQuery(sSQL);
                    CurrentInvoice.InvoiceNumber = incId.ToString();
                }
                else
                {
                    sSQL = String.Format(clsMainSQL.SaveInvoice, CurrentInvoice.InvoiceDate.ToShortDateString(), CurrentInvoice.Cost.ToString(), CurrentInvoice.InvoiceNumber);
                    clsData.ExecuteNonQuery(sSQL);
                }

                sSQL = String.Format(clsMainSQL.DeleteLineItems, CurrentInvoice.InvoiceNumber);
                clsData.ExecuteNonQuery(sSQL);
                int i = 1;
                foreach (Item row in CurrentInvoice.Items)
                {
                    sSQL = String.Format(clsMainSQL.SaveLineItems, CurrentInvoice.InvoiceNumber, i, row.Code);
                    clsData.ExecuteNonQuery(sSQL);
                    i++;
                }
            }
        }
示例#3
0
        /// <summary>
        /// Removes a item from the itemDesc table if that item is not in use.
        /// If that item is in a invoice. this will show a message box of all invoices it's using.
        /// </summary>
        /// <param name="itemCode"></param>
        /// <returns></returns>
        public string DeleteItem(string itemCode)
        {
            try
            {
                if (DoesItemExist(itemCode))
                {
                    int     count        = 0;
                    DataSet usedInvoices = data.ExecuteSQLStatement(clsItemsSQL.InvoicesBeingUsed(itemCode), ref count);

                    if (count == 0)
                    {
                        data.ExecuteNonQuery(clsItemsSQL.ItemDeleteDescSQL(itemCode));
                        return("Item Deleted");
                    }
                    else
                    {
                        string returnMessage = "Invoice Id: \r";
                        for (int i = 0; i < count; i++)
                        {
                            returnMessage += usedInvoices.Tables[0].Rows[i][0] + "\r";
                        }
                        MessageBox.Show(returnMessage, "Item in use by invoices");
                        return("Item not deleted");
                    }
                }
                return("Error! Item does not exist");
            }
            catch (System.Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }
        }
示例#4
0
        /// <summary>
        /// Adds an invoice to the data base
        /// </summary>
        /// <param name="invoiceDate">The date to be added with the new invoice</param>
        /// <param name="invoiceItems">The list of items to be added and associated with the new invoice</param>
        public static void AddInvoice(DateTime invoiceDate, List <string> invoiceItems)
        {
            try
            {
                int           i         = 0;                                                                  // Temp ref integer, unused but required
                List <string> itemCodes = new List <string>();                                                // The list of item codes to be inserted and associated with the invoice
                decimal       totalCost = 0;                                                                  // Temp cost to be calculated and inserted

                foreach (var item in invoiceItems)                                                            // Each row (each individual item) in the list
                {
                    DataSet ds = _data.ExecuteSQLStatement(clsMainSQL.GetItemDescRowByItemDesc(item), ref i); // The DataSet that holds the row item
                    itemCodes.Add(ds.Tables[0].Rows[0][0].ToString());
                    totalCost += Convert.ToDecimal(ds.Tables[0].Rows[0][2]);
                }
                _data.ExecuteNonQuery(clsMainSQL.InsertInvoice(invoiceDate, totalCost));       // Insert the new invoice

                string newInvoiceNum = _data.ExecuteScalarSQL(clsMainSQL.GetNewestInvoiceNum); // The new invoice num inserted

                int lineNum = 0;                                                               // The temp line num for the line item
                foreach (var item in itemCodes)                                                // Each line item associated with the new invoice
                {
                    _data.ExecuteScalarSQL(clsMainSQL.InsertLineItems(newInvoiceNum, ++lineNum, item));
                }
            }
            catch
            {
                throw new Exception("Could not add new invoice");
            }
        }
        /// <summary>
        /// Method to update an Item
        /// </summary>
        /// <param name="sCode">Item Code of Item to be updated</param>
        /// <param name="sDesc">New Item Description</param>
        /// <param name="sCost">New Item Cost</param>
        /// <returns>Bool; True if cost is valid, false otherwise</returns>
        public bool updateItem(string sCode, string sDesc, string sCost)
        {
            try
            {
                int  iCost;
                int  iRet;
                bool validCost = false;

                validCost = Int32.TryParse(sCost, out iCost);

                if (validCost)
                {
                    string sSQL = clsSQL.UpdateItem(sCode, sDesc, iCost);
                    iRet = clsDA.ExecuteNonQuery(sSQL);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." +
                                    MethodInfo.GetCurrentMethod().Name + " ->" + ex.Message);
            }
        }
示例#6
0
        /// <summary>
        ///     Deletes the invoice from the database for the passed in Id
        /// </summary>
        /// <param name="invoiceId"></param>
        /// <returns></returns>
        public int DeleteInvoice(int invoiceId)
        {
            var sql = $"Delete from Invoices where InvoiceNum = {invoiceId}";

            var result = _dataAccess.ExecuteNonQuery(sql);

            return(result);
        }
 /// <summary>
 /// Inserts card Name and Cost into DataBase
 /// </summary>
 /// <param name="cardName"></param>
 /// <param name="cardCost"></param>
 public void InsertCard(string cardName, double cardCost)
 {
     try
     {
         data.ExecuteNonQuery(sql.SQLAddRow(cardName, cardCost));
     }catch (Exception ex)
     {
         throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodBase.GetCurrentMethod().Name + " -> " + ex.Message);
     }
 }
示例#8
0
 /// <summary>
 /// Insert a new item to database table ItemDesc
 /// </summary>
 /// <param name="itemCode">Anew item code to be inserted to table </param>
 /// <param name="itemDesc">Anew item desc to be inserted to table</param>
 /// <param name="itemCost">Anew item cost to be inserted to table</param>
 public static void AddItem(string itemCode, string itemDesc, string itemCost)
 {
     try
     {
         _data.ExecuteNonQuery(clsItemsSQL.InsertItem(itemCode, itemDesc, itemCost)); // Insert the new item
     }
     catch (Exception e)
     {
         throw new Exception("Could not add item " + itemDesc);
     }
 }
示例#9
0
 /// <summary>
 /// method that will update the cusstomers seat. takes in a steat number, passenger id, and flight ID
 /// </summary>
 /// <param name="SSeat"></param>
 /// <param name="ID"></param>
 /// <param name="SFlight"></param>
 public void ChangePassengerSeat(string SSeat, string ID, string SFlight)
 {
     try
     {
         string sql = "UPDATE Flight_Passenger_Link SET Seat_Number = " + SSeat + " WHERE Passenger_ID = " + ID + " AND Flight_ID = " + SFlight;
         _dataAccess.ExecuteNonQuery(string.Format(sql, SSeat, ID, SFlight));
     }
     catch (Exception ex)
     {
         throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
     }
 }
 /// <summary>
 /// This adds a new invoice into the database. It will not have any items on it when first created.
 /// </summary>
 /// <param name="invoiceDateTime">The date of the invoice (Defaults to today)</param>
 /// <returns>SQL string for adding an invoice</returns>
 public void AddInvoice(string invoiceDateTime)
 {
     try
     {
         string sSQL = "INSERT INTO Invoices(InvoiceDate) VALUES('" + invoiceDateTime + "');";
         db.ExecuteNonQuery(sSQL);
     }
     catch (Exception ex)
     {
         throw new Exception("Unable to add invoice." + ex.ToString());
     }
 }
示例#11
0
 /// <summary>
 /// This class should update the Item Description
 /// </summary>
 /// <param name="ItemDescInUpdate"></param>
 /// <param name="ItemCodeInUpdate"></param>
 public void UpdateItemDesc(string ItemDescInUpdate, string ItemCodeInUpdate)
 {
     try
     {
         db.ExecuteNonQuery(Query.UpdateItemDesc(ItemDescInUpdate, ItemCodeInUpdate));
     }
     catch (Exception ex)
     {
         throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType + "." +
                             MethodInfo.GetCurrentMethod().Name + "->" + ex.Message);
     }
 }
示例#12
0
 /// <summary>
 /// addItem()
 ///
 /// A SQL statement that takes the string cost and description of an item
 /// and creates a new entry in the database with those values.
 /// </summary>
 /// <param name="cost">The cost of the item.</param>
 /// <param name="description">The description of the item.</param>
 /// <returns>An integer that indicates how many lines were added to the database. A value different than 1 indicates an error</returns>
 public static int addItem(string cost, string description)
 {
     // Note: These values will be validated in the calling method inside clsItemLogic.
     try
     {
         return(db.ExecuteNonQuery("INSERT INTO ItemDesc (Cost, ItemDesc) " +
                                   "VALUES (" + cost + ", " + description + ")"));
     }
     catch (Exception ex)
     {
         throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
     }
 }
示例#13
0
        internal void DeleteInvoice()
        {
            DataSet ds = new DataSet();

            clsData = new clsDataAccess();
            string sSQL;

            sSQL = String.Format(clsMainSQL.DeleteInvoice, CurrentInvoice.InvoiceNumber);
            clsData.ExecuteNonQuery(sSQL);

            sSQL = String.Format(clsMainSQL.DeleteLineItems, CurrentInvoice.InvoiceNumber);
            clsData.ExecuteNonQuery(sSQL);
        }
示例#14
0
        /// <summary>
        /// deletes an item in the database if that item is not in an invoice
        /// </summary>
        /// <param name="code">the items code</param>
        /// <returns>if something was deleted</returns>
        public bool DeleteItem(string code)
        {
            try
            {
                int     iRet = 0;
                DataSet ds   = new DataSet();
                try
                {
                    ds = data.ExecuteSQLStatement(SQL.InAInvoice(code), ref iRet);
                }
                catch (Exception ex)
                {
                    throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
                }

                if (iRet == 0)
                {
                    try
                    {
                        int del = data.ExecuteNonQuery(SQL.DeleteItem(code));
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
                    }
                    wnd.ShowError("Deleted");
                    return(true);
                }
                else
                {
                    string sError = "This Item is in Invoice ";
                    bool   bFirst = true;
                    for (int i = 0; i < iRet; i++)
                    {
                        if (!bFirst)
                        {
                            sError += ", ";
                        }

                        sError += ds.Tables[0].Rows[i][0].ToString();
                    }

                    wnd.ShowError(sError);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }
        }
示例#15
0
        /// <summary>
        /// Insert New Item into ItemDesc table
        /// </summary>
        /// <param name="code"></param>
        /// <param name="desc"></param>
        /// <param name="cost"></param>
        public void InsertNewItem(char code, string desc, string cost)
        {
            try
            {
                //Sql statement
                string insert = "INSERT INTO ItemDesc(ItemCode, ItemDesc, Cost) VALUES('" + code + "', '" + desc + "', '" + cost + "')";

                DataAccess.ExecuteNonQuery(insert);
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " --> " + ex.Message);
            }
        }
示例#16
0
        /// <summary>
        /// Updates the SQL and return the ourput.
        /// </summary>
        /// <param name="ssql"></param>
        public int updateItem(int ID, string Set)
        {
            try
            {
                string sSQL;

                sSQL = "Update Equipment " + Set + "Where ID ='" + ID + "'";

                return(db.ExecuteNonQuery(sSQL));
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }
        }
示例#17
0
        /// <summary>
        /// Adds an item to the database.
        /// </summary>
        /// <param name="itemcode"></param>
        /// <param name="itemdesc"></param>
        /// <param name="cost"></param>
        public void AddNewItem(string itemcode, string itemdesc, string cost)
        {
            try
            {
                string sSQL = "INSERT INTO ItemDesc (ItemCode, ItemDesc, Cost) VALUES ('" + itemcode + "', '" +
                              itemdesc + "', '" + cost + "')";

                Data.ExecuteNonQuery(sSQL);
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." +
                                    MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }
        }
示例#18
0
        /// <summary>
        /// this deletes an item from the db
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public int DeleteItem(int code)
        {
            var sql    = $"Delete from ItemDesc where ItemCode = {code}";
            var result = _dba.ExecuteNonQuery(sql);

            return(result);
        }
 /// <summary>
 /// Adding a new item
 /// </summary>
 /// <param name="sItemDesc"></param>
 /// <param name="dCost"></param>
 /// <returns></returns>
 public bool AddSelectedItem(string sItemCode, string sItemDesc, string sCost)
 {
     try
     {
         string sSql         = "INSERT INTO ItemDesc(ItemCode, ItemDesc, Cost) VALUES ('" + sItemCode + "', '" + sItemDesc + "', '" + sCost + "')";
         int    affectedRows = da.ExecuteNonQuery(sSql);
         //If no rows are affected, something went wrong. Otherwise, it worked
         return(affectedRows > 0);
     }
     catch (Exception ex)
     {
         System.IO.File.AppendAllText("C:\\Error.txt", Environment.NewLine +
                                      "HandleError Exception: " + ex.Message);
         // return empty string because something is wrong
         return(false);
     }
 }
示例#20
0
        /// <summary>
        /// Update Query to update Invoice Items
        /// </summary>
        /// <param name="invoice"></param>
        public void UpdateInvoiceItems(Invoice invoice)
        {
            try
            {
                //Need to delete Lines from Invoice first, then update
                //Sql Statement
                string delete = "DELETE FROM LineItems WHERE InvoiceNum = " + invoice.InvoiceNumber;

                DataAccess.ExecuteNonQuery(delete);

                //Need to loop through Invoice items and add new rows
                int i = 1;// integer representing Line Item Number
                foreach (Item item in invoice.InvoiceItems)
                {
                    string Sql = "INSERT INTO LineItems(InvoiceNum, LineItemNum, ItemCode) VALUES ('"
                                 + invoice.InvoiceNumber + "', '" + i + "', '" + item.ItemCode + "')";
                    DataAccess.ExecuteNonQuery(Sql);
                    i++;//increment LineItemNumber
                }
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " --> " + ex.Message);
            }
        }
示例#21
0
 /// <summary>
 /// Delete the invoice corresponding to the given invoice ID.
 /// </summary>
 /// <param name="invoiceID">The ID corresponding with the invoice to delete.</param>
 public static void DeleteInvoice(int invoiceID)
 {
     try
     {
         // First, delete the line items associated with the Invoice.
         clsDataAccess db   = new clsDataAccess();
         string        sSQL = clsMainSQL.DeleteLineItemsByInvoiceID(invoiceID);
         db.ExecuteNonQuery(sSQL);
         // Next, delete the Invoice proper.
         sSQL = clsMainSQL.DeleteInvoiceByID(invoiceID);
         db.ExecuteNonQuery(sSQL);
     }
     catch (Exception ex)
     {
         throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "."
                             + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
     }
 }
示例#22
0
        /// <summary>
        /// Adds a new invoice to the database,
        /// and sets the generated invoiceNum
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public void AddNewInvoice(Invoice inv)
        {
            try
            {
                DataAccess.ExecuteNonQuery(DataSQL.InsertInvoice(inv.InvoiceDate, 0));

                //gets the invoice num and sets the property on the object
                if (int.TryParse(DataAccess.ExecuteScalarSQL(DataSQL.SelectLatestInvoiceNum()), out int result))
                {
                    inv.InvoiceNum = result;
                }
            }
            catch (Exception ex)
            {
                //Throw a custom-trace exception
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." +
                                    MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }
        }
示例#23
0
 /// <summary>
 /// Saves all the line items for an invoice. Expected to have all line items removed previously if invoice exists
 /// </summary>
 /// <param name="invoiceID">Invoice number to be saved for the line items</param>
 /// <param name="lineItems">Items to be saved to the invoice</param>
 /// <returns>Boolean of if all items were saved or not</returns>
 public bool SaveAllLineItems(string invoiceID, List <clsItemDescObj> lineItems)
 {
     try
     {
         int affectedRows = 0;
         for (int i = 1; i < lineItems.Count + 1; i++)
         {
             string sql = sqlProvider.InsertIndividualLineItemQuery(invoiceID, i, lineItems[i - 1]);
             affectedRows += da.ExecuteNonQuery(sql);
         }
         //If no rows are affected, something went wrong. Otherwise, it worked
         return(affectedRows > 0);
     }
     catch (Exception ex)
     {
         System.IO.File.AppendAllText("C:\\Error.txt", Environment.NewLine +
                                      "HandleError Exception: " + ex.Message);
         return(false);
     }
 }
 /// <summary>
 /// if item is new it will insert into the db, otherwise it will update it.
 /// </summary>
 /// <param name="item"></param>
 internal void upsert(Item item)
 {
     try
     {
         string command;
         if (item.newRecord)
         {
             command = sql.addNewItemDescription(item.ItemCode, item.ItemDesc, item.Cost);
         }
         else
         {
             command = sql.updateItemDescription(item.ItemDesc, item.Cost, item.ItemCode);
         }
         db.ExecuteNonQuery(command);
     }
     catch (Exception ex)
     {
         throw new Exception(ExceptionChain(MethodInfo.GetCurrentMethod(), ex));
     }
 }
示例#25
0
        /// <summary>
        /// Deletes a passenger from the passenger and flight_Passenger_Link table
        /// After a given id is given
        /// </summary>
        /// <param name="id">Passenger's id that is to be deleted</param>
        public void DeletePassenger(int id)
        {
            try
            {
                //deltes the from the link table first
                databaseQuery = "DELETE " +
                                "FROM Flight_Passenger_Link WHERE Passenger_ID = " + id + "";

                db.ExecuteNonQuery(databaseQuery);

                //then deletes the passenger
                databaseQuery = "DELETE " +
                                "FROM Passenger WHERE Passenger_ID = " + id + "";

                db.ExecuteNonQuery(databaseQuery);
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }
        }
        private void cmdAddItem_Click(object sender, RoutedEventArgs e)
        {
            boxListItem.Items.Clear();
            string sNewName = txtName.Text;
            string sNewDesc = txtDesc.Text;
            string sNewCost = txtCost.Text;

            string sSQL = "INSERT INTO ItemDesc( ItemCode, ItemDesc, Cost) VALUES('" + sNewName + "','" + sNewDesc + "','" + sNewCost + "')";

            db.ExecuteNonQuery(sSQL);
            UpdateBox();
        }
        /// <summary>
        /// Saves a working invoice to the Invoices database
        /// </summary>
        /// <param name="invoiceDate"></param>
        /// <param name="totalCost"></param>
        public void SaveInvoice(string invoiceDate, string totalCost)
        {
            try
            {
                string insertInvoiceSQL = sql.InsertInvoice(invoiceDate, totalCost);

                data.ExecuteNonQuery(insertInvoiceSQL);

                string invoiceNumber = data.ExecuteScalarSQL("SELECT MAX(InvoiceNum) FROM Invoices");
                selectedInvoice = Int32.Parse(invoiceNumber);

                string insertLineItemSQL;

                dgItems = new ObservableCollection <Items.clsItem>();

                // insert a line item for each item on the invoice
                for (int i = 0; i < WorkingInvoiceItems.Count; i++)
                {
                    dgItems.Add(WorkingInvoiceItems[i]);

                    insertLineItemSQL = sql.InsertLineItem(Int32.Parse(invoiceNumber), (i + 1), WorkingInvoiceItems[i].Code);
                    data.ExecuteNonQuery(insertLineItemSQL);
                }
            }
            catch (Exception ex)
            {
                //Just throw the exception
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." +
                                    MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }
        }
示例#28
0
 /// <summary>
 /// method to update an item with the outlined variables
 /// </summary>
 /// <param name="db"></param>
 /// <param name="code"></param>
 /// <param name="cost"></param>
 /// <param name="description"></param>
 public void Updateitem(clsDataAccess db, string code, float cost, string description)
 {
     try
     {
         sSQL = "Update ItemDesc Set ItemDesc = '" + description + "', Cost = " + cost + " where ItemCode = '" + code + "'";
         db.ExecuteNonQuery(sSQL);
     }
     catch (Exception ex)
     {
         throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." +
                             MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
     }
 }
示例#29
0
 /// <summary>
 /// method to execute an insert statement with the given variables
 /// </summary>
 /// <param name="db"></param>
 /// <param name="code"></param>
 /// <param name="cost"></param>
 /// <param name="description"></param>
 public void InsertItem(clsDataAccess db, string code, float cost, string description)
 {
     try
     {
         sSQL = "Insert into ItemDesc (ItemCode, ItemDesc, Cost) Values ('" + code + "', '" + description + "', " + cost + ")";
         db.ExecuteNonQuery(sSQL);
     }
     catch (Exception ex)
     {
         throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." +
                             MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
     }
 }
示例#30
0
 /// <summary>
 /// method to Delete an item with the given code from the database
 /// </summary>
 /// <param name="db"></param>
 /// <param name="code"></param>
 public void DeleteItem(clsDataAccess db, string code)
 {
     try
     {
         sSQL = "Delete from ItemDesc Where ItemCode = '" + code + "'";
         db.ExecuteNonQuery(sSQL);
     }
     catch (Exception ex)
     {
         throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." +
                             MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
     }
 }
        /// <summary>
        /// Adds a new invoice to the database
        /// </summary>
        /// <param name="date"></param>
        /// <param name="totalCharge"></param>
        /// <param name="items"></param>
        public void addInvoice(string date, string totalCharge, ObservableCollection<clsItem> items)
        {
            try
            {
                db = new clsDataAccess();
                int iRet = 0;

                string sSQL = "INSERT INTO Invoices( InvoiceDate, TotalCharge) VALUES(#" +
                    date + "#, " + totalCharge + ")";
                db.ExecuteNonQuery(sSQL);

                string sSQLInvoiceNumber = "SELECT MAX(InvoiceNum) FROM Invoices";

                DataSet newInvoice = db.ExecuteSQLStatement(sSQLInvoiceNumber, ref iRet);
                string invoiceNumber = newInvoice.Tables[0].Rows[0][0].ToString();

                int i = 1;
                foreach (clsItem item in items)
                {
                    string sSQLLineItem = "INSERT INTO LineItems(InvoiceNum, LineItemNum, ItemCode) " +
                        "VALUES('" + invoiceNumber + "', '" + i + "' , '" + item.ItemCode + "')";
                    db.ExecuteNonQuery(sSQLLineItem);
                    i += 1;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }
        }
        /// <summary>
        /// Updates an existing invoice in the database
        /// </summary>
        /// <param name="invoiceNum"></param>
        /// <param name="totalCharge"></param>
        /// <param name="items"></param>
        public void updateInvoice(string invoiceNum, string totalCharge, ObservableCollection<clsItem> items)
        {
            try
            {
                db = new clsDataAccess();

                string sSQL = "UPDATE Invoices " +
                    "SET TotalCharge = '" + totalCharge +
                    "' WHERE InvoiceNum = " + invoiceNum;
                db.ExecuteNonQuery(sSQL);

                sSQL = "Delete FROM LineItems WHERE InvoiceNum = " + invoiceNum;
                db.ExecuteNonQuery(sSQL);

                int i = 1;
                foreach (clsItem item in items)
                {
                    string sSQLLineItem = "INSERT INTO LineItems(InvoiceNum, LineItemNum, ItemCode) " +
                        "VALUES('" + invoiceNum + "', '" + i + "' , '" + item.ItemCode + "')";
                    db.ExecuteNonQuery(sSQLLineItem);
                    i += 1;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }
        }