///<summary>Save changes to orderItems based on input in grid.</summary> //private bool saveChangesHelper() { // if(gridItems.Rows.Count==0) { // return true; // } // //validate ------------------------------------------------------------------------ // for(int i=0;i<gridItems.Rows.Count;i++) { // int qtyThisRow=0; // double priceThisRow=0; // if(gridItems.Rows[i].Cells[2].Text!=""){ // try{ // qtyThisRow=Int32.Parse(gridItems.Rows[i].Cells[2].Text); // } // catch{ // MsgBox.Show(this,"Please fix errors in Qty column first."); // return false; // } // } // if(gridItems.Rows[i].Cells[3].Text!=""){ // try{ // priceThisRow=double.Parse(gridItems.Rows[i].Cells[3].Text); // } // catch{ // MsgBox.Show(this,"Please fix errors in Price column first."); // return false; // } // } // } // //Save changes--------------------------------------------------------------------------- // //List<SupplyOrderItem> listOrderItems=OpenDentBusiness.Crud.SupplyOrderItemCrud.TableToList(tableOrderItems);//turn table into list of supplyOrderItem objects // for(int i=0;i<gridItems.Rows.Count;i++) { // int qtyThisRow=PIn.Int(gridItems.Rows[i].Cells[2].Text);//already validated // double priceThisRow=PIn.Double(gridItems.Rows[i].Cells[3].Text);//already validated // if(qtyThisRow==PIn.Int(tableOrderItems.Rows[i]["Qty"].ToString()) // && priceThisRow==PIn.Double(tableOrderItems.Rows[i]["Price"].ToString())) // { // continue;//no changes to order item. // } // SupplyOrderItem soi=new SupplyOrderItem(); // soi.SupplyNum=PIn.Long(tableOrderItems.Rows[i]["SupplyNum"].ToString()); // soi.SupplyOrderItemNum=PIn.Long(tableOrderItems.Rows[i]["SupplyOrderItemNum"].ToString()); // soi.SupplyOrderNum=ListOrders[gridOrders.GetSelectedIndex()].SupplyOrderNum; // soi.Qty=qtyThisRow; // soi.Price=priceThisRow; // SupplyOrderItems.Update(soi); // }//end gridItems // SupplyOrders.UpdateOrderPrice(ListOrders[gridOrders.GetSelectedIndex()].SupplyOrderNum); // int selectedIndex=gridOrders.GetSelectedIndex(); // ListOrdersAll = SupplyOrders.GetAll();//update new totals // FillGridOrders(); // if(selectedIndex!=-1) { // gridOrders.SetSelected(selectedIndex,true); // } // return true; //} private void gridItems_CellLeave(object sender, ODGridClickEventArgs e) { //no need to check which cell was edited, just reprocess both cells int qtyNew = 0; //default value. try { qtyNew = PIn.Int(gridItems.Rows[e.Row].Cells[2].Text); //0 if not valid input } catch { } double priceNew = PIn.Double(gridItems.Rows[e.Row].Cells[3].Text); //0 if not valid input SupplyOrderItem suppOI = SupplyOrderItems.CreateObject(PIn.Long(_tableOrderItems.Rows[e.Row]["SupplyOrderItemNum"].ToString())); suppOI.Qty = qtyNew; suppOI.Price = priceNew; SupplyOrderItems.Update(suppOI); SupplyOrders.UpdateOrderPrice(suppOI.SupplyOrderNum); gridItems.Rows[e.Row].Cells[2].Text = qtyNew.ToString(); //to standardize formatting. They probably didn't type .00 gridItems.Rows[e.Row].Cells[3].Text = priceNew.ToString("n"); //to standardize formatting. They probably didn't type .00 gridItems.Rows[e.Row].Cells[4].Text = (qtyNew * priceNew).ToString("n"); //to standardize formatting. They probably didn't type .00 gridItems.Invalidate(); int si = gridOrders.GetSelectedIndex(); _listOrdersAll = SupplyOrders.GetAll(); FillGridOrders(); gridOrders.SetSelected(si, true); }
private void butNewOrder_Click(object sender, EventArgs e) { if (comboSupplier.SelectedIndex < 1) //Includes no items or the ALL supplier being selected. { MsgBox.Show(this, "Please select a supplier first."); return; } for (int i = 0; i < _listOrders.Count; i++) { if (_listOrders[i].DatePlaced.Year > 2200) { MsgBox.Show(this, "Not allowed to add a new order when there is already one pending. Please finish the other order instead."); return; } } SupplyOrder order = new SupplyOrder(); if (comboSupplier.SelectedIndex == 0) //Supplier "All". { order.SupplierNum = 0; } else //Specific supplier selected. { order.SupplierNum = _listSuppliers[comboSupplier.SelectedIndex - 1].SupplierNum; //SelectedIndex-1 because "All" is first option. } order.IsNew = true; order.DatePlaced = new DateTime(2500, 1, 1); order.Note = ""; SupplyOrders.Insert(order); _listOrdersAll = SupplyOrders.GetAll(); //Refresh the list all. FillGridOrders(); gridOrders.SetSelected(_listOrders.Count - 1, true); gridOrders.ScrollToEnd(); FillGridOrderItem(); }
private void FormSupplyOrders_Load(object sender, EventArgs e) { Height = SystemInformation.WorkingArea.Height; //max height Location = new Point(Location.X, 0); //move to top of screen _listSuppliers = Suppliers.GetAll(); _listOrdersAll = SupplyOrders.GetAll(); _listOrders = new List <SupplyOrder>(); FillComboSupplier(); FillGridOrders(); gridOrders.ScrollToEnd(); }
private void gridOrder_CellDoubleClick(object sender, ODGridClickEventArgs e) { FormSupplyOrderEdit FormSOE = new FormSupplyOrderEdit(); FormSOE.ListSupplier = _listSuppliers; FormSOE.Order = _listOrders[e.Row]; FormSOE.ShowDialog(); if (FormSOE.DialogResult != DialogResult.OK) { return; } _listOrdersAll = SupplyOrders.GetAll(); FillGridOrders(); FillGridOrderItem(); }
private void UpdatePriceAndRefresh() { SupplyOrder gridSelect = gridOrders.SelectedTag <SupplyOrder>(); SupplyOrders.UpdateOrderPrice(_listOrders[gridOrders.GetSelectedIndex()].SupplyOrderNum); _listOrdersAll = SupplyOrders.GetAll(); FillGridOrders(); for (int i = 0; i < gridOrders.Rows.Count; i++) { if (gridSelect != null && ((SupplyOrder)gridOrders.Rows[i].Tag).SupplyOrderNum == gridSelect.SupplyOrderNum) { gridOrders.SetSelected(i, true); } } FillGridOrderItem(); }
private void gridOrderItem_CellDoubleClick(object sender, ODGridClickEventArgs e) { FormSupplyOrderItemEdit FormSOIE = new FormSupplyOrderItemEdit(); FormSOIE.ItemCur = SupplyOrderItems.CreateObject((long)tableOrderItems.Rows[e.Row]["SupplyOrderItemNum"]); FormSOIE.ListSupplier = Suppliers.CreateObjects(); FormSOIE.ShowDialog(); if (FormSOIE.DialogResult != DialogResult.OK) { return; } SupplyOrderItems.Update(FormSOIE.ItemCur); ListOrdersAll = SupplyOrders.GetAll(); //force refresh because total might have changed. int gridSelect = gridOrders.SelectedIndices[0]; FillGridOrders(); gridOrders.SetSelected(gridSelect, true); FillGridOrderItem(); }