private bool ManageAdjustmentDetail(int?PK, eRepeaterOperation RepeaterOperation) { #region Check Same Product var lstCheckProductId = new List <int>(); if (RepeaterOperation == eRepeaterOperation.Validate) { foreach (RepeaterItem Item in rptAdjustmentDetail.Items) { var ddlProduct = Item.FindControl("ddlProduct") as DropDownList; if (ddlProduct.zIsSelect()) { if (lstCheckProductId.Contains(ddlProduct.zToInt().Value)) { ddlProduct.Focus(); CU.ZMessage(eMsgType.Error, string.Empty, "This Product is Repeat in Same Adjustment Please Marge Same Product."); return(false); } lstCheckProductId.Add(ddlProduct.zToInt().Value); } } } #endregion var lstAdjProduct = new List <AdjProduct>(); var dtItemAdjustmentDetail = new DataTable(); int ItemAdjustmentId = lblItemAdjustmentId.zToInt().HasValue ? lblItemAdjustmentId.zToInt().Value : 0; if (RepeaterOperation == eRepeaterOperation.Save) { dtItemAdjustmentDetail = new ItemAdjustmentDetail() { ItemAdjustmentId = ItemAdjustmentId, }.Select(); } if (RepeaterOperation == eRepeaterOperation.Select) { #region Get Data From DB dtItemAdjustmentDetail = new ItemAdjustmentDetail() { ItemAdjustmentId = ItemAdjustmentId, }.Select(); var dtItemAdjustmentDetailProduct = dtItemAdjustmentDetail.DefaultView.ToTable(true, CS.ProductId); var lstProductId = new List <int>(); foreach (DataRow drItemAdjustmentDetailProduct in dtItemAdjustmentDetailProduct.Rows) { lstProductId.Add(drItemAdjustmentDetailProduct[CS.ProductId].zToInt().Value); } var dtItem = new Query() { ProductIdIn = CU.GetParaIn(lstProductId, true) }.Select(eSP.qry_Item); foreach (DataRow drItemAdjustmentDetailProduct in dtItemAdjustmentDetailProduct.Rows) { var lstAdjProductItem = new List <AdjProductItem>(); foreach (DataRow drItem in dtItem.Select(CS.ProductId + "=" + drItemAdjustmentDetailProduct[CS.ProductId].zToInt())) { int? ItemAdjustmentDetailId = null; decimal?Quantity = null, Rate = null; var drItemAdjustmentDetailtem = dtItemAdjustmentDetail.Select(CS.ProductId + "=" + drItemAdjustmentDetailProduct[CS.ProductId].zToInt() + " AND " + CS.ItemId + "=" + drItem[CS.ItemId].zToInt()); if (drItemAdjustmentDetailtem.Length > 0) { ItemAdjustmentDetailId = drItemAdjustmentDetailtem[0][CS.ItemAdjustmentDetailId].zToInt(); Quantity = drItemAdjustmentDetailtem[0][CS.Quantity].zToDecimal(); Rate = drItemAdjustmentDetailtem[0][CS.Rate].zToDecimal(); } lstAdjProductItem.Add(new AdjProductItem() { ItemAdjustmentDetailId = ItemAdjustmentDetailId, ItemId = drItem[CS.ItemId].zToInt().Value, ItemName = drItem[CS.ItemName].ToString(), Quantity = Quantity, Rate = Rate, }); } lstAdjProduct.Add(new AdjProduct() { ProductId = drItemAdjustmentDetailProduct[CS.ProductId].zToInt().Value, lstAdjProductItem = lstAdjProductItem, }); } #endregion } else { #region Manage Data foreach (RepeaterItem Item in rptAdjustmentDetail.Items) { var lblPK = Item.FindControl("lblPK") as Label; if (RepeaterOperation == eRepeaterOperation.Remove && PK == lblPK.zToInt()) { continue; } var ddlProduct = Item.FindControl("ddlProduct") as DropDownList; var rptAdjustmentItemDetail = Item.FindControl("rptAdjustmentItemDetail") as Repeater; if (RepeaterOperation == eRepeaterOperation.Add || RepeaterOperation == eRepeaterOperation.Refresh || RepeaterOperation == eRepeaterOperation.Remove) { #region Get Old Data #region Product Item var lstAdjProductItem = new List <AdjProductItem>(); foreach (RepeaterItem ItemAdjustmentItemDetail in rptAdjustmentItemDetail.Items) { var lblItemId = ItemAdjustmentItemDetail.FindControl("lblItemId") as Label; var lblItemName = ItemAdjustmentItemDetail.FindControl("lblItemName") as Label; var txtQuantity = ItemAdjustmentItemDetail.FindControl("txtQuantity") as TextBox; var txtRate = ItemAdjustmentItemDetail.FindControl("txtRate") as TextBox; lstAdjProductItem.Add(new AdjProductItem() { ItemId = lblItemId.zToInt().Value, ItemName = lblItemName.Text, Quantity = txtQuantity.zToDecimal(), Rate = txtRate.zToDecimal(), }); } #endregion lstAdjProduct.Add(new AdjProduct() { ProductId = ddlProduct.zToInt().Value, lstAdjProductItem = lstAdjProductItem }); #endregion } else if (RepeaterOperation == eRepeaterOperation.Validate) { #region Validate //if (ddlProduct.zIsSelect()) //{ // foreach (RepeaterItem ItemAdjustmentItemDetail in rptAdjustmentItemDetail.Items) // { // var txtQuantity = ItemAdjustmentItemDetail.FindControl("txtQuantity") as TextBox; // var txtRate = ItemAdjustmentItemDetail.FindControl("txtRate") as TextBox; // if (!txtQuantity.zIsDecimal(true)) // { // txtQuantity.Focus(); // CU.ZMessage(eMsgType.Error, string.Empty, "Please Enter Quantity"); // return false; // } // } //} #endregion } else if (RepeaterOperation == eRepeaterOperation.Save) { #region Save Data if (ddlProduct.zIsSelect()) { foreach (RepeaterItem ItemAdjustmentItemDetail in rptAdjustmentItemDetail.Items) { var lblItemAdjustmentDetailId = ItemAdjustmentItemDetail.FindControl("lblItemAdjustmentDetailId") as Label; var lblItemId = ItemAdjustmentItemDetail.FindControl("lblItemId") as Label; var lblItemName = ItemAdjustmentItemDetail.FindControl("lblItemName") as Label; var txtQuantity = ItemAdjustmentItemDetail.FindControl("txtQuantity") as TextBox; var txtRate = ItemAdjustmentItemDetail.FindControl("txtRate") as TextBox; if (txtQuantity.zIsDecimal(true)) { var objItemAdjustmentDetail = new ItemAdjustmentDetail() { ItemAdjustmentDetailId = lblItemAdjustmentDetailId.zToInt(), ItemAdjustmentId = lblItemAdjustmentId.zToInt(), ProductId = ddlProduct.zToInt(), ItemId = lblItemId.zToInt(), Quantity = txtQuantity.zToDecimal(), Rate = txtRate.zToDecimal(), }; CU.AdjustStock(objItemAdjustmentDetail, true); if (objItemAdjustmentDetail.ItemAdjustmentDetailId.HasValue && objItemAdjustmentDetail.ItemAdjustmentDetailId > 0) { var drItemAdjustmentDetail = dtItemAdjustmentDetail.Select(CS.ItemAdjustmentDetailId + "=" + objItemAdjustmentDetail.ItemAdjustmentDetailId); if (drItemAdjustmentDetail.Length > 0) { dtItemAdjustmentDetail.Rows.Remove(drItemAdjustmentDetail[0]); } } } } } #endregion } } #endregion } if (RepeaterOperation == eRepeaterOperation.Add || RepeaterOperation == eRepeaterOperation.Refresh || RepeaterOperation == eRepeaterOperation.Remove || RepeaterOperation == eRepeaterOperation.Select) { #region Manage And Bind Data if (RepeaterOperation == eRepeaterOperation.Add || lstAdjProduct.Count == 0) { for (int i = 0; i < 5; i++) { lstAdjProduct.Add(new AdjProduct() { }); } } dtProduct = new Query() { eStatus = (int)eStatus.Active, OrganizationId = lblOrganizationId.zToInt() }.Select(eSP.qry_Product); var drProduct = dtProduct.NewRow(); drProduct[CS.ProductId] = "0"; drProduct[CS.ProductCode] = "-- Select Product --"; dtProduct.Rows.InsertAt(drProduct, 0); rptAdjustmentDetail.DataSource = lstAdjProduct; rptAdjustmentDetail.DataBind(); #endregion } else if (RepeaterOperation == eRepeaterOperation.Save) { #region Save Data foreach (DataRow drItemAdjustmentDetail in dtItemAdjustmentDetail.Rows) { CU.AdjustStockDelete(drItemAdjustmentDetail[CS.ItemAdjustmentDetailId].zToInt().Value); } #endregion } return(true); }
private bool ManageShippingCharge(int?PK, eRepeaterOperation RepeaterOperation) { var dtShippingCharge = new DataTable(); var lstShippingChargeInsert = new List <ShippingCharge>(); var lstShippingChargeUpdate = new List <ShippingCharge>(); int CourierId = lblCourierId.zToInt().Value; if (RepeaterOperation == eRepeaterOperation.Save) { dtShippingCharge = new Query() { FirmId = lblFirmId.zToInt(), CourierId = CourierId, }.Select(eSP.qry_ShippingCharge); } else if (RepeaterOperation != eRepeaterOperation.Validate) { dtShippingCharge = new DataTable(); dtShippingCharge.Columns.Add(CS.eCourierType); dtShippingCharge.Columns.Add(CS.eZone); dtShippingCharge.Columns.Add(CS.Weight); dtShippingCharge.Columns.Add(CS.ShipCharge); dtShippingCharge.Columns.Add(CS.FirmShipCharge); } if (RepeaterOperation == eRepeaterOperation.Select) { #region Get Data From DB var dt = new Query() { FirmId = lblFirmId.zToInt(), CourierId = CourierId, }.Select(eSP.qry_ShippingCharge); foreach (DataRow dr in dt.Rows) { var drShippingCharge = dtShippingCharge.NewRow(); drShippingCharge[CS.eCourierType] = dr[CS.eCourierType].ToString(); drShippingCharge[CS.eZone] = dr[CS.eZone].ToString(); drShippingCharge[CS.Weight] = dr[CS.Weight].ToString(); drShippingCharge[CS.ShipCharge] = dr[CS.ShipCharge].ToString(); drShippingCharge[CS.FirmShipCharge] = dr[CS.FirmShipCharge].ToString(); dtShippingCharge.Rows.Add(drShippingCharge); } #endregion } else { #region Manage Data foreach (RepeaterItem Item in rptShippingCharge.Items) { var lblPK = Item.FindControl("lblPK") as Label; var txtWeight = Item.FindControl("txtWeight") as TextBox; if (RepeaterOperation == eRepeaterOperation.Remove && PK == lblPK.zToInt()) { continue; } if (RepeaterOperation == eRepeaterOperation.Save && (!txtWeight.zIsDecimal(false) || txtWeight.zToDecimal() <= 0)) { continue; } var rptZone = Item.FindControl("rptZone") as Repeater; foreach (RepeaterItem ItemZone in rptZone.Items) { var rptCourierType = ItemZone.FindControl("rptCourierType") as Repeater; foreach (RepeaterItem ItemCourierType in rptCourierType.Items) { var lblCourierTypeId = ItemCourierType.FindControl("lblCourierTypeId") as Label; var lblZoneId = ItemCourierType.FindControl("lblZoneId") as Label; var txtShipCharge = ItemCourierType.FindControl("txtShipCharge") as TextBox; var txtFirmShipCharge = ItemCourierType.FindControl("txtFirmShipCharge") as TextBox; if (RepeaterOperation == eRepeaterOperation.Add || RepeaterOperation == eRepeaterOperation.Refresh || RepeaterOperation == eRepeaterOperation.Remove) { #region Get Old Data var drShippingCharge = dtShippingCharge.NewRow(); drShippingCharge[CS.eCourierType] = lblCourierTypeId.Text; drShippingCharge[CS.eZone] = lblZoneId.Text; drShippingCharge[CS.Weight] = txtWeight.Text; drShippingCharge[CS.ShipCharge] = txtShipCharge.Text; drShippingCharge[CS.FirmShipCharge] = txtFirmShipCharge.Text; dtShippingCharge.Rows.Add(drShippingCharge); #endregion } else if (RepeaterOperation == eRepeaterOperation.Validate) { #region Validate if (txtShipCharge.zToInt() > 0 || txtFirmShipCharge.zToInt() > 0) { if (!txtWeight.zIsDecimal(false) || txtWeight.zToDecimal() <= 0) { txtWeight.Focus(); CU.ZMessage(eMsgType.Error, string.Empty, "Please Enter Weight"); return(false); } if (!txtShipCharge.zIsDecimal(false) || txtShipCharge.zToDecimal() <= 0) { txtShipCharge.Focus(); CU.ZMessage(eMsgType.Error, string.Empty, "Please Enter Courier Charge"); return(false); } if (!txtFirmShipCharge.zIsDecimal(false) || txtFirmShipCharge.zToDecimal() <= 0) { txtFirmShipCharge.Focus(); CU.ZMessage(eMsgType.Error, string.Empty, "Please Enter Firm Courier Charge"); return(false); } } #endregion } else if (RepeaterOperation == eRepeaterOperation.Save) { #region Save Data if (txtShipCharge.zToInt() > 0 || txtFirmShipCharge.zToInt() > 0) { var objShippingCharge = new ShippingCharge() { ShippingChargeId = dtShippingCharge.Rows.Count > 0 ? dtShippingCharge.Rows[0][CS.ShippingChargeId].zToInt() : (int?)null, FirmId = lblFirmId.zToInt(), CourierId = CourierId, Weight = txtWeight.zToDecimal(), eCourierType = lblCourierTypeId.zToInt(), eZone = lblZoneId.zToInt(), ShipCharge = txtShipCharge.zToInt(), FirmShipCharge = txtFirmShipCharge.zToInt() }; if (objShippingCharge.ShippingChargeId.HasValue) { dtShippingCharge.Rows.RemoveAt(0); lstShippingChargeUpdate.Add(objShippingCharge); } else { lstShippingChargeInsert.Add(objShippingCharge); } } #endregion } } } } #endregion } if (RepeaterOperation == eRepeaterOperation.Add || RepeaterOperation == eRepeaterOperation.Refresh || RepeaterOperation == eRepeaterOperation.Remove || RepeaterOperation == eRepeaterOperation.Select) { #region Manage And Bind Data if (RepeaterOperation == eRepeaterOperation.Add || dtShippingCharge.Rows.Count == 0) { var drShippingCharge = dtShippingCharge.NewRow(); dtShippingCharge.Rows.Add(drShippingCharge); } dtCourierType = CU.GetEnumDt <eCourierType>(string.Empty); dtZone = CU.GetEnumDt <eZone>(string.Empty); dtShippingChargeData = dtShippingCharge; dtShippingCharge = dtShippingCharge.DefaultView.ToTable(true, CS.Weight); rptShippingCharge.DataSource = dtShippingCharge; rptShippingCharge.DataBind(); #endregion } else if (RepeaterOperation == eRepeaterOperation.Save) { #region Save Data var lstShippingChargeDelete = new List <ShippingCharge>(); foreach (DataRow dr in dtShippingCharge.Rows) { lstShippingChargeDelete.Add(new ShippingCharge() { ShippingChargeId = dr[CS.ShippingChargeId].zToInt() }); } lstShippingChargeInsert.Insert(); lstShippingChargeUpdate.Update(); lstShippingChargeDelete.Delete(); #endregion } return(true); }