private void editWhseBtn_Click(object sender, RoutedEventArgs e) { if (CentersListBox.SelectedItem is AmzWarehouseModel) { //grab selected item. AmzWarehouseModel amzSelected = (AmzWarehouseModel)CentersListBox.SelectedItem; //instantiate new AmazonWarehouseWin and pass in selected AmzWarehouseModel AmazonWarehouseWin amzWin = new AmazonWarehouseWin(amzSelected, Utilities.DbQuery.Edit); amzWin.titleLabel.Content = "Edit Amazon Fulfillment Warehouse"; //show the window. amzWin.ShowDialog(); if (amzWin.DialogResult == true) //warehouse edit is successful { //save updated warehouse to database. MessageBox.Show("Amazon Fulfillment Warehouse successfully saved."); PopulateGUI(); } else //warehouse edit is unsuccessful { //inform user nothing was done. MessageBox.Show("Unable to save the Amazon Fulfillment Warehouse."); } } }
/// <summary> /// Overloaded constructor passing in an AmzWarehouseModel object to edit one. /// </summary> /// <param name="comp">CompanyAddressModel to be edited.</param> public AmzWarehouseViewModel(AmzWarehouseModel amzWhse) { StateModels = new List <StateModel>(); FulFillmentCenters = new List <AmzWarehouseModel>(); CurrentAmazonWhse = amzWhse; PopulateLists(); }
public AmazonWarehouseWin(AmzWarehouseModel warehouseModel, Utilities.DbQuery dbQuery) { InitializeComponent(); amzWarehouse = warehouseModel; amzWarehouseVM = new AmzWarehouseViewModel(warehouseModel); DbQuery = dbQuery; PopulateGUI(); }
/// <summary> /// Grabs all AmazonWarehouses from the DbContext to populate the ListBox for the NewShipment.xaml view. /// </summary> private void PopulateAmazonWarehouse() { using (var db = new Models.AppContext()) { List <AmazonWarehouse> warehousees = db.AmazonWarehouses.Include(s => s.State).ToList(); foreach (AmazonWarehouse amz in warehousees) { AmzWarehouseModel amzModel = new AmzWarehouseModel(amz); AmzWarehouses.Add(amzModel); } } }
/// <summary> /// Sends a list of boxes to the default label printer to be printed. /// </summary> /// <param name="boxestoPrint">List of boxes to print</param> /// <param name="amzWarehouse">The Amazon Fulfillment Center for the box label</param> /// <param name="companyAddress">The Company Address for the box label</param> public void ReprintLabels(List <FBABox> boxestoPrint, AmzWarehouseModel amzWarehouse, CompanyAddressModel companyAddress, int totalBoxCount) { //reinitialize the labelfactory LabelFactory = new LabelFactory(boxestoPrint, amzWarehouse, companyAddress, totalBoxCount); //grab default label printer string labelPrinter = Properties.Settings.Default.LabelPrinter; //send each label to the printer. foreach (var label in LabelFactory.BoxLabels) //send each BoxLabel to printer. { RawPrinterHelper.SendStringToPrinter(labelPrinter, label.ZPLCommand); } }
private void btn_AddWhse_Click(object sender, RoutedEventArgs e) { //open new window to add an Amazon Warehouse AmzWarehouseModel amzwhse = new AmzWarehouseModel(); AmazonWarehouseWin amzWindow = new AmazonWarehouseWin(amzwhse, DbQuery.Add); amzWindow.ShowDialog(); if (amzWindow.DialogResult == true) { MessageBox.Show("New Amazon warehouse successfully added to DB!"); RefreshGUI(); } else { MessageBox.Show("Unable to save Amazon warehouse to DB."); } }
/// <summary> /// Allows for a query to be performed on the database to an AmazonWarehouse Entity. /// </summary> /// <param name="amzWarehouse">AmazonWarehouse entity to be passed to database.</param> /// <param name="dbQuery">The type of query to be performed on the database.</param> /// <returns>If successfully added to Db return True. </returns> public bool AmzWarehouseDbQuery(AmzWarehouseModel amzWarehouse, Utilities.DbQuery dbQuery) { if (amzWarehouse != null) { using (var db = new Models.AppContext()) { //instantiate new AmazonWarehouse entity and fill fields AmazonWarehouse amazon = new AmazonWarehouse() { Id = amzWarehouse.Id, WarehouseCode = amzWarehouse.WarehouseCode, Name = amzWarehouse.Name, AddressLine = amzWarehouse.AddressLine, City = amzWarehouse.City, ZipCode = amzWarehouse.ZipCode, State = db.States.Where(s => s.Id == amzWarehouse.StateId).FirstOrDefault() }; //perform correct DB query depending on what was passed in as dbentry. switch (dbQuery) { case Utilities.DbQuery.Add: db.AmazonWarehouses.Add(amazon); break; case Utilities.DbQuery.Edit: db.Entry(amazon).State = System.Data.Entity.EntityState.Modified; break; case Utilities.DbQuery.Delete: AmazonWarehouse compDelete = db.AmazonWarehouses.Find(amazon.Id); db.AmazonWarehouses.Remove(compDelete); break; } //save DbContext db.SaveChanges(); return(true); } } else { return(false); } }
/// <summary> /// Event when the 'Add' button is clicked on the view. ds to the warehouse. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void addWhseBtn_Click(object sender, RoutedEventArgs e) { //open new window to add an Amazon Warehouse AmzWarehouseModel amzwhse = new AmzWarehouseModel(); AmazonWarehouseWin amzWindow = new AmazonWarehouseWin(amzwhse, DbQuery.Add); amzWindow.titleLabel.Content = "Add An Amazon Warehouse"; amzWindow.ShowDialog(); if (amzWindow.DialogResult == true) { MessageBox.Show("The new Amazon Fulfillment Warehouse was successfully added to the Database! :D"); //refresh UI PopulateGUI(); } else { MessageBox.Show("Unable to save the new Amazon Warehouse"); } }
private void deleteWhseBtn_Click(object sender, RoutedEventArgs e) { if (CentersListBox.SelectedItem is AmzWarehouseModel) { //grab selected item. AmzWarehouseModel amzSelected = (AmzWarehouseModel)CentersListBox.SelectedItem; //call db query to delete warehouse if (amzViewModel.AmzWarehouseDbQuery(amzSelected, DbQuery.Delete)) { MessageBox.Show("Amazon Warehouse: " + amzSelected.WarehouseCode + " successfully deleted from databse."); //refresh UI PopulateGUI(); } else { MessageBox.Show("Unable to delete Amazon Warehouse: " + amzSelected.WarehouseCode + ". :("); } } }
/// <summary> /// Reprints FBA Box labels to PDF using labelry.com API service. /// </summary> /// <param name="boxestoPrint">List of FBABox to be reprinted</FBABox></param> /// <param name="amzWarehouse">Ship To Amazon Warehouse</param> /// <param name="companyAddress">Ship From Company Address</param> /// <param name="totalBoxCount">Total boxes in the shipment</param> /// <param name="shipmentID">The Shipment Id of the boxes.</param> public void ReprintToPDF(List <FBABox> boxestoPrint, AmzWarehouseModel amzWarehouse, CompanyAddressModel companyAddress, int totalBoxCount, string shipmentID) { //empty string to fill zpl command string zpl = ""; string boxesPrinted = ""; //instantiate new LabelFactory with passed in parameters. LabelFactory = new LabelFactory(boxestoPrint, amzWarehouse, companyAddress, totalBoxCount); //fill in string for ZPL command foreach (ZPLLabel label in LabelFactory.BoxLabels) { zpl += label.ZPLCommand; boxesPrinted += label.Box.BoxNumber + "-"; } //make a savepath string string filePath = Properties.Settings.Default.SaveFileDir + "\\" + shipmentID + "_BOXES_" + boxesPrinted + " _Reprinted_Labels.pdf"; //get string in UTF8 bytes byte[] zplByte = Encoding.UTF8.GetBytes(zpl); // instantiate request object var request = (HttpWebRequest)WebRequest.Create("http://api.labelary.com/v1/printers/8dpmm/labels/4x8/"); request.Method = "POST"; request.Accept = "application/pdf"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = zplByte.Length; //adding headers request.Headers.Add("X-Rotation:90"); //rotate labels 90 degrees request.Headers.Add("X-Page-Size", "Letter"); request.Headers.Add("X-Page-Layout:1x2"); // layout labels with 1 column and 3 rows (3 labels per page) var requestStream = request.GetRequestStream(); requestStream.Write(zplByte, 0, zplByte.Length); requestStream.Close(); try { //get the response from the request var response = (HttpWebResponse)request.GetResponse(); //get the response stream var responseStream = response.GetResponseStream(); //create file where response data will go var fileStream = File.Create(filePath); //convert the responseStream to a file at specified path responseStream.CopyTo(fileStream); //close the stream responseStream.Close(); fileStream.Close(); //inform of success //Console.WriteLine("Successfully retrieved the PDF for the ZPL string!"); } catch (WebException e) { //Console.WriteLine("ERROR: {0}\n", e.Message); } }