private void btnRemainingInventory_Click(object sender, EventArgs e) { WebRequestReport report = new WebRequestReport(); string srtFileName = null; using (StringWriter sw = new StringWriter()) { using (XmlWriter writer = XmlWriter.Create(sw)) { writer.WriteStartElement("Report"); writer.WriteElementString("Path", "Remaining_Inventory.jrxml"); writer.WriteEndElement(); writer.Flush(); writer.Close(); } srtFileName = report.getReport(sw.ToString()); } try { System.Diagnostics.Process.Start(srtFileName); } catch (Exception ex) { ErrorLog log = new ErrorLog(); log.createLogFile(ex); } }
//post data should contain the name of the report for example "Remaining_Inventory.jrxml" public String getReport(String postData) { byte[] byteArray = Encoding.UTF8.GetBytes(postData);//post data should contain the name of the report for example "Remaining_Inventory.jrxml" string strFileName = DateTime.Now.ToString("yyyyMMdd_hhmmss") + ".pdf"; WebRequest request = null; try { #if DEBUG request = WebRequest.Create("http://localhost:8084/JasperService/webresources/generic"); #else request = WebRequest.Create("http://10.0.0.10:8080/JasperService/webresources/generic"); #endif } catch(WebException ex) { ErrorLog log = new ErrorLog(); log.createLogFile(ex); } catch (Exception ex) { ErrorLog log = new ErrorLog(); log.createLogFile(ex); } if (request != null) { request.Method = "POST"; request.ContentType = "text/xml"; request.ContentLength = byteArray.Length; try { var dataStream = request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); } catch(Exception ex) { ErrorLog log = new ErrorLog(); log.createLogFile(ex); } } try { var response = (HttpWebResponse)request.GetResponse(); using (var stream = File.Create(strFileName)) { response.GetResponseStream().CopyTo(stream); return strFileName; } } catch (Exception ex) { ErrorLog log = new ErrorLog(); log.createLogFile(ex); return null; } }
private void cellEdited(object sender,EventArgs e) { try { ctx.SaveChanges(); } catch (Exception GenEx) { ErrorLog log = new ErrorLog(); log.createLogFile(GenEx); MessageBox.Show("Something Went Wrong\nSee Log For Details"); } ctx.SaveChanges(); }
private void btnAddOrUpdate_Click(object sender, EventArgs e) { if(row != null && btnAddOrUpdate.Text.Equals("Update")) { row.Cells[3].Value = cmbCategory.Text; row.Cells[4].Value = cmbStatus.Text; row.Cells[1].Value = txtIngredient.Text.ToString(); row.Cells[2].Value = txtMoisture.Value; try { ctx.SaveChanges(); } catch(Exception ex) { ErrorLog log = new ErrorLog(); log.createLogFile(ex); MessageBox.Show("Could Not Update"); } } if(btnAddOrUpdate.Text.Equals("Add")) { ingredient ing = new ingredient(); ing.category = cmbCategory.Text; ing.status= cmbStatus.Text; ing.ingredient1 = txtIngredient.Text.ToString(); ing.moisture = txtMoisture.Value; ctx.ingredients.Add(ing); try { ctx.SaveChanges(); clearToolStripMenuItem_Click(null, null); populateDgvIngredient(); } catch (Exception ex) { ErrorLog log = new ErrorLog(); log.createLogFile(ex); MessageBox.Show("Could Not Update"); } } }
private void BatchPreparationForm_Load(object sender, EventArgs e) { ctx = new PWIC_TEST_ONEEntities(); try { list = ctx.Dry_Ingredient_Use_Temp.ToList(); } catch(Exception ex) { MessageBox.Show("Please Restart The Application"); ErrorLog log = new ErrorLog(); log.createLogFile(ex); } }
private void setIngredientID() { using (var ctx = new PWIC_TEST_ONEEntities()) { string idToSet = Guid.NewGuid().ToString(); try { if (ctx.Raw_Mix_Ingredient_list.Any(o => o.ingredient_id == idToSet)) { setIngredientID(); } else { ingredient_id = idToSet; } } catch (EntityException entityException) { ErrorLog eLog = new ErrorLog(); eLog.createLogFile(entityException); MessageBox.Show("Could Not Connect to the database. See Log For Details"); } } }
private void confirmInitialRecipe() { bool success = true; // this.clearOldTempDryMixUse(); foreach (Dry_Ingredient_Use_Temp dt in listOfIngredients) { dt.litresToProduce = this.txtAmount.Value; dt.butterFat = this.txtButterFat.Value; dt.snf = this.txtSNF.Value; ctx.Dry_Ingredient_Use_Temp.Add(dt); //if (diut != null) //{ // diut.Add(dt); //} //else //{ // ctx.Dry_Ingredient_Use_Temp.Add(dt); //} } try { ctx.SaveChanges(); lblNotification.Text = "Done"; lblNotification.ForeColor = Color.Green; } catch(Exception ex) { ErrorLog log = new ErrorLog(); log.createLogFile(ex); } //if (diut != null) //{ // foreach (Dry_Ingredient_Use_Temp d in diut) // { // ctx.Dry_Ingredient_Use_Temp.Add(d); // } // try // { // ctx.SaveChanges(); // //Form form = new BatchPreparationForm(); // //form.ShowDialog(); // } // catch (Exception ex) // { // this.removeAllLabels(this.listOfLabelsToRemove); // //removeAllIngredients(); // this.locationOnTheForm = 2; // success = false; // MessageBox.Show("Something Went Wrong \nfrom confirminitialRecipe method", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); // } //} }
//this is the final save /// <summary> /// this is the final save. /// </summary> private void saveToDryIngredientUse() { string strMessage = ""; foreach(RawMixIngredient ing in listOfIngredientsAndQuantities) { if(ing.lotCodes.Count < 1 && ing.name != "Water") { strMessage += ing.name + " doesn't have a lot code\n"; } } //if (!String.IsNullOrEmpty(strMessage)) //{ // strMessage = "One Or More Ingredients does not have a lot code associated with it.\nWill Not Save"; // MessageBox.Show(strMessage); //} //else //{ foreach (RawMixIngredient ing in listOfIngredientsAndQuantities) { foreach (LotCode l in ing.lotCodes) { Dry_Ingredient_Use d = new Dry_Ingredient_Use(); d.Lot_Code = l.lotCode; d.bags_used = l.quantity; d.mix_date = DateTime.Today; d.litres_produced = txtAmount.Value; d.flavour = cmbRecipeName.Text; d.PT_Number = Convert.ToInt32(txtPtNumber.Value); d.ingredient = l.ingredientName; d.purchase_order_number = ing.purchaseOrderNumber; ctx.Dry_Ingredient_Use.Add(d); } } try { ctx.SaveChanges(); MessageBox.Show("Your mix has been saved", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); try { ctx.Database.ExecuteSqlCommand("delete from dbo.Dry_Ingredient_Use_Temp"); reloadForm(); } catch (Exception deletingFromTempGeneralException) { ErrorLog log = new ErrorLog(); log.createLogFile(deletingFromTempGeneralException); MessageBox.Show(deletingFromTempGeneralException.ToString()); } } catch (Exception savingToAddUseGeneralException) { ErrorLog eLog = new ErrorLog(); eLog.createLogFile(savingToAddUseGeneralException); MessageBox.Show("Failed. Please see log for details.", "Can't Continue", MessageBoxButtons.OK, MessageBoxIcon.Error); } //TODO: save to the three new table to be able to reproduce the report // } }
private void btnAdd_Click(object sender, EventArgs e) { if (txtBagsUsed.Value != 0) { Dry_Ingredient_Use_Temp ingredientToSave = new Dry_Ingredient_Use_Temp(); ingredientToSave.ingredient = cmbIngredientUseIngredient.Text.ToString(); ingredientToSave.Lot_Code = cmbLotCode.Text.ToString(); ingredientToSave.mix_date = today.Date; ingredientToSave.recipe_ID = recipe_id; ingredientToSave.recipe_name = cmbRecipeName.Text.ToString(); ingredientToSave.total_amount = dcmlTotalKG; ingredientToSave.bags_used = Convert.ToDecimal(txtBagsUsed.Text); ingredientToSave.PT_Number = Convert.ToInt32(this.txtPtNumber.Value); ingredientToSave.rowNumber = 999; ingredientToSave.totalWeightForLotCode = Convert.ToDecimal(txtBagsUsed.Text); ingredientToSave.totalWeightForRecipe = Convert.ToDecimal(txtBagsUsed.Text); ingredientToSave.totalBagsForRecipe = Convert.ToDecimal(txtBagsUsed.Text); ingredientToSave.litresToProduce = this.txtAmount.Value; ingredientToSave.butterFat = this.txtButterFat.Value; ingredientToSave.snf = this.txtSNF.Value; try { ctx.Dry_Ingredient_Use_Temp.Add(ingredientToSave); } catch (Exception ex) { ErrorLog log = new ErrorLog(); log.createLogFile(ex); } try { ctx.SaveChanges(); lblNotification.Text = "Done"; lblNotification.ForeColor = Color.Green; } catch (Exception ex) { ErrorLog log = new ErrorLog(); log.createLogFile(ex); } this.btnLoad_Click(null, null); } }
private void deleteFromRawMix() { foreach(Raw_Mix_Ingredient_Lot_code l in ctx.Raw_Mix_Ingredient_Lot_code.Where(o => o.mix_id == mix_id).ToList()) { ctx.Raw_Mix_Ingredient_Lot_code.Remove(l); } foreach(Raw_Mix_Ingredient_list l in ctx.Raw_Mix_Ingredient_list.Where(o => o.mix_id == mix_id).ToList()) { ctx.Raw_Mix_Ingredient_list.Remove(l); } foreach(Raw_Mix r in ctx.Raw_Mix.Where(o => o.mix_id == mix_id).ToList()) { ctx.Raw_Mix.Remove(r); } try { ctx.SaveChanges(); MessageBox.Show("Deleted", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); reloadForm(); } catch(Exception ex) { ErrorLog log = new ErrorLog(); log.createLogFile(ex); MessageBox.Show(ex.ToString()); } }
private void deleteFromUseTemp() { try { ctx.Database.ExecuteSqlCommand("delete from dbo.Dry_Ingredient_Use_Temp"); reloadForm(); } catch (Exception deletingFromTempGeneralException) { ErrorLog log = new ErrorLog(); log.createLogFile(deletingFromTempGeneralException); MessageBox.Show(deletingFromTempGeneralException.ToString()); } }
private void setMixId() { mix_id = Guid.NewGuid().ToString(); try { if (ctx.Raw_Mix.Any(o => o.mix_id == mix_id)) { setMixId(); } } catch(EntityException entityException) { ErrorLog eLog = new ErrorLog(); eLog.createLogFile(entityException); MessageBox.Show("Could Not Connect to the database. See Log For Details", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private string setIngredientID() { string ingredient_id = Guid.NewGuid().ToString(); try { if (ctx.Raw_Mix_Ingredient_list.Any(o => o.mix_id == mix_id)) { setIngredientID(); } return ingredient_id; } catch (EntityException entityException) { ErrorLog eLog = new ErrorLog(); eLog.createLogFile(entityException); MessageBox.Show("Could Not Connect to the database. See Log For Details", "Can't Continue", MessageBoxButtons.OK, MessageBoxIcon.Error); return null; } }
private void saveToRawMixTable(bool isFinished) { if (isNew) { //saveto raw mix table isNew = false; Raw_Mix mix = new Raw_Mix(); mix.mix_id = mix_id; mix.mix_date = DateTime.Today; mix.mix_name = cmbRecipeName.Text; mix.butter_fat = txtButterFat.Value; mix.snf = txtSNF.Value; mix.pt_number = Convert.ToInt32(txtPtNumber.Value); mix.pt_wash_Date = dtPtWashDate.Value; mix.pt_wash_time = dtPtWashTime.Value.ToString("HHmmss"); mix.sanitized_date = dtSanitizedDate.Value; mix.sanitized_time = dtSanitizedTime.Value.ToString("HHmmss"); mix.agitator_verification = Convert.ToBoolean(cmbAgitatorVerification.SelectedValue); mix.cooling_Verification = Convert.ToBoolean(cmbCoolingVerification.SelectedValue); mix.cream_Tank_Number = Convert.ToInt32(txtPtNumber.Value); mix.mix_maker = txtMixMaker.Text; mix.litresToProduce = Convert.ToInt32(txtAmount.Value); mix.totalWeight = dcmlTotalWeight; mix.finished = isFinished; ctx.Raw_Mix.Add(mix); foreach (RawMixIngredient r in listOfIngredientsAndQuantities) { //save to Raw_Mix_Ingredient_list table Raw_Mix_Ingredient_list i = new Raw_Mix_Ingredient_list(); i.ingredient = r.name; i.mix_id = mix_id; i.quantity = r.quantity; i.ingredient_weight = r.weight; i.ingredient_id = r.ingredient_id; i.ord = orderTheIngredients(r.name); #region order of ingredients //switch (r.name) //{ // case "Cream": // i.ord = 10; // break; // case "Glucose": // i.ord = 20; // break; // case "Whey": // i.ord = 30; // break; // case "Skim Powder": // i.ord = 35; // break; // case "Sugar": // i.ord = 40; // break; // case "DI 15 Stabilizer": // i.ord = 50; // break; // case "CCC360 Stabilizer": // i.ord = 55; // break; // case "Annatto Yellow #170": // i.ord = 60; // break; // case "Egg Yellow": // i.ord = 65; // break; // case "CP5303 Cocoa": // i.ord = 70; // break; // case "CP5171 Cocoa": // i.ord = 75; // break; // case "Water": // i.ord = 999; // break; // default: // i.ord = 998; // break; //} #endregion foreach (LotCode l in r.lotCodes) { //save to Raw_Mix_Ingredient_Lot_code table Raw_Mix_Ingredient_Lot_code lc = new Raw_Mix_Ingredient_Lot_code(); lc.ingredient_id = i.ingredient_id; lc.mix_id = mix_id; lc.lot_code = l.lotCode; lc.quantity = l.quantity; lc.po_Number = l.po; ctx.Raw_Mix_Ingredient_Lot_code.Add(lc); } ctx.Raw_Mix_Ingredient_list.Add(i); } try { ctx.SaveChanges(); MessageBox.Show("The Mix Has Been Tentatively Saved", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (DbEntityValidationException ex) { ErrorLog log = new ErrorLog(); log.createLogFile(ex); MessageBox.Show("Something Went Wrong When saving to the three tables.", "Can't Continue", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { ErrorLog log = new ErrorLog(); log.createLogFile(ex); MessageBox.Show("Something Went Wrong When saving to the three tables.", "Can't Continue", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else//this is executed when the mix is updated and not created { Raw_Mix rm = ctx.Raw_Mix.Where(o => o.mix_id == mix_id).FirstOrDefault(); if(isFinished != rm.finished) { rm.finished = isFinished; ctx.SaveChanges(); } //remove whatever is in there right now. foreach (Raw_Mix_Ingredient_list l in ctx.Raw_Mix_Ingredient_list.Where(o => o.mix_id == mix_id).ToList()) { ctx.Raw_Mix_Ingredient_list.Remove(l); } try { ctx.SaveChanges(); foreach (RawMixIngredient r in listOfIngredientsAndQuantities) { //save to Raw_Mix_Ingredient_list table Raw_Mix_Ingredient_list i = new Raw_Mix_Ingredient_list(); i.ingredient = r.name; i.mix_id = mix_id; i.quantity = r.quantity; i.ingredient_weight = r.weight; i.ingredient_id = r.ingredient_id; #region order of ingredients i.ord = orderTheIngredients(r.name); //switch (r.name) //{ // case "Cream": // i.ord = 1; // break; // case "Whey": // i.ord = 2; // break; // case "Glucose": // i.ord = 3; // break; // case "Sugar": // i.ord = 4; // break; // case "DI 15 Stabilizer": // i.ord = 5; // break; // case "CCC360 Stabilizer": // i.ord = 5; // break; // case "Annatto Yellow #170": // i.ord = 5; // break; // case "Egg Yellow": // i.ord = 5; // break; // case "CP5303 Cocoa": // i.ord = 5; // break; // case "CP5171 Cocoa": // i.ord = 5; // break; // case "Water": // i.ord = 6; // break; //} #endregion ctx.Raw_Mix_Ingredient_list.Add(i); } } catch(Exception ex) { } foreach (Raw_Mix_Ingredient_Lot_code l in ctx.Raw_Mix_Ingredient_Lot_code.Where(o => o.mix_id == mix_id).ToList()) { ctx.Raw_Mix_Ingredient_Lot_code.Remove(l); } try { ctx.SaveChanges(); foreach (RawMixIngredient r in listOfIngredientsAndQuantities) { //save to Raw_Mix_Ingredient_list table foreach (LotCode l in r.lotCodes) { //save to Raw_Mix_Ingredient_Lot_code table Raw_Mix_Ingredient_Lot_code lc = new Raw_Mix_Ingredient_Lot_code(); lc.ingredient_id = r.ingredient_id; lc.mix_id = mix_id; lc.lot_code = l.lotCode; lc.quantity = l.quantity; lc.po_Number = l.po; ctx.Raw_Mix_Ingredient_Lot_code.Add(lc); } } try { ctx.SaveChanges(); } catch (DbEntityValidationException ex) { ErrorLog log = new ErrorLog(); log.createLogFile(ex); MessageBox.Show("Something Went Wrong When saving to the three tables.", "Can't Continue", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { ErrorLog log = new ErrorLog(); log.createLogFile(ex); MessageBox.Show("Something Went Wrong When saving to the three tables.", "Can't Continue", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch(Exception ex) { MessageBox.Show(ex.StackTrace); ErrorLog log = new ErrorLog(); log.createLogFile(ex); } } }
private void cellEdited(object sender,EventArgs e) { try { ctx.SaveChanges(); } catch(Exception ex) { ErrorLog log = new ErrorLog(); log.createLogFile(ex); } }
private void clearDBandLists() { if (ctx.Dry_Ingredient_Use_Temp.Any()) { ctx.Database.ExecuteSqlCommand("delete from dbo.dry_ingredient_use_temp"); try { ctx.SaveChanges(); } catch (Exception ex) { ErrorLog log = new ErrorLog(); log.createLogFile(ex); } } if (diut != null) { diut = null; diut = new List<Dry_Ingredient_Use_Temp>(); } if(listOfIngredients != null) { listOfIngredients = null; listOfIngredients = new List<Dry_Ingredient_Use_Temp>(); } }
private void presistToTable() { //get all dataGrdiViews in the form foreach (DataGridView d in this.flowPanel.Controls.OfType<DataGridView>()) { //get rows in the dgv foreach(DataGridViewRow dgvr in d.Rows) { Raw_Mix_Batch batch = new Raw_Mix_Batch(); if (dgvr.Cells[0].Value != null) { batch.ingredient = dgvr.Cells[0].Value.ToString(); } if(dgvr.Cells[1].Value != null) { //batch.amount = Convert.ToDecimal(dgvr.Cells[1].Value); } if(dgvr.Cells[2].Value != null) { batch.batch_number = Convert.ToInt32(dgvr.Cells[2].Value); } if(batch.ingredient != null && batch.amount != null && batch.batch_number != null) { ctx.Raw_Mix_Batch.Add(batch); } } } try { ctx.SaveChanges(); } catch(Exception ex) { ErrorLog log = new ErrorLog(); log.createLogFile(ex); } }
private void populateRemainingInventory() { List<remaining_inventory> list; try { list = ctx.remaining_inventory.ToList(); var bindingList = new BindingList<remaining_inventory>(list); var source = new BindingSource(bindingList, null); dgvRemainingInventory.DataSource = source; dgvRemainingInventory.Columns[0].Visible = false; dgvRemainingInventory.Columns[1].Visible = false; dgvRemainingInventory.Columns[2].Visible = false; dgvRemainingInventory.Columns[5].Visible = false; dgvRemainingInventory.Columns[7].Visible = false; dgvRemainingInventory.Columns[6].DisplayIndex = 0; dgvRemainingInventory.Columns[4].DisplayIndex = 1; dgvRemainingInventory.Columns[3].DisplayIndex = 2; dgvRemainingInventory.Columns[8].DisplayIndex = 3; dgvRemainingInventory.Columns[9].DisplayIndex = 4; } catch (Exception ex) { ErrorLog log = new ErrorLog(); log.createLogFile(ex); System.Threading.Thread.Sleep(1000); this.populateRemainingInventory(); } }