public void WriteToOutput(string text) { try { File.AppendAllText(outputfile, text + Environment.NewLine); } catch (Exception e) { PopUp popup = new PopUp("Importer Message", "Error writing to Output. " + e.Message); popup.Show(); } }
public void writeToLog(string message) { try { File.AppendAllText(logname, DateTime.Now.ToString() + " | " + message + Environment.NewLine); } catch(Exception e) { PopUp popup = new PopUp("Importer Message", "Error writing to log. " + e.Message); popup.Show(); } }
private void WriteToOutput(string text) { try { File.AppendAllText(writefile, text + "\n"); } catch (Exception e) { PopUp popup = new PopUp("Importer Message", "Error writing to Output. " + e.Message); popup.Show(); } }
private void btnSubmit_Click(object sender, RoutedEventArgs e) { #region Declerations int departmentid = 0; // declare the departmentid int itemid = 0; // declare the itemid int inventoryid = 0; // declare the inventoryid int quantity = 0; // declare the quantity string status = ""; // get status for item_quantity string tfcontents = "Beginning the import..."; // string for textblock DataTable dt = new DataTable(); // declare datatable #endregion txtFileContents.Text = tfcontents; // write string to textblock if (tbDeptNum.Text != null || tbDeptNum.Text != "") // check to see if department number textbox contains text or is empty { departmentid = ss.GetDepartmentID(tbDeptNum.Text); // get the departmentid, need from SQLGetStatements } if (departmentid > 0 && FilePath != null) // check to see if departmentid returned a number and that the file to import is not empty { StreamReader file = new StreamReader(FilePath); // Read from the text file string line; // declare the string for the lines int linecount = 0; ClearInventoryValues(departmentid); // clears the inventory values and sets quantities to 0, updates status to "InActive". while ((line = file.ReadLine()) != null) // assign string line to the line from a file and confirm it is not null. { itemid = ss.GetItemIDByBarcode(line); // get the itemid from SQLGetStatements by barcode linecount++; if (itemid <= 1) { itemid = si.InsertItems("", 1, line, "Created to insert into ItemQuantity", 0, 0, 0, 0, 0, 0, "Unknown", "", "", "", "", "", "", "", "", "", ""); } if (previousLines.Contains(line)) { // The line has been used before dt = ss.GetItemQuantity(itemid, departmentid); // get the current quantity infromation if (dt.Rows.Count > 0) { quantity = dt.Rows[0].Field<int>("quantity"); // get the current quantity quantity = quantity + 1; // add 1 to the quantity if (su.SQLItemQuantityUpdateQty(itemid, departmentid, quantity, "Active")) // Update inventory { si.InsertInventoryLog(itemid, "", departmentid, 1, "Inventory increased by 1 for item. The current quantity is " + quantity.ToString()); // insert into Inventory Log } } else if (dt.Rows.Count <= 0)// if ItemQuantity does not exist { si.InsertItemQuantities(itemid, departmentid, 1, "Active"); si.InsertInventoryLog(itemid, "", departmentid, 1, "Added to inventory quantities with default quantity of 1."); } else { logger.WriteToOutput(line); //WriteToOutput(line); } dt.Clear(); } else { dt = ss.GetItemQuantity(itemid, departmentid); // get the itemquantity from itemid and departmentid if (dt.Rows.Count > 0) // if ItemQuantity exists { quantity = dt.Rows[0].Field<int>("quantity"); // assign "quantity" to quantity variable status = dt.Rows[0].Field<string>("status"); // assign "status" to status variable inventoryid = dt.Rows[0].Field<int>("item_quantity_id"); // assign "item_quantity_id" to inventoryid variable previousLines.Add(line); // Add the line to previous lines. if (su.SQLItemQuantityUpdateQty(itemid, departmentid, 1, "Active")) // try to update quantity { si.InsertInventoryLog(itemid, "", departmentid, 1, "Inventory reset and then increased by 1 for item. Previous quantity was: " + quantity.ToString()); // insert into inventorylog } } else if (dt.Rows.Count <= 0)// if ItemQuantity does not exist { // TODO: Input a new inventory item. si.InsertItemQuantities(itemid, departmentid, 1, "Active"); si.InsertInventoryLog(itemid, "", departmentid, 1, "Added to inventory quantities with default quantity of 1."); } else // check for exceptions { logger.WriteToOutput(line); //WriteToOutput(line); } dt.Clear(); } } previousLines.Clear(); tfcontents = tfcontents + Environment.NewLine + "Completed the Import!"; txtFileContents.Text = tfcontents; PopUp pop = new PopUp("Inventory Scan Complete", "Inventory Scan for Store " + tbDeptNum.Text + " has finished." + Environment.NewLine + "There were " + linecount.ToString() + " items that were proceesed"); pop.Show(); } }
private void Items() { AccessQueries accquer = new AccessQueries(); DataTable dt1 = new DataTable(); DateTime itemdate = DateTime.Now.AddYears(-3); string vendorid = "", invoiceid = "", invoiceitemid = "", itemid = "", quantityid = "", departmentid = ""; int units = 0; string invoicenum = ""; string vendornumber = ""; decimal cost = 0; decimal retail = 0; if (dpItemDate.Text != null || dpItemDate.Text != "") { itemdate = conv.ConvertToDate(dpItemDate.Text, -1095); } // TODO: Validate if it is an actual date. Change to DatePicker. // 1 = Paragould, 2 = Jackson, 4 = Jonesboro if (tbDeptNum.Text == "1" || tbDeptNum.Text == "2" || tbDeptNum.Text == "4") { dt1 = accquer.GetItems(tbDeptNum.Text, itemdate); } else { dt1 = accquer.GetItems("1", itemdate); } // Query Access with parameter of a store number and cutoff date. if (dt1.Rows.Count > 0) { foreach (DataRow row in dt1.Rows) { vendornumber = row[15].ToString(); if (row[9] == null) { cost = 0; } else { cost = conv.ConvertToDecimal(row[9].ToString()); } if (row[10] == null) { retail = 0; } // row 10 to Retail else { retail = conv.ConvertToDecimal(row[10].ToString()); } if (row[11] == null) { units = 1; } else { units = conv.ConvertToInt(row[11].ToString()); } try { vendorid = ss.GetVendorID(vendornumber); } catch (Exception) { logging.writeToLog("Warning: Unable to retrieve VendorID = " + vendornumber + " from ImportItems. "); } if (vendorid == "" || vendorid == null) { vendorid = "1"; } try { invoiceid = ss.GetInvoiceIDforImports(vendorid); } catch (Exception) { logging.writeToLog("Warning: Unable to retrieve InvoiceID = " + vendorid.ToString() + " from ImportItems."); } if (invoiceid == "" || invoiceid == null) { invoicenum = "X" + vendornumber + "X"; invoiceid = si.InsertInvoices(invoicenum, row[13].ToString(), row[14].ToString(), vendorid, "22331111-0111-1000-1000-000011112222", "Created by System", "none"); // Invoices } itemid = si.InsertItems(row[0].ToString(), "44441111-0111-1000-1000-000011112222", row[8].ToString(), row[2].ToString(), cost, retail, 0, 0, 0, "", "Active", row[0].ToString(), row[1].ToString(), row[4].ToString(), row[16].ToString(), row[3].ToString(), "", "", row[5].ToString(), row[6].ToString(), row[7].ToString()); // Items DataTable dt2 = ss.GetDepartmentByDeptNum(tbDeptNum.Text); try { departmentid = dt2.Rows[0].Field<string>("id"); } catch (Exception) { departmentid = "11111111-0111-1000-1000-000011112222"; } // TODO: Add this to a list and search the list for quicker results. // Find the date of the item and retrieve the invoiceid // Insert invoice with datetime invoiceitemid = si.InsertInvoiceItems(invoiceid, itemid, "Created by System", "", 0, 0, 0, 0, 0, departmentid, 0); // Invoice Items quantityid = si.InsertItemQuantities(itemid, departmentid, units, "Inserted by System"); // Insert into ItemQuantities } try { dt1.Clear(); } catch (Exception) { logging.writeToLog("Error: Clearing Results in Items DataTable"); } } PopUp pop = new PopUp("Items Imported.", "Items have finished importing."); pop.Show(); }
private void Customers(DataTable results) { int intcharge = 0, intvalue = 0; string strcharge = "", strjoindate = "", strstore = "", custcount = "", addressid = "", personid = "", customerid = "", intstore = ""; decimal declimit = 0, balance = 0; intvalue = conv.ConvertToInt(ss.GetAppConfig("CusRowCount")); if (results.Rows.Count != intvalue) { if (intvalue == 0) { custcount = si.InsertAppConfig("CusRowCount", results.Rows.Count.ToString()); } foreach (DataRow row in results.Rows) { strjoindate = row[10].ToString(); strstore = row[11].ToString(); // convert row12 string to int charge account strcharge = row[12].ToString().ToLower(); // convert to lowercase // convert string to int if "yes" if (strcharge == "yes") { intcharge = 1; } // convert row18 to charge limit if (row[18] == null) { declimit = 0; } else { try { declimit = Convert.ToDecimal(row[18].ToString()); } catch (Exception e) { declimit = 0; logging.writeToLog("Error: Convert Customer.row18 to declimit : " + e.Message + "\n Value: " + row[18].ToString()); } } // convert row16 to balance if (row[16] == null) { balance = 0; } else { conv.ConvertToDecimal(row[16].ToString()); } if (strjoindate.Length < 7) { strjoindate = ""; } if (strstore.Length > 1) { strstore.TrimStart('0'); } if (strstore == null || strstore == "") { strstore = "11111111-0111-1000-1000-000011112222"; } addressid = si.InsertAddress(row[2].ToString(), "", "", row[3].ToString(), row[4].ToString(), row[5].ToString(), "USA", "Imported from Access"); personid = si.InsertPerson(row[1].ToString(), row[0].ToString(), addressid, "", row[6].ToString(), row[7].ToString(), row[17].ToString(), "", row[9].ToString(), row[8].ToString(), "Imported from Access", "", "Active"); customerid = si.InsertCustomer(row[11].ToString(), personid, strjoindate, intcharge, declimit, 0, intstore, balance, 1); } try { results.Clear(); } catch (Exception e) { logging.writeToLog("Error: Clear Results Customer DataTable" + e.Message); } } PopUp pop = new PopUp("Customers Imported.", "Customers have finished importing."); pop.Show(); }
private void btnFullSync_Click(object sender, RoutedEventArgs e) { AccessQueries accquer = new AccessQueries(); //txtDBSyncStatus.Text = ""; if (cbStores.IsChecked.Value == true) { DataTable dt = new DataTable(); accquer.ImportDepartments(); //txtDBSyncStatus.Text += "Stores Imported...\n"; string addressid = "", departmentid = ""; foreach (DataRow row in dt.Rows) { // Insert into Address get ID addressid = si.InsertAddress("", "", "", "", "", "", "USA", "Imported from Access"); // Insert into Person get ID departmentid = si.InsertDepartment(row[0].ToString(), row[1].ToString(), addressid, "Imported from Access", "Active"); } try { dt.Clear(); } catch (Exception) { logging.writeToLog("Error: Clearing the results in Department of dataTable. "); } } if (cbEmployees.IsChecked.Value == true) { accquer.ImportEmployees(); // Import Employees //txtDBSyncStatus.Text += "Employees Imported...\n"; } if (cbCustomers.IsChecked.Value == true) { DataTable dt = new DataTable(); dt = accquer.ImportCustomers(); Customers(dt); //txtDBSyncStatus.Text += "Customers Imported...\n"; } if (cbVendors.IsChecked.Value == true) { DataTable dt = new DataTable(); eargs = eargs + "vendors "; //txtDBSyncStatus.Text += "Vendors Imported...\n"; // Import Vendors dt = accquer.ImportVendors(); VendorImport(dt); } if (cbCategories.IsChecked.Value == true) { //txtDBSyncStatus.Text += "Seasons Imported...\n"; //txtDBSyncStatus.Text += "Sizes Imported...\n"; //txtDBSyncStatus.Text += "Divisions Imported...\n"; // Import Divisions //txtDBSyncStatus.Text += "Classes Imported...\n"; // Import Classes // TODO: import categories } if (cbItems.IsChecked.Value == true) // Import Items { eargs = eargs + "items "; Items(); } if (cbTickets.IsChecked.Value == true) { DataTable tickets = new DataTable(); // Tickets => Date | TicketNumber | Total | Payment | Customer | Employee string date = dpTickets.SelectedDate.ToString(); DateTime start = DateTime.Now; DateTime end = DateTime.Now; start = conv.ConvertToDate(date); if (start.ToString("MM/dd/yyyy") == DateTime.Now.ToString("MM/dd/yyyy")) { start = start.AddMonths(-4); } for (var dte = start; dte <= end; dte = dte.AddDays(1)) { // Insert into tickets, ticket_items and ticket_payments tickets = accquer.GetTicketsByDate(dte.ToString("MM/dd/yyyy")); Tickets(tickets); tickets.Clear(); } PopUp pop = new PopUp("Tickets Imported.", "Tickets have finished importing."); pop.Show(); } //txtDBSyncStatus.Text += "Approvals Imported...\n"; //// Import Approvals //txtDBSyncStatus.Text += "Charge Customers Imported...\n"; //// Import Charge Customers. //txtDBSyncStatus.Text += "Cost Codes Imported...\n"; //// Import CostCode //txtDBSyncStatus.Text += "Credits Imported...\n"; //// Import Credits //txtDBSyncStatus.Text += "Orders Imported...\n"; //// Import Orders //txtDBSyncStatus.Text += "Sales Imported...\n"; //// Import Sales //txtDBSyncStatus.Text += "Tickets Imported...\n"; //// Import Tickets }