private void butAddI_Click_1(object sender, EventArgs e) { Instrument ins = LqtUtil.GetComboBoxValue <Instrument>(comInstrumentI); if (ins != null) { MasterProduct pro = LqtUtil.GetComboBoxValue <MasterProduct>(comProductI); if (pro != null) { //if (! _consum.IsExsistProductUsage(ins.Id, pro.Id)) // { if (comPeriodI.SelectedValue != null) { if (!_consum.IsExsistUsageRatePerInst(ins.Id, pro.Id)) { ConsumableUsage cu = new ConsumableUsage(); cu.Period = comPeriodI.Text; cu.PerInstrument = true; cu.Product = pro; cu.Instrument = ins; cu.ProductUsageRate = 1; cu.MasterConsumable = _consum; _consum.ConsumableUsages.Add(cu); BindProductUsageI(); if (OnDataUsageEdit != null) { OnDataUsageEdit(this, new EventArgs()); } } } } } }
public HttpResponseMessage Post(ConsumableUsage value) { HttpResponseMessage response = null; ValidateModel(value); if (!ModelState.IsValid) { response = Request.CreateResponse(HttpStatusCode.BadRequest, GetModelErrors()); return(response); } try { service.Save(value); response = Request.CreateResponse(HttpStatusCode.Created, value); string uri = Url.Link("DefaultApi", new { id = value.Id }); response.Headers.Location = new Uri(uri); } catch (Exception ex) { response = Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message); } return(response); }
private void butAddP_Click(object sender, EventArgs e) { MasterProduct pro = LqtUtil.GetComboBoxValue <MasterProduct>(comProductP); if (pro != null) { if (comPeriodP.SelectedValue != null) { if (!_consum.IsExsistUsageRatePerPeriod(pro.Id)) { ConsumableUsage cu = new ConsumableUsage(); cu.Period = comPeriodP.SelectedValue.ToString(); cu.PerPeriod = true; cu.Product = pro; cu.ProductUsageRate = 1; cu.MasterConsumable = _consum; _consum.ConsumableUsages.Add(cu); BindProductUsageP(); if (OnDataUsageEdit != null) { OnDataUsageEdit(this, new EventArgs()); } } } } }
private void butAddT_Click(object sender, EventArgs e) { MasterProduct pro = LqtUtil.GetComboBoxValue <MasterProduct>(comProductT); if (pro != null) { if (!_consum.IsExsistUsageRatePerTest(pro.Id)) { if (txtNoofTest.Text != "0") { ConsumableUsage cu = new ConsumableUsage(); cu.NoOfTest = int.Parse(txtNoofTest.Text); cu.PerTest = true; cu.Product = pro; cu.ProductUsageRate = 1; cu.MasterConsumable = _consum; _consum.ConsumableUsages.Add(cu); BindProductUsage(); if (OnDataUsageEdit != null) { OnDataUsageEdit(this, new EventArgs()); } } } } }
private void butSave_Click(object sender, EventArgs e) { int count = 0; int error = 0; try { foreach (ImportProUsageData rd in _rdata) { if (!rd.IsExist) { ConsumableUsage pu = new ConsumableUsage(); // pu.Instrument = rd.Instrument; pu.Product = rd.Product; pu.ProductUsageRate = rd.Rate; if (rd.IsForTest) { pu.NoOfTest = rd.NoOfTest; pu.PerTest = rd.IsForTest; rd.Cons.ConsumableUsages.Add(pu); count++; } else if (rd.IsForPeriod) { pu.Period = rd.Period; pu.PerPeriod = rd.IsForPeriod; rd.Cons.ConsumableUsages.Add(pu); count++; } else if (rd.IsForInstrument) { pu.Period = rd.Period; pu.PerInstrument = rd.IsForInstrument; pu.Instrument = rd.Instrument; rd.Cons.ConsumableUsages.Add(pu); count++; } DataRepository.SaveOrUpdateConsumables(rd.Cons); } else { error++; } } MessageBox.Show(count + "Consumables are imported and saved successfully." + Environment.NewLine + error + " Consumables Failed.", "Importing", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } catch { MessageBox.Show("Error: Unable to imported and saved Consumables data.", "Importing", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { DataRepository.CloseSession(); } }
public HttpResponseMessage Put(Guid id, ConsumableUsage value) { ValidateModel(value); if (!ModelState.IsValid || value.Id != id) { return(Request.CreateResponse(HttpStatusCode.BadRequest, GetModelErrors())); } HttpResponseMessage response = null; try { service.Save(value); response = Request.CreateResponse(HttpStatusCode.OK); } catch (Exception ex) { response = Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message); } return(response); }
/// <summary> /// Maps the usage to model. Need to use automapper? /// </summary> /// <param name="usage">The usage.</param> /// <param name="details">The details.</param> /// <returns>EggFarmSystem.Models.ConsumableUsage.</returns> private ConsumableUsage MapUsageToModel(Models.Data.ConsumableUsage usage, List <Models.Data.ConsumableUsageDetail> details) { var model = new ConsumableUsage(); model.Id = usage.Id; model.Date = usage.Date; model.Total = usage.Total; model.Details = new List <ConsumableUsageDetail>(); foreach (var detail in details) { var detailModel = new ConsumableUsageDetail { ConsumableId = detail.ConsumableId, Count = detail.Count, HouseId = detail.HouseId, SubTotal = detail.SubTotal, UnitPrice = detail.UnitPrice }; model.Details.Add(detailModel); } return(model); }
/// <summary> /// Saves the specified model. /// </summary> /// <param name="model">The model.</param> /// <returns><c>true</c> if save success, <c>false</c> otherwise</returns> public void Save(ConsumableUsage model) { using (var db = factory.OpenDbConnection()) { using (var trans = db.OpenTransaction()) { bool isNew = model.IsNew; Models.Data.ConsumableUsage usage = null; if (isNew) { usage = db.FirstOrDefault <Models.Data.ConsumableUsage>(u => u.Date == model.Date); } else { usage = db.Query <Models.Data.ConsumableUsage>("Date = @Date and Id <> @Id", new { Date = model.Date, Id = model.Id.ToString() }) .FirstOrDefault(); } if (usage != null) { trans.Rollback(); throw new ServiceException("Usage_DuplicateDate"); } if (isNew) { model.Id = Guid.NewGuid(); } usage = Mapper.Map <ConsumableUsage, Models.Data.ConsumableUsage>(model); if (isNew) { db.InsertParam(usage); } else { db.UpdateParam(usage); } if (!isNew) { db.Delete <Models.Data.ConsumableUsageDetail>(where : "UsageId = {0}".Params(usage.Id.ToString())); } foreach (var detailModel in model.Details) { var detail = Mapper.Map <ConsumableUsageDetail, Models.Data.ConsumableUsageDetail>(detailModel); detail.UsageId = usage.Id; db.InsertParam(detail); } try { trans.Commit(); } catch (Exception ex) { trans.Rollback(); throw new ServiceException(ex.Message); } } } }