private void RefeshProductImportList(int id) { IList data = new ArrayList(); var total = 0.0; foreach (RepeaterItem item in rptProductList.Items) { IvProductImport productImport = new IvProductImport(); HiddenField hddProductImportId = (HiddenField)item.FindControl("hddProductImportId"); HiddenField hddProductId = (HiddenField)item.FindControl("hddProductId"); TextBox txtCodeProduct = (TextBox)item.FindControl("txtCodeProduct"); TextBox txtQuantity = (TextBox)item.FindControl("txtQuantity"); TextBox txtUnitPrice = (TextBox)item.FindControl("txtUnitPrice"); TextBox txtItemTotal = (TextBox)item.FindControl("txtTotal"); var ddlUnit = (DropDownList)item.FindControl("ddlUnit"); if (!string.IsNullOrEmpty(hddProductImportId.Value)) { productImport.Id = Convert.ToInt32(hddProductImportId.Value); } if (!string.IsNullOrEmpty(txtCodeProduct.Text)) { productImport.Product = Module.IvProductGetByCode(txtCodeProduct.Text.Trim(), _currentImport.Storage); } if (!string.IsNullOrEmpty(hddProductId.Value)) { productImport.Product = Module.GetById <IvProduct>(Convert.ToInt32(hddProductId.Value)); } if (!string.IsNullOrEmpty(txtUnitPrice.Text)) { productImport.UnitPrice = Convert.ToDouble(txtUnitPrice.Text); } if (!string.IsNullOrEmpty(txtQuantity.Text)) { productImport.Quantity = Convert.ToInt32(txtQuantity.Text); } if (!string.IsNullOrEmpty(txtItemTotal.Text)) { productImport.Total = Convert.ToDouble(txtItemTotal.Text); } if (!string.IsNullOrEmpty(ddlUnit.SelectedValue)) { productImport.Unit = Module.GetById <IvUnit>(Convert.ToInt32(ddlUnit.SelectedValue)); } productImport.Import = CurrentImport; if (productImport.Id != id) { total += productImport.Total; data.Add(productImport); } } rptProductList.DataSource = data; rptProductList.DataBind(); txtGrandTotal.Text = string.Format("{0:0.00}", total); rptProductListItems.Value = data.Count.ToString(); }
protected void rptProductList_ItemCommand(object sender, RepeaterCommandEventArgs e) { switch (e.CommandName.ToLower()) { case "delete": var hddProductImportId = e.Item.FindControl("hddProductImportId") as HiddenField; if (hddProductImportId != null && !string.IsNullOrEmpty(hddProductImportId.Value)) { IvProductImport productImport = Module.GetById <IvProductImport>(Convert.ToInt32(hddProductImportId.Value)); Module.Delete(productImport); RefeshProductImportList(Convert.ToInt32(hddProductImportId.Value)); } break; default: break; } }
public void PushImport(string imports) { InventoryServRes res = new InventoryServRes(); res.BillFails = new List <int>(); res.ProductFails = new List <int>(); res.BillProductFails = new Dictionary <int, int>(); try { if (!string.IsNullOrWhiteSpace(imports)) { var importDtos = JsonConvert.DeserializeObject <List <ImportDTO> >(imports); if (importDtos.Count > 0) { foreach (var r in importDtos) { var count = Module.IvImportCheckByCode(r.Code); if (count <= 0) { var import = new IvImport(); try { if (r.ImportId > 0) { import = Module.GetById <IvImport>(r.ImportId); } import.ModifiedDate = r.ModifiedDate; import.Name = r.Name; import.Code = r.Code; import.CreatedDate = r.CreatedDate; import.ImportedBy = r.ImportedBy; import.Deleted = r.Deleted; import.Detail = r.Detail; if (r.StorageId > 0) { import.Storage = Module.IvStorageGetById(r.StorageId); } import.ImportDate = r.ImportDate; import.Total = r.Total; if (r.AgencyId > 0) { import.Agency = Module.GetById <Agency>(r.AgencyId); } if (r.CruiseId > 0) { import.Cruise = Module.CruiseGetById(r.CruiseId); } Module.SaveOrUpdate(import); var isInsertProductSuccess = true; if (r.ImportProducts.Count > 0) { foreach (var p in r.ImportProducts) { try { var productImport = new IvProductImport(); if (p.ImportProductId > 0) { productImport = Module.GetById <IvProductImport>(p.ImportProductId); } productImport.Import = import; if (p.ProductId > 0) { productImport.Product = Module.IvProductGetById(p.ProductId); } productImport.Quantity = p.Quantity; if (p.StorageId > 0) { productImport.Storage = Module.IvStorageGetById(p.StorageId); } productImport.Total = p.Total; productImport.UnitPrice = p.UnitPrice; if (p.UnitId > 0) { productImport.Unit = Module.IvUnitGetById(p.UnitId); } Module.SaveOrUpdate(productImport); } catch (Exception e) { isInsertProductSuccess = false; res.ProductFails.Add(p.Id); } } } if (!isInsertProductSuccess) { res.BillProductFails.Add(r.Id, import.Id); res.BillFails.Add(r.Id); } } catch (Exception e) { res.BillFails.Add(r.Id); } } } } } res.Status = "1"; HttpContext.Current.Response.ContentType = "application/json"; HttpContext.Current.Response.Charset = "utf-8"; HttpContext.Current.Response.Write(JsonConvert.SerializeObject(res)); } catch (Exception e) { res.Status = "0"; HttpContext.Current.Response.ContentType = "application/json"; HttpContext.Current.Response.Charset = "utf-8"; HttpContext.Current.Response.Write(JsonConvert.SerializeObject(res)); } }
protected void btnSaveProductImport_Click(object sender, EventArgs e) { try { #region ---Save Current Export--- CurrentImport.Name = txtName.Text; int flag = Module.CountImportGetByCode(Request.QueryString, UserIdentity, txtCode.Text); if (flag > 0 && CurrentImport.Id <= 0) { ShowError("Mã phiếu đã tồn tại"); return; } _currentImport.Code = txtCode.Text; _currentImport.Detail = txtDetail.Text; if (!string.IsNullOrWhiteSpace(ddlAgency.SelectedValue)) { _currentImport.Agency = Module.AgencyGetById(Convert.ToInt32(ddlAgency.SelectedValue)); } _currentImport.ImportedBy = txtImportBy.Text; if (!string.IsNullOrEmpty(txtImportedDate.Text)) { _currentImport.ImportDate = DateTime.ParseExact(txtImportedDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture); } else { _currentImport.ImportDate = DateTime.Now; } IvStorage storage = null; if (!string.IsNullOrEmpty(ddlStorage.SelectedValue)) { storage = Module.GetById <IvStorage>(Convert.ToInt32(ddlStorage.SelectedValue)); } _currentImport.Storage = storage; if (storage != null && storage.Cruise != null) { _currentImport.Cruise = storage.Cruise; } Module.SaveOrUpdate(_currentImport, UserIdentity); #endregion double sum = 0; foreach (RepeaterItem item in rptProductList.Items) { HiddenField hddProductImportId = (HiddenField)item.FindControl("hddProductImportId"); HiddenField hddProductId = (HiddenField)item.FindControl("hddProductId"); TextBox txtCodeProduct = (TextBox)item.FindControl("txtCodeProduct"); TextBox txtQuantity = (TextBox)item.FindControl("txtQuantity"); TextBox txtUnitPrice = (TextBox)item.FindControl("txtUnitPrice"); var ddlUnit = (DropDownList)item.FindControl("ddlUnit"); if (!string.IsNullOrEmpty(hddProductImportId.Value)) { int id = Convert.ToInt32(hddProductImportId.Value); IvProductImport productImport = Module.GetById <IvProductImport>(id); productImport.Product = Module.IvProductGetByCode(txtCodeProduct.Text.Trim(), _currentImport.Storage); if (!string.IsNullOrWhiteSpace(hddProductId.Value)) { productImport.Product = Module.GetById <IvProduct>(Convert.ToInt32(hddProductId.Value)); } if (!string.IsNullOrWhiteSpace(ddlUnit.SelectedValue)) { productImport.Unit = Module.GetById <IvUnit>(Convert.ToInt32(ddlUnit.SelectedValue)); } if (!string.IsNullOrWhiteSpace(txtQuantity.Text)) { productImport.Quantity = Convert.ToInt32(txtQuantity.Text); } if (!string.IsNullOrWhiteSpace(txtUnitPrice.Text)) { productImport.UnitPrice = Convert.ToDouble(txtUnitPrice.Text); } if (!string.IsNullOrWhiteSpace(txtQuantity.Text) && !string.IsNullOrWhiteSpace(txtUnitPrice.Text)) { productImport.Total = Convert.ToInt32(txtQuantity.Text) * Convert.ToDouble(txtUnitPrice.Text); } productImport.Import = CurrentImport; productImport.Storage = storage; sum += productImport.Total; if (productImport.Product != null && productImport.Product.Id > 0) { Module.SaveOrUpdate(productImport, UserIdentity); } } else { IvProductImport productImport = new Domain.IvProductImport(); productImport.Product = Module.IvProductGetByCode(txtCodeProduct.Text.Trim(), _currentImport.Storage); if (!string.IsNullOrWhiteSpace(hddProductId.Value)) { productImport.Product = Module.GetById <IvProduct>(Convert.ToInt32(hddProductId.Value)); } if (ddlUnit != null && !string.IsNullOrWhiteSpace(ddlUnit.SelectedValue)) { productImport.Unit = Module.GetById <IvUnit>(Convert.ToInt32(ddlUnit.SelectedValue)); } if (!string.IsNullOrWhiteSpace(txtQuantity.Text)) { productImport.Quantity = Convert.ToInt32(txtQuantity.Text); } if (!string.IsNullOrWhiteSpace(txtUnitPrice.Text)) { productImport.UnitPrice = Convert.ToDouble(txtUnitPrice.Text); } if (!string.IsNullOrWhiteSpace(txtQuantity.Text) && !string.IsNullOrWhiteSpace(txtUnitPrice.Text)) { productImport.Total = Convert.ToInt32(txtQuantity.Text) * Convert.ToDouble(txtUnitPrice.Text); } productImport.Import = CurrentImport; productImport.Storage = storage; sum += productImport.Total; if (productImport.Product != null && productImport.Product.Id > 0) { Module.SaveOrUpdate(productImport, UserIdentity); } } } CurrentImport.Total = sum; Module.SaveOrUpdate(CurrentImport, UserIdentity); BindrptProductImportList(); PageRedirect(string.Format("IvImportAdd.aspx?NodeId={0}&SectionId={1}&ImportId={2}", Node.Id, Section.Id, _currentImport.Id)); } catch (Exception ex) { ShowErrors(ex.Message); } }