protected void btnAddNewProduct_Click(object sender, EventArgs e) { IList data = new ArrayList(); foreach (RepeaterItem item in rptProductList.Items) { Domain.IvProductImport productImport = new Domain.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; data.Add(productImport); } data.Add(new Domain.IvProductImport()); rptProductList.DataSource = data; _total = 0; rptProductList.DataBind(); rptProductListItems.Value = data.Count.ToString(); }
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); } }
protected void rptProductList_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.DataItem is Domain.IvProductImport) { Domain.IvProductImport productImport = (Domain.IvProductImport)e.Item.DataItem; double quantity = 0; double unitprice = 0; HiddenField hddId = e.Item.FindControl("hddProductImportId") as HiddenField; HiddenField hddProductId = e.Item.FindControl("hddProductId") as HiddenField; if (hddId != null) { if (productImport.Id > 0) { hddId.Value = productImport.Id.ToString(); } } if (hddProductId != null) { if (productImport.Product != null) { hddProductId.Value = productImport.Product.Id.ToString(); } } Label lblName = e.Item.FindControl("lblName") as Label; if (lblName != null) { if (productImport.Product != null) { lblName.Text = productImport.Product.Name; } else { lblName.Text = ""; } } TextBox txtUnitPrice = e.Item.FindControl("txtUnitPrice") as TextBox; TextBox txtQuantity = e.Item.FindControl("txtQuantity") as TextBox; TextBox txtItemTotal = e.Item.FindControl("txtTotal") as TextBox; var ddlUnit = (DropDownList)e.Item.FindControl("ddlUnit"); if (ddlUnit != null) { ddlUnit.DataSource = _ivUnits; ddlUnit.DataValueField = "Id"; ddlUnit.DataTextField = "NameTree"; ddlUnit.DataBind(); ddlUnit.Items.Insert(0, new ListItem(" -- chọn --", "")); if (productImport.Unit != null) { ddlUnit.SelectedValue = productImport.Unit.Id.ToString(); } } if (txtUnitPrice != null && txtQuantity != null && txtItemTotal != null) { if (productImport.UnitPrice > 0) { txtUnitPrice.Text = productImport.UnitPrice.ToString(); unitprice = Convert.ToDouble(productImport.UnitPrice.ToString()); } else { txtUnitPrice.Text = ""; } txtUnitPrice.Attributes.Add("onkeyup", string.Format("Calculate('{0}','{1}','{2}');", txtUnitPrice.ClientID, txtQuantity.ClientID, txtItemTotal.ClientID)); txtUnitPrice.Attributes.Add("onchange", string.Format("Calculate('{0}','{1}','{2}');", txtUnitPrice.ClientID, txtQuantity.ClientID, txtItemTotal.ClientID)); if (productImport.Quantity > 0) { txtQuantity.Text = productImport.Quantity.ToString(); quantity = Convert.ToDouble(productImport.Quantity.ToString()); } else { txtQuantity.Text = ""; } txtQuantity.Attributes.Add("onkeyup", string.Format("Calculate('{0}','{1}','{2}');", txtUnitPrice.ClientID, txtQuantity.ClientID, txtItemTotal.ClientID)); txtQuantity.Attributes.Add("onchange", string.Format("Calculate('{0}','{1}','{2}');", txtUnitPrice.ClientID, txtQuantity.ClientID, txtItemTotal.ClientID)); double total = quantity * unitprice; _total += total; txtItemTotal.Text = total.ToString(); } TextBox txtCodeProduct = e.Item.FindControl("txtCodeProduct") as TextBox; if (txtCodeProduct != null && lblName != null && txtUnitPrice != null && hddProductId != null) { if (productImport.Product != null) { txtCodeProduct.Text = productImport.Product.Code; } else { txtCodeProduct.Text = ""; } txtCodeProduct.Attributes.Add("onchange", string.Format("GetProduct('{0}','{1}','{2},{0},{3},{4}');", "ajaxloader", txtCodeProduct.ClientID, lblName.ClientID, txtUnitPrice.ClientID, hddProductId.ClientID)); txtCodeProduct.Attributes.Add("onfocus", string.Format("GetProduct('{0}','{1}','{2},{0},{3},{4}');", "ajaxloader", txtCodeProduct.ClientID, lblName.ClientID, txtUnitPrice.ClientID, hddProductId.ClientID)); } } txtGrandTotal.Text = _total.ToString("#,0.#"); txtTotal1.Text = _total.ToString("#,0.#"); }