protected void uiGridViewClients_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "EditClient") { IStock.BLL.Clients objData = new IStock.BLL.Clients(); objData.LoadByPrimaryKey(Convert.ToInt32(e.CommandArgument.ToString())); uiTextBoxName.Text = objData.Name; uiTextBoxDesc.Text = objData.Description; uiTextBoxAddress.Text = objData.Address; uiTextBoxTele.Text = objData.Telephone; uiDropDownListCities.SelectedValue = objData.CityID.ToString(); uiDropDownListClientTypes.SelectedValue = objData.ClientTypeID.ToString(); if(!objData.IsColumnNull("StartCredit")) uiTextBoxCredit.Text = objData.StartCredit.ToString(); uiPanelAllClients.Visible = false; uiPanelEditClients.Visible = true; CurrentClient = objData; BindClients(); } else if (e.CommandName == "DeleteClient") { try { IStock.BLL.Clients objData = new IStock.BLL.Clients(); objData.LoadByPrimaryKey(Convert.ToInt32(e.CommandArgument.ToString())); objData.MarkAsDeleted(); objData.Save(); CurrentClient = null; BindClients(); } catch (Exception ex) { } } else if (e.CommandName == "GetClientCredit") { Session["Report_ClientIDForCredit"] = e.CommandArgument.ToString(); Session["CurrentReport"] = "Report_GetClientCredit"; Response.Redirect("Reports.aspx"); } }
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 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.DeliveryOrderDetails objData = new IStock.BLL.DeliveryOrderDetails(); objData.LoadByPrimaryKey(Convert.ToInt32(e.CommandArgument.ToString())); decimal price = 0; if (!CurrentDeliveryOrder.IsColumnNull("Discount") && CurrentDeliveryOrder.Discount != 0) { price = objData.ItemPrice * objData.Quantity * (CurrentDeliveryOrder.Discount / 100); } else { price = objData.ItemPrice * objData.Quantity; } /* restore items to stock */ IStock.BLL.Items item = new IStock.BLL.Items(); item.LoadByPrimaryKey(objData.ItemID); item.Quantity += objData.Quantity; item.Save(); /* restore items to stock */ IStock.BLL.Clients client = new IStock.BLL.Clients(); client.LoadByPrimaryKey(CurrentDeliveryOrder.ClientID); client.StartCredit -= price; client.Save(); objData.MarkAsDeleted(); objData.Save(); BindItems(); } }
protected void uiLinkButtonAddItem_Click(object sender, EventArgs e) { /* get items from stock */ IStock.BLL.Items item = new IStock.BLL.Items(); item.LoadByPrimaryKey(Convert.ToInt32(uiHiddenFieldCurrentItem.Value)); if (!item.IsColumnNull("Quantity")) { if (item.Quantity == 0 || Convert.ToInt32(uiTextBoxQty.Text) > item.Quantity) { ErrorDiv.Visible = true; uiLabelError.Text = GetLocalResourceObject("ItemQtyError").ToString(); return; } item.Quantity -= Convert.ToInt32(uiTextBoxQty.Text); } else { ErrorDiv.Visible = true; uiLabelError.Text = GetLocalResourceObject("ItemQtyError").ToString(); return; } item.Save(); /* get items from stock */ IStock.BLL.DeliveryOrderDetails detail = new IStock.BLL.DeliveryOrderDetails(); detail.AddNew(); detail.DeliveryOrderID = CurrentDeliveryOrder.DeliveryOrderID; detail.ItemID = Convert.ToInt32(uiHiddenFieldCurrentItem.Value); //detail.ItemID = Convert.ToInt32(uiDropDownListItems.SelectedValue); detail.Quantity = Convert.ToInt32(uiTextBoxQty.Text); detail.ItemPrice = decimal.Parse(uiTextBoxPrice.Text); detail.Save(); decimal price = 0; if (!CurrentDeliveryOrder.IsColumnNull("Discount") && CurrentDeliveryOrder.Discount != 0) { price = detail.ItemPrice * detail.Quantity * (CurrentDeliveryOrder.Discount / 100); } else { price = detail.ItemPrice * detail.Quantity; } IStock.BLL.Clients client = new IStock.BLL.Clients(); client.LoadByPrimaryKey(CurrentDeliveryOrder.ClientID); if (!client.IsColumnNull("StartCredit")) client.StartCredit += price; else client.StartCredit = price; client.Save(); ErrorDiv.Visible = false; uiTextBoxItems.Text = ""; uiTextBoxPrice.Text = ""; uiTextBoxQty.Text = ""; BindItems(); }
protected void uiGridViewOrders_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "EditOrder") { IStock.BLL.DeliveryOrder objData = new IStock.BLL.DeliveryOrder(); objData.LoadByPrimaryKey(Convert.ToInt32(e.CommandArgument.ToString())); uiTextBoxCode.Text = objData.DeliveryOrderNo; uiTextBoxDate.Text = objData.DeliveryOrderDate.ToString("dd/MM/yyy"); uiDropDownListClients.SelectedValue = objData.ClientID.ToString(); uiDropDownListEmployee.SelectedValue = objData.EmployeeID.ToString(); if(!objData.IsColumnNull("Discount")) uiTextBoxDiscount.Text = objData.Discount.ToString(); uiPanelAllOrders.Visible = false; uiPanelEditDeliveryOrder.Visible = true; uiPanelItems.Visible = true; CurrentDeliveryOrder = objData; //EnableDisableActions(); BindItems(); } else if (e.CommandName == "DeleteOrder") { try { IStock.BLL.DeliveryOrder objData = new IStock.BLL.DeliveryOrder(); objData.LoadByPrimaryKey(Convert.ToInt32(e.CommandArgument.ToString())); IStock.BLL.DeliveryOrderDetails details = new IStock.BLL.DeliveryOrderDetails(); details.GetDeliveryOrderDetails(objData.DeliveryOrderID); decimal total = objData.GetDeliveryOrderTotals(objData.DeliveryOrderID); /* restore items to stock */ for (int i = 0; i < details.RowCount; i++) { IStock.BLL.Items item = new IStock.BLL.Items(); item.LoadByPrimaryKey(details.ItemID); item.Quantity += details.Quantity; details.MoveNext(); item.Save(); } /* restore items to stock */ details.MarkAsDeleted(); details.Save(); /* update client credit */ IStock.BLL.Clients client = new IStock.BLL.Clients(); client.LoadByPrimaryKey(objData.ClientID); client.StartCredit -= total; client.Save(); /* update client credit */ IStock.BLL.ClientReturns cr = new IStock.BLL.ClientReturns (); cr.GetClientReturnByDeliveryOrderID(objData.DeliveryOrderID); if (cr.RowCount > 0) { cr.SetColumnNull("DeliveryOrderID"); cr.Save(); } objData.MarkAsDeleted(); objData.Save(); CurrentDeliveryOrder = null; BindOrders(); } catch (Exception ex) { uipanelError.Visible = true; } } }
protected void uiGridViewPayments_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "EditPayment") { IStock.BLL.Payments objData = new IStock.BLL.Payments(); objData.LoadByPrimaryKey(Convert.ToInt32(e.CommandArgument.ToString())); uiTextBoxCode.Text = objData.PaymentNo.ToString(); uiTextBoxDate.Text = objData.PaymentDate.ToString("dd/MM/yyy"); uiDropDownListClients.SelectedValue = objData.ClientID.ToString(); if (!objData.IsColumnNull("PaymentTypeID")) uiRadioButtonListPaymentType.SelectedValue = objData.PaymentTypeID.ToString(); else uiRadioButtonListPaymentType.SelectedValue = "1"; uiDropDownListEmployee.SelectedValue = objData.EmployeeID.ToString(); uiTextBoxAmount.Text = objData.Amount.ToString(); uiPanelAllPayments.Visible = false; uiPanelEditPayment.Visible = true; CurrentPayment = objData; EnableDisableControls(); } else if (e.CommandName == "DeletePayment") { try { IStock.BLL.Payments objData = new IStock.BLL.Payments(); objData.LoadByPrimaryKey(Convert.ToInt32(e.CommandArgument.ToString())); IStock.BLL.Clients client = new IStock.BLL.Clients(); client.LoadByPrimaryKey(objData.ClientID); client.StartCredit += objData.Amount; client.Save(); objData.MarkAsDeleted(); objData.Save(); BindPayments(); } catch (Exception ex) { uipanelError.Visible = true; } } }
protected void uiLinkButtonConfirm_Click(object sender, EventArgs e) { IStock.BLL.Clients client = new IStock.BLL.Clients(); client.LoadByPrimaryKey(CurrentPayment.ClientID); if (!client.IsColumnNull("StartCredit")) client.StartCredit -= CurrentPayment.Amount; else client.StartCredit = 0 - CurrentPayment.Amount; client.Save(); CurrentPayment.Confirmed = true; CurrentPayment.Save(); EnableDisableControls(); }
protected void uiLinkButtonOK_Click(object sender, EventArgs e) { IStock.BLL.Clients clients = new IStock.BLL.Clients(); if (CurrentClient == null) clients.AddNew(); else clients = CurrentClient; clients.Name = uiTextBoxName.Text; clients.Description = uiTextBoxDesc.Text; clients.Address = uiTextBoxAddress.Text; clients.Telephone = uiTextBoxTele.Text; clients.CityID = Convert.ToInt32(uiDropDownListCities.SelectedValue); clients.ClientTypeID = Convert.ToInt32(uiDropDownListClientTypes.SelectedValue); if(!string.IsNullOrEmpty(uiTextBoxCredit.Text)) clients.StartCredit = decimal.Parse(uiTextBoxCredit.Text); clients.Save(); ClearFields(); CurrentClient = null; uiPanelEditClients.Visible = false; uiPanelAllClients.Visible = true; BindClients(); }