protected void uiLinkButtonAddItem_Click(object sender, EventArgs e) { IStock.BLL.ClientReturnDetails detail = new IStock.BLL.ClientReturnDetails(); detail.AddNew(); detail.ClientReturnID = CurrentReturn.ClientReturnID; //if (uiDropDownListItems.SelectedIndex != -1) if (!string.IsNullOrEmpty(uiHiddenFieldCurrentItem.Value)) { //detail.ItemID = Convert.ToInt32(uiDropDownListItems.SelectedValue); detail.ItemID = Convert.ToInt32(uiHiddenFieldCurrentItem.Value); } else { uiPanelErrorItems.Visible = true; return; } try { detail.Quantity = Convert.ToInt32(uiTextBoxQty.Text); } catch (Exception ex) { return; } try { detail.Valid = Convert.ToInt32(uiTextBoxValid.Text); } catch (Exception ex) { return; } try { detail.ItemPrice = decimal.Parse(uiTextBoxPrice.Text); } catch (Exception ex) { return; } detail.Save(); uiPanelErrorItems.Visible = false; decimal price = 0; if (!CurrentReturn.IsColumnNull("Discount") && CurrentReturn.Discount != 0) { price = detail.ItemPrice * detail.Quantity * (CurrentReturn.Discount / 100); } else { price = detail.ItemPrice * detail.Quantity; } IStock.BLL.Clients client = new IStock.BLL.Clients(); client.LoadByPrimaryKey(CurrentReturn.ClientID); if (!client.IsColumnNull("StartCredit")) client.StartCredit -= price; else client.StartCredit = -price; client.Save(); IStock.BLL.Items item = new IStock.BLL.Items(); item.LoadByPrimaryKey(detail.ItemID); item.Quantity += detail.Valid; item.Save(); BindItems(); }
protected void uiGridViewItems_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "DeleteDetail") { IStock.BLL.ClientReturnDetails objData = new IStock.BLL.ClientReturnDetails(); objData.LoadByPrimaryKey(Convert.ToInt32(e.CommandArgument.ToString())); decimal price = 0; if (!objData.IsColumnNull("Discount") && objData.Discount != 0) { price = objData.ItemPrice * objData.Quantity * (objData.Discount / 100); } else { price = objData.ItemPrice * objData.Quantity; } IStock.BLL.Clients client = new IStock.BLL.Clients(); IStock.BLL.ClientReturns returns = new IStock.BLL.ClientReturns (); returns.LoadByPrimaryKey(objData.ClientReturnID); client.LoadByPrimaryKey(returns.ClientID); client.StartCredit += price; client.Save(); IStock.BLL.Items item = new IStock.BLL.Items(); item.LoadByPrimaryKey(objData.ItemID); if(!objData.IsColumnNull("Valid")) item.Quantity -= objData.Valid; item.Save(); objData.MarkAsDeleted(); objData.Save(); BindItems(); } }
protected void uiGridViewReturns_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "EditReturn") { IStock.BLL.ClientReturns objData = new IStock.BLL.ClientReturns(); objData.LoadByPrimaryKey(Convert.ToInt32(e.CommandArgument.ToString())); uiTextBoxCode.Text = objData.ReturnNo; uiTextBoxDate.Text = objData.ReturnDate.ToString("dd/MM/yyy"); uiDropDownListClients.SelectedValue = objData.ClientID.ToString(); uiDropDownListEmployee.SelectedValue = objData.EmployeeID.ToString(); if (!objData.IsColumnNull("Discount")) uiTextBoxDiscount.Text = objData.Discount.ToString(); uiPanelAllReturns.Visible = false; uiPanelEditReturn.Visible = true; uiPanelItems.Visible = true; CurrentReturn = objData; BindItems(); } else if (e.CommandName == "DeleteReturn") { try { IStock.BLL.ClientReturns objData = new IStock.BLL.ClientReturns(); objData.LoadByPrimaryKey(Convert.ToInt32(e.CommandArgument.ToString())); IStock.BLL.ClientReturnDetails details = new IStock.BLL.ClientReturnDetails(); details.GetClientReturnDetails(objData.ClientReturnID); details.MarkAsDeleted(); details.Save(); /* IStock.BLL.Clients client = new IStock.BLL.Clients(); client.LoadByPrimaryKey(objData.ClientID); client.StartCredit -= total; client.Save(); */ objData.MarkAsDeleted(); objData.Save(); CurrentReturn = null; BindReturns(); } catch (Exception ex) { uipanelError.Visible = true; } } }