/// <summary> /// updates the invoice int he db /// </summary> /// <param name="oInvoice"></param> public void editInvoiceFromDB(clsInvoice oInvoice) { try { //Delete all Old line items foreach (var item in oInvoice.LItems) { db.ExecuteNonQuery("DELETE FROM LineItems WHERE InvoiceNum = " + oInvoice.IInvoiceNumber + " AND LineItemNum = " + item.ILineItemNum); } //Add new Line Items foreach (var item in oInvoice.LItems) { db.ExecuteNonQuery("INSERT INTO LineItems(InvoiceNum, LineItemNum, ItemCode) VALUES(" + oInvoice.IInvoiceNumber + ", " + item.ILineItemNum + ", '" + item.SItemCode.ToString() + "')"); } //update Invoice db.ExecuteNonQuery("UPDATE Invoices SET InvoiceDate = #" + oInvoice.DateInvoiceDate.ToShortDateString() + "#, TotalCost = " + oInvoice.ITotalCost + " WHERE InvoiceNum = " + oInvoice.IInvoiceNumber); } catch (System.Exception ex) { //Just throw the exception throw new System.Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message); } }
/// <summary> /// Returns the full list of invoices from the database /// </summary> /// <returns></returns> public ObservableCollection <clsInvoice> invoicesCollection() { try { string sSQL; //Holds an SQL statement int iRet = 0; //Number of return values ds = new DataSet(); db = new clsDataAccess(); ObservableCollection <clsInvoice> col_Invoices = new ObservableCollection <clsInvoice>(); clsInvoice invoice; sSQL = "SELECT InvoiceNum, InvoiceDate, TotalCharge " + "FROM Invoices"; ds = db.ExecuteSQLStatement(sSQL, ref iRet); for (int i = 0; i < iRet; i++) { invoice = new clsInvoice(); invoice.InvoiceNum = ds.Tables[0].Rows[i][0].ToString(); invoice.InvoiceDate = ds.Tables[0].Rows[i]["InvoiceDate"].ToString(); invoice.TotalCharge = ds.Tables[0].Rows[i]["TotalCharge"].ToString(); col_Invoices.Add(invoice); } return(col_Invoices); } catch (Exception ex) { throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message); } }
/// <summary> /// Get invoices function builds a query string and executes it and returns a list of invoices. /// </summary> /// <param name="dateTime"></param> /// <param name="totalCharges"></param> /// <param name="invoiceId"></param> /// <returns></returns> public List <clsInvoice> GetInvoices(DateTime?dateTime, double?totalCharges, int?invoiceId) { try { string queryString = clsSearchSQL.GetInvoices(dateTime, totalCharges, invoiceId); int numReturned = 0; DataSet invoiceDataSet = clsDataAccess.ExecuteSQLStatement(queryString, ref numReturned); List <clsInvoice> clsInvoicesList = new List <clsInvoice>(); for (int i = 0; i < numReturned; i++) { var invoice = new clsInvoice(); invoice.Id = int.Parse(invoiceDataSet.Tables[0].Rows[i][0].ToString()); invoice.InvoiceDate = (DateTime)invoiceDataSet.Tables[0].Rows[i][1]; invoice.TotalCost = double.Parse(invoiceDataSet.Tables[0].Rows[i][2].ToString()); clsInvoicesList.Add(invoice); } return(clsInvoicesList); } catch (Exception ex) { throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message); } }
protected void Page_Load(object sender, EventArgs e) { clsInvoice objInv = new clsInvoice(); clsCommon objCom = new clsCommon(); Guid invID = Guid.Parse(Request.QueryString["item_number"]); string txID = Request.QueryString["tx"]; string txStatus = Request.QueryString["st"]; if (txStatus == "Completed") { lblData.Text = " Your transaction was completed successfully! "; lblData.Text += "<br/> Please make a note of the following details : "; lblData.Text += "<br/> <b> Transaction ID : </b>" + txID; lblData.Text += "<br/> <b> Paid on date : </b>" + DateTime.Now; // update db objInv.updateTransaction(invID, txID, DateTime.Now); } else { lblData.Text = " Your transaction was not completed!"; lblData.Text += "<br/> <br/>"; lblData.Text += "Please contact PayPal or your credit card provider and try again later."; } }
/// <summary> /// Removes a specific order from the selected Invoice /// </summary> /// <param name="orderObject">SelectedOrder</param> internal void RemoveOrderFromInvoice(int orderId) { try { int foundInvoiceId = 0; foreach (clsInvoice invoice in invoices) { foreach (clsOrder order in invoice.Orders) { if (order.OrderId == orderId) { foundInvoiceId = invoice.Id; } } } dataAccess.ExecuteNonQuery(MainSQL.SQLRemoveOrderFromInvoice(orderId)); Update(); clsInvoice foundInvoice = invoices.SingleOrDefault(i => i.Id == foundInvoiceId); SetTotalCost(foundInvoice.Id, foundInvoice.Orders); } catch (Exception) { throw; } }
public List <clsInvoice> GetAllInvoices() { try { DataSet ds = new DataSet(); int iRef = 0; var query = sql.SelectAllInvoices(); invoiceResult = new List <clsInvoice>(); clsInvoice invoice; ds = db.ExecuteSQLStatement(query, ref iRef); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { invoice = new clsInvoice(); invoice.InvoiceNum = Convert.ToInt32(ds.Tables[0].Rows[i][0]); invoice.InvoiceDate = ds.Tables[0].Rows[i][1].ToString(); invoice.TotalCost = Convert.ToInt32(ds.Tables[0].Rows[i][2]); invoiceResult.Add(invoice); } } catch (Exception ex) { throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message); } return(invoiceResult); }
/// <summary> /// Runs the provided SQL string and fills the invoice variable with the results. /// </summary> /// <param name="sSQL"></param> /// <returns></returns> public ObservableCollection <clsInvoice> getInvoices(string sSQL) { try { DataSet ds = new DataSet(); result = new ObservableCollection <clsInvoice>(); clsInvoice invoice; int numRows = 0; ds = dt.ExecuteSQLStatement(sSQL, ref numRows); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { invoice = new clsInvoice(); invoice.InvoiceNum = Convert.ToInt32(ds.Tables[0].Rows[i][0]); invoice.InvoiceDate = ds.Tables[0].Rows[i][1].ToString(); invoice.TotalCost = Convert.ToInt32(ds.Tables[0].Rows[i][2]); result.Add(invoice); } } catch (Exception ex) { //Just throw the exception throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message); } return(result); }
public void InstanceOK() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //test to see that it exists Assert.IsNotNull(AInvoice); }
public void OrderNoPropertyOK() { //create an instance of the class clsInvoice AInvoice = new clsInvoice(); //create some test data to assign to the property Int32 SomeOrderNo = 1; //assign the data to the property AInvoice.OrderNo = SomeOrderNo; //test to see that it exists Assert.AreEqual(AInvoice.OrderNo, SomeOrderNo); }
public void AddressProperty() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //create some test data to assign to the property string SomeAddress = "Leicestershire"; //assign the data to the property AInvoice.Address = SomeAddress; //test to see that the two values are the same Assert.AreEqual(AInvoice.Address, SomeAddress); }
public void PostcodePropertyOK() { //create an instance of the class clsInvoice AInvoice = new clsInvoice(); //create some test data to assign to the property string SomePostcode = "LE2 7EE"; //assign the data to the property AInvoice.Postcode = SomePostcode; //test to see that it exists Assert.AreEqual(AInvoice.Postcode, SomePostcode); }
public void PricePropertyOK() { //create an instance of the class clsInvoice AInvoice = new clsInvoice(); //create some test data to assign to the property double SomePrice = 1.1; //assign the data to the property AInvoice.Price = SomePrice; //test to see that it exists Assert.AreEqual(AInvoice.Price, SomePrice); }
public void AddressNoPropertyOK() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //create some test data to assign to the property Int32 AddressNo = 1; //assign the data to the property AInvoice.AddressNo = AddressNo; //test to see that the two values are the same Assert.AreEqual(AInvoice.AddressNo, AddressNo); }
public void DateCreatedPropertyOK() { //create an instance of the class clsInvoice AInvoice = new clsInvoice(); //create some test data to assign to the property string SomeDateCreated = "2018/09/06"; //assign the data to the property AInvoice.DateCreated = SomeDateCreated; //test to see that it exists Assert.AreEqual(AInvoice.InvoiceNo, SomeDateCreated); }
public void FindMethodOK() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //string variable to store any error message Boolean Found = false; //create some test data to pass to method Int32 SomeInvoiceNo = 1; //invoke the method Found = AInvoice.Find(SomeInvoiceNo); //test to see that the result is correct Assert.IsTrue(Found); }
/// <summary> /// Adds an order to the selected invoice. /// </summary> /// <param name="invoiceId">SelectedInvoiceId</param> /// <param name="cardId">SelectedCardId</param> /// <param name="quantity">SelectedCardQuantity</param> public void AddOrderToInvoice(int invoiceId, int cardId, int quantity) { try { dataAccess.ExecuteNonQuery(MainSQL.SQLAddOrderToInvoice(invoiceId, cardId, quantity)); Update(); clsInvoice foundInvoice = invoices.SingleOrDefault(i => i.Id == invoiceId); SetTotalCost(invoiceId, foundInvoice.Orders); } catch (Exception) { throw; } }
public void AddressMinLessOne() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //boolean variable to store the result of the validation Boolean OK = false; //create some test data to assign to the property string SomeAddress = ""; //invoke the method OK = AInvoice.Valid(SomeAddress); //test to see that the result is correct Assert.IsFalse(OK); }
public void AddressExtremeMax() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //boolean variable to store the result of the validation Boolean OK = false; //create some test data to assign to the property string SomeAddress = ""; //pad the string with a character SomeAddress = SomeAddress.PadRight(500, 'a'); //invoke the method OK = AInvoice.Valid(SomeAddress); //test to see that the result is correct Assert.IsFalse(OK); }
/// <summary> /// Selects an invoice /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnSelectInvoice_Click(object sender, RoutedEventArgs e) { try { if (dgItems.SelectedItem != null) { selectedInvoice = (clsInvoice)dgItems.SelectedItem; this.Close(); } } catch (Exception ex) { HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
public void DateCreatedInvalidData() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //string variable to store any error message String Error = ""; //create some test data to pass to method Int32 SomeInvoiceNo = 1; string SomeDateCreated = "This is not a date"; double SomePrice = 1.1; string SomePostcode = "LE2 7FZ"; Int32 SomeOrderNo = 1; //invoke the method Error = AInvoice.Valid(SomeInvoiceNo, SomeDateCreated, SomePrice, SomePostcode, SomeOrderNo); //test to see that the result is correct Assert.AreEqual(Error, ""); }
/// <summary> /// parses out which invoice was deleted and deletes it. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DeleteInvoice_Click(object sender, RoutedEventArgs e) { try { //get the id MainLogic.DeleteInvoice(MyInvoice.InvoiceID); //clears all displays MyList.Clear(); MyInvoice = new clsInvoice(0, "", 0); UpdateDisplays(); } catch (Exception ex) { HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// initializes all class level items /// </summary> public MainWindow() { try { InitializeComponent(); //Main window main logic class MainLogic = new clsMainLogic(); //all the selected items MyList = new List <clsLineItems>(); //new blank invoice MyInvoice = new clsInvoice(0, "", 0.00); //flag to switch between and edit save and an add save TypeOfSave = false; //Populates All items in the database to a combo box cbItems.ItemsSource = MainLogic.ListItems(); //populates all selected into a data grid dgAll_Items.ItemsSource = MyList; //updates the displays UpdateDisplays(); ItemsWindow = new wndItems(); //initializes the ItemsWindow //disables editing/deleting/saving until there is something to save EditInvoice.IsEnabled = false; DeleteInvoice.IsEnabled = false; SaveInvoice.IsEnabled = false; //disables all input DisableAllInput(); } catch (Exception ex) { HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
public void OrderNoMid() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //string variable to store any error message String Error = ""; //create some test data to pass to method Int32 SomeInvoiceNo = 1; DateTime TestDateCreated = DateTime.Now.Date; string SomeDateCreated = TestDateCreated.ToString(); double SomePrice = 1.1; string SomePostcode = "LE2 7FZ"; Int32 SomeOrderNo = 1073741824; //invoke the method Error = AInvoice.Valid(SomeInvoiceNo, SomeDateCreated, SomePrice, SomePostcode, SomeOrderNo); //test to see that the result is correct Assert.AreEqual(Error, ""); }
public void TestOrderNoFound() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //string variable to store any error message Boolean Found = false; //boolean variable to record if data is OK Boolean OK = true; //create some test data to pass to method Int32 InvoiceNo = 1; //invoke the method Found = AInvoice.Find(InvoiceNo); //check property on if (AInvoice.OrderNo != 1) { OK = false; } Assert.IsTrue(OK); }
/// <summary> /// deletes the invoice /// </summary> /// <param name="oInvoice"></param> public void deleteInvoice(clsInvoice oInvoice) { try { //Delete all Old line items foreach (var item in oInvoice.LItems) { db.ExecuteNonQuery("DELETE FROM LineItems WHERE InvoiceNum = " + oInvoice.IInvoiceNumber + " AND LineItemNum = " + item.ILineItemNum); } //Delete Old Invoice db.ExecuteNonQuery("DELETE FROM Invoices WHERE InvoiceNum = " + oInvoice.IInvoiceNumber); } catch (System.Exception ex) { //Just throw the exception throw new System.Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message); } }
/// <summary> /// Saves the selected invoice number in the InvoiceNum variable for the main screen to access. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSelect_Click(object sender, RoutedEventArgs e) { try { if (dgInvoices.SelectedItem != null) { clsInvoice invoice = (clsInvoice)dgInvoices.SelectedCells[0].Item; InvoiceNum = invoice.InvoiceNum; } else { InvoiceNum = -1; } this.Close(); } catch (Exception ex) { HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// This SQL statement gets item names of all available items /// </summary> /// <param name="sItemCode"></param> /// <returns>Item names</returns> public static clsInvoice getInvoice(int invoiceNumber) { try { //local variables to store returned data clsDataAccess ds = new clsDataAccess(); clsInvoice invoice = new clsInvoice(); DataSet dataSet = new DataSet(); ObservableCollection <clsItem> list = new ObservableCollection <clsItem>(); //set invoice object attribute invoice number invoice.setInvoiceNumber(invoiceNumber); //get invoice date using invoice number string sSQL = "SELECT InvoiceDate FROM Invoices WHERE InvoiceNum = " + invoiceNumber; invoice.setInvoiceDate(ds.ExecuteScalarSQL(sSQL).ToString()); //get line items int iRef = 0; sSQL = "SELECT LineItems.ItemCode, ItemDesc.ItemDesc, ItemDesc.Cost FROM ItemDesc " + "INNER JOIN LineItems ON ItemDesc.ItemCode = LineItems.ItemCode WHERE LineItems.InvoiceNum = " + invoiceNumber; dataSet = ds.ExecuteSQLStatement(sSQL, ref iRef); foreach (DataRow dr in dataSet.Tables[0].Rows) { clsItem item = new clsItem(); item.sItemCode = dr[0].ToString(); item.sItemDesc = dr[1].ToString(); item.sCost = dr[2].ToString(); list.Add(item); } invoice.setLineItemList(list); return(invoice); } catch (Exception ex) { throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " ->" + ex.Message); } }
protected void btnGetAQuote_Click(object sender, EventArgs e) { //No a member is no allow if (CustomerNo == 0) { lblError.Text = "Please Sign-In or Sign-Up first from main page"; } else if (tbxCollectionPostcode.Text == "" || tbxDestinationPostcode.Text == "") { lblError.Text = "Please fill the list"; } else { //create an instance of the class we want to create clsOrderCollection AllOrders = new clsOrderCollection(); clsOrder AddItem = new clsOrder(); //set its properties AddItem.Active = true; AddItem.CollectionPostcode = tbxCollectionPostcode.Text; AddItem.DestinationCountry = ddlDestinationCountry.SelectedValue; AddItem.DestinationPostcode = tbxDestinationPostcode.Text; DateTime NowDateCreated = DateTime.Now.Date; AddItem.DateCreated = NowDateCreated.ToString(); AddItem.ParcelSize = ddlParcelSize.SelectedValue; AddItem.Status = "Parcel Collecting"; AddItem.CustomerNo = CustomerNo; //Put item into ThisOrder AllOrders.ThisOrder = AddItem; //Add order and store the PK Int32 OrderNoPK = AllOrders.Add(); //create a class object clsInvoice invoice = new clsInvoice(); //set its properties Int32 InvoiceNoPK = invoice.Add(NowDateCreated.ToString(), CalculatePrice(), tbxDestinationPostcode.Text, OrderNoPK); Response.Redirect("GotQuickQuote.aspx"); } }
/// <summary> /// menu control when search is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SearchTab_Click(object sender, RoutedEventArgs e) { try { SearchWindow = new wndSearch(); //initializes the SearchWindow this.Hide(); SearchWindow.ShowDialog(); this.Show(); DeleteInvoice.IsEnabled = true; EditInvoice.IsEnabled = true; MyList.Clear(); AmountOfItems.Text = ""; ItemCostTextBox.Text = ""; cbItems.SelectedIndex = -1; DisableAllInput(); SaveInvoice.IsEnabled = false; //check if it has been closed but nothing has been selected if (SearchWindow.SelectedInvoice != null) { MyInvoice = SearchWindow.SelectedInvoice; //adds all the items that are associated with the invoice into the data grid foreach (var item in MainLogic.GetLineItems(MyInvoice.InvoiceID)) { MyList.Add(item); } } UpdateDisplays(); } catch (Exception ex) { HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
internal async Task <clsitemresponse> PlaceOrder(clsInvoice items) { clsitemresponse response1 = new clsitemresponse(); var Httpclient = new HttpClient(); var url = Constants.BaseApiAddress + "myapi/insertupdatesaleorder"; var uri = new Uri(string.Format(url, string.Empty)); var json = JsonConvert.SerializeObject(items); var content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = null; response = await Httpclient.PostAsync(uri, content); if (response.StatusCode == HttpStatusCode.OK) { var responseContent = await response.Content.ReadAsStringAsync(); var jObject = JObject.Parse(responseContent); response1 = new clsitemresponse { Status = (bool)jObject.GetValue("Status"), Message = jObject.GetValue("Message").ToString(), OrderNumber = jObject.GetValue("orderNumber").ToString(), }; } return(response1); }
/// <summary> /// Updates the Database With the new Invoice And Lineitem data /// </summary> /// <param name="oInvoice"></param> public int addNewInvoiceToDB(clsInvoice oInvoice) { //Add New Invoice try { //Create new invoice db.ExecuteNonQuery("INSERT INTO Invoices(InvoiceDate, TotalCost) VALUES (#" + oInvoice.DateInvoiceDate.ToShortDateString() + "#, " + oInvoice.ITotalCost + ")"); } catch (Exception ex) { Console.WriteLine("Failed to add new invoice."); throw (ex); } //Add All New Line Items try { //get the invoice number int iInvoiceNumber = getMaxInvoice() - 1; //Add the items for the invoice foreach (var item in oInvoice.LItems) { db.ExecuteNonQuery("INSERT INTO LineItems(InvoiceNum, LineItemNum, ItemCode) VALUES(" + iInvoiceNumber + ", " + item.ILineItemNum + ", '" + item.SItemCode.ToString() + "')"); } //return the new invoice number return(iInvoiceNumber); } catch (Exception ex) { Console.WriteLine("Failed to add new line items."); throw (ex); } }