/// <summary>Creates a new order with all the items currently highlighted as a new pending order.</summary> private void butCreateOrders_Click(object sender,EventArgs e) { //Not visible in IsSelectMode if(gridMain.SelectedIndices.Length==0){ MsgBox.Show(this,"Please select supplies, first."); return; } //they are not ordered by supplier, so we need to keep track of a local list of orders List<SupplyOrder> listSupplyOrders=new List<SupplyOrder>(); SupplyOrder supplyOrder=null; for(int i=0;i<gridMain.SelectedIndices.Length;i++){ supplyOrder=listSupplyOrders.FirstOrDefault(x=>x.SupplierNum==_listSupplies[gridMain.SelectedIndices[i]].SupplierNum); if(supplyOrder==null){ supplyOrder=new SupplyOrder(); supplyOrder.SupplierNum=_listSupplies[gridMain.SelectedIndices[i]].SupplierNum; supplyOrder.IsNew=true; supplyOrder.DatePlaced=new DateTime(2500,1,1); //date used for new 'pending' orders. supplyOrder.Note=""; supplyOrder.UserNum=Security.CurUser.UserNum; supplyOrder.SupplyOrderNum=SupplyOrders.Insert(supplyOrder); listSupplyOrders.Add(supplyOrder); } SupplyOrderItem supplyOrderItem=new SupplyOrderItem(); supplyOrderItem.SupplyNum=_listSupplies[gridMain.SelectedIndices[i]].SupplyNum; supplyOrderItem.Qty=_listSupplies[gridMain.SelectedIndices[i]].OrderQty; supplyOrderItem.Price=_listSupplies[gridMain.SelectedIndices[i]].Price; supplyOrderItem.SupplyOrderNum=supplyOrder.SupplyOrderNum; SupplyOrderItems.Insert(supplyOrderItem); } for(int i=0;i<listSupplyOrders.Count;i++){ SupplyOrders.UpdateOrderPrice(listSupplyOrders[i].SupplyOrderNum); } MessageBox.Show(Lan.g(this,"Done. Added ")+listSupplyOrders.Count.ToString()+Lan.g(this," orders. Manage orders from Orders window")); DialogResult=DialogResult.OK; }
private void butAddSupply_Click(object sender, EventArgs e) { if (gridOrders.GetSelectedIndex() == -1) { MsgBox.Show(this, "Please select a supply order to add items to first."); return; } FormSupplies FormSup = new FormSupplies(); FormSup.IsSelectMode = true; FormSup.SelectedSupplierNum = _listOrders[gridOrders.GetSelectedIndex()].SupplierNum; FormSup.ShowDialog(); if (FormSup.DialogResult != DialogResult.OK) { return; } for (int i = 0; i < FormSup.ListSelectedSupplies.Count; i++) { //check for existing---- if (_tableOrderItems.Rows.OfType <DataRow>().Any(x => PIn.Long(x["SupplyNum"].ToString()) == FormSup.ListSelectedSupplies[i].SupplyNum)) { //MsgBox.Show(this,"Selected item already exists in currently selected order. Please edit quantity instead."); continue; } SupplyOrderItem orderitem = new SupplyOrderItem(); orderitem.SupplyNum = FormSup.ListSelectedSupplies[i].SupplyNum; orderitem.Qty = 1; orderitem.Price = FormSup.ListSelectedSupplies[i].Price; orderitem.SupplyOrderNum = _listOrders[gridOrders.GetSelectedIndex()].SupplyOrderNum; //soi.SupplyOrderItemNum SupplyOrderItems.Insert(orderitem); } UpdatePriceAndRefresh(); }
private void butAddSupply_Click(object sender, EventArgs e) { if (gridOrders.GetSelectedIndex() == -1) { MsgBox.Show(this, "Please select a supply order to add items to first."); return; } FormSupplies FormSup = new FormSupplies(); FormSup.IsSelectMode = true; FormSup.SelectedSupplierNum = ListOrders[gridOrders.GetSelectedIndex()].SupplierNum; FormSup.ShowDialog(); if (FormSup.DialogResult != DialogResult.OK) { return; } for (int i = 0; i < FormSup.ListSelectedSupplies.Count; i++) { //check for existing---- if (itemExistsHelper(FormSup.ListSelectedSupplies[i])) { //MsgBox.Show(this,"Selected item already exists in currently selected order. Please edit quantity instead."); continue; } SupplyOrderItem orderitem = new SupplyOrderItem(); orderitem.SupplyNum = FormSup.ListSelectedSupplies[i].SupplyNum; orderitem.Qty = 1; orderitem.Price = FormSup.ListSelectedSupplies[i].Price; orderitem.SupplyOrderNum = ListOrders[gridOrders.GetSelectedIndex()].SupplyOrderNum; //soi.SupplyOrderItemNum SupplyOrderItems.Insert(orderitem); } FillGridOrderItem(); }
///<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 gridItems_CellLeave(object sender, ODGridClickEventArgs e) { int qtyOld = PIn.Int(_tableOrderItems.Rows[e.Row]["Qty"].ToString(), false); int qtyNew = 0; try { qtyNew = PIn.Int(gridItems.ListGridRows[e.Row].Cells[2].Text); //0 if not valid input } catch { } double priceOld = PIn.Double(_tableOrderItems.Rows[e.Row]["Price"].ToString()); double priceNew = PIn.Double(gridItems.ListGridRows[e.Row].Cells[3].Text); //0 if not valid input //if(e.Col==2){//Qty //gridItems.ListGridRows[e.Row].Cells[2].Text=qtyNew.ToString();//Fix the cell formatting //if(qtyOld==qtyNew){ //don't go to db. //gridItems.Invalidate(); //return; //} //} //if(e.Col==3){//price //gridItems.ListGridRows[e.Row].Cells[3].Text=priceNew.ToString("n");//Fix the cell formatting //if(priceOld==priceNew){ //don't go to db. //gridItems.Invalidate(); //return; //} //} //gridItems.ListGridRows[e.Row].Cells[4].Text=(qtyNew*priceNew).ToString("n"); //gridItems.Invalidate(); if (qtyOld == qtyNew && priceOld == priceNew) { FillGridOrderItem(false); //no refresh } else { SupplyOrderItem supplyOrderItem = SupplyOrderItems.SelectOne(PIn.Long(_tableOrderItems.Rows[e.Row]["SupplyOrderItemNum"].ToString())); supplyOrderItem.Qty = qtyNew; supplyOrderItem.Price = priceNew; SupplyOrderItems.Update(supplyOrderItem); SupplyOrder updatedSupplyOrderItem = SupplyOrders.UpdateOrderPrice(supplyOrderItem.SupplyOrderNum); //this might be an expensive query that we could avoid FillGridOrderItem(); int index = _listSupplyOrders.FindIndex(x => x.SupplyOrderNum == supplyOrderItem.SupplyOrderNum); if (index < 0) //Just in case, shouldn't happen { FillGridOrders(); return; } _listSupplyOrders[index] = updatedSupplyOrderItem; gridOrders.SelectedGridRows[0].Cells[2].Text = updatedSupplyOrderItem.AmountTotal.ToString("c2"); gridOrders.Invalidate(); } }
private void gridOrderItem_CellDoubleClick(object sender, ODGridClickEventArgs e) { FormSupplyOrderItemEdit FormS = new FormSupplyOrderItemEdit(); FormS.ItemCur = SupplyOrderItems.CreateObject(PIn.Long(tableOrderItem.Rows[e.Row]["SupplyOrderItemNum"].ToString())); FormS.ListSupplier = listSupplier; FormS.ShowDialog(); if (FormS.DialogResult == DialogResult.OK) { FillGridOrderItem(); } //still need to reselect item }
private void butOK_Click(object sender, EventArgs e) { if (textQty.errorProvider1.GetError(textQty) != "" || textPrice.errorProvider1.GetError(textPrice) != "") { MsgBox.Show(this, "Please fix data entry errors first."); return; } ItemCur.Qty = PIn.Int(textQty.Text); ItemCur.Price = PIn.Double(textPrice.Text); SupplyOrderItems.Update(ItemCur); //never new DialogResult = DialogResult.OK; }
private void gridOrderItem_CellDoubleClick(object sender, ODGridClickEventArgs e) { FormSupplyOrderItemEdit FormSOIE = new FormSupplyOrderItemEdit(); FormSOIE.ItemCur = SupplyOrderItems.CreateObject(PIn.Long(_tableOrderItems.Rows[e.Row]["SupplyOrderItemNum"].ToString())); FormSOIE.ListSupplier = Suppliers.GetAll(); FormSOIE.ShowDialog(); if (FormSOIE.DialogResult != DialogResult.OK) { return; } SupplyOrderItems.Update(FormSOIE.ItemCur); UpdatePriceAndRefresh(); }
private void gridOrderItem_CellDoubleClick(object sender, ODGridClickEventArgs e) { FormSupplyOrderItemEdit formSupplyOrderItemEdit = new FormSupplyOrderItemEdit(); formSupplyOrderItemEdit.SupplyOrderItemCur = SupplyOrderItems.SelectOne(PIn.Long(_tableOrderItems.Rows[e.Row]["SupplyOrderItemNum"].ToString())); formSupplyOrderItemEdit.ListSuppliersAll = Suppliers.GetAll(); formSupplyOrderItemEdit.ShowDialog(); if (formSupplyOrderItemEdit.DialogResult != DialogResult.OK) { return; } //SupplyOrderItems.Update(formSupplyOrderItemEdit.SupplyOrderItemCur); UpdatePriceAndRefresh(); }
private void butDelete_Click(object sender, EventArgs e) { if (!MsgBox.Show(this, true, "Delete?")) { return; } //try{ SupplyOrderItems.DeleteObject(ItemCur); //} //catch(ApplicationException ex){ // MessageBox.Show(ex.Message); // return; //} DialogResult = DialogResult.OK; }
private void FillGridOrderItem(bool refresh = true) { long orderNum = 0; if (gridOrders.GetSelectedIndex() != -1) //an order is selected { orderNum = _listSupplyOrders[gridOrders.GetSelectedIndex()].SupplyOrderNum; } if (refresh) { _tableOrderItems = SupplyOrderItems.GetItemsForOrder(orderNum); } gridItems.BeginUpdate(); gridItems.ListGridColumns.Clear(); GridColumn col = new GridColumn(Lan.g(this, "Catalog #"), 80); gridItems.ListGridColumns.Add(col); col = new GridColumn(Lan.g(this, "Description"), 320); gridItems.ListGridColumns.Add(col); col = new GridColumn(Lan.g(this, "Qty"), 60, HorizontalAlignment.Center); col.IsEditable = true; gridItems.ListGridColumns.Add(col); col = new GridColumn(Lan.g(this, "Price/Unit"), 70, HorizontalAlignment.Right); col.IsEditable = true; gridItems.ListGridColumns.Add(col); col = new GridColumn(Lan.g(this, "Subtotal"), 70, HorizontalAlignment.Right); gridItems.ListGridColumns.Add(col); gridItems.ListGridRows.Clear(); GridRow row; double price; int qty; double subtotal; for (int i = 0; i < _tableOrderItems.Rows.Count; i++) { row = new GridRow(); row.Cells.Add(_tableOrderItems.Rows[i]["CatalogNumber"].ToString()); row.Cells.Add(_tableOrderItems.Rows[i]["Descript"].ToString()); qty = PIn.Int(_tableOrderItems.Rows[i]["Qty"].ToString()); row.Cells.Add(qty.ToString()); price = PIn.Double(_tableOrderItems.Rows[i]["Price"].ToString()); row.Cells.Add(price.ToString("n")); subtotal = ((double)qty) * price; row.Cells.Add(subtotal.ToString("n")); gridItems.ListGridRows.Add(row); } gridItems.EndUpdate(); }
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(); }
/// <summary>Creates a new order with all the items that have a Qty entered as a new pending order.</summary> private void butCreateOrdersQty_Click(object sender, EventArgs e) { //Not visible in IsSelectMode List<SupplyOrder> listSupplyOrders=new List<SupplyOrder>(); SupplyOrder supplyOrder=null; for(int i=0;i<_listSupplies.Count;i++){ if(_listSupplies[i].OrderQty==0){ continue; } supplyOrder=listSupplyOrders.FirstOrDefault(x=>x.SupplierNum==_listSupplies[i].SupplierNum); if(supplyOrder==null){ supplyOrder=new SupplyOrder(); supplyOrder.SupplierNum=_listSupplies[i].SupplierNum; supplyOrder.IsNew=true; supplyOrder.DatePlaced=new DateTime(2500,1,1); //date used for new 'pending' orders. supplyOrder.Note=""; supplyOrder.UserNum=Security.CurUser.UserNum; supplyOrder.SupplyOrderNum=SupplyOrders.Insert(supplyOrder); listSupplyOrders.Add(supplyOrder); } SupplyOrderItem supplyOrderItem=new SupplyOrderItem(); supplyOrderItem.SupplyNum=_listSupplies[i].SupplyNum; supplyOrderItem.Qty=_listSupplies[i].OrderQty; supplyOrderItem.Price=_listSupplies[i].Price; supplyOrderItem.SupplyOrderNum=supplyOrder.SupplyOrderNum; SupplyOrderItems.Insert(supplyOrderItem); //Supply has been added to order. Now, zero out qty on supply. _listSupplies[i].OrderQty=0; Supplies.Update(_listSupplies[i]); } if(listSupplyOrders.Count==0){ MsgBox.Show("Please enter quantities for supplies first."); return; } for(int i=0;i<listSupplyOrders.Count;i++){ SupplyOrders.UpdateOrderPrice(listSupplyOrders[i].SupplyOrderNum); } MessageBox.Show(Lan.g(this,"Done. Added ")+listSupplyOrders.Count.ToString()+Lan.g(this," orders. Manage orders from Orders window")); DialogResult=DialogResult.OK; }
private void FillGridOrderItem() { long orderNum = 0; if (gridOrders.GetSelectedIndex() != -1) //an order is selected { orderNum = _listOrders[gridOrders.GetSelectedIndex()].SupplyOrderNum; } _tableOrderItems = SupplyOrderItems.GetItemsForOrder(orderNum); gridItems.BeginUpdate(); gridItems.Columns.Clear(); //ODGridColumn col=new ODGridColumn(Lan.g(this,"Supplier"),120); //gridItems.Columns.Add(col); ODGridColumn col = new ODGridColumn(Lan.g(this, "Catalog #"), 80); gridItems.Columns.Add(col); col = new ODGridColumn(Lan.g(this, "Description"), 320); gridItems.Columns.Add(col); col = new ODGridColumn(Lan.g(this, "Qty"), 60, HorizontalAlignment.Center); col.IsEditable = true; gridItems.Columns.Add(col); col = new ODGridColumn(Lan.g(this, "Price/Unit"), 70, HorizontalAlignment.Right); col.IsEditable = true; gridItems.Columns.Add(col); col = new ODGridColumn(Lan.g(this, "Subtotal"), 70, HorizontalAlignment.Right); gridItems.Columns.Add(col); gridItems.Rows.Clear(); ODGridRow row; double price; int qty; double subtotal; double total = 0; bool autocalcTotal = true; for (int i = 0; i < _tableOrderItems.Rows.Count; i++) { row = new ODGridRow(); //if(gridOrders.GetSelectedIndex()==-1){ // row.Cells.Add(""); //} //else{ // row.Cells.Add(Suppliers.GetName(ListSuppliers,ListOrders[gridOrders.GetSelectedIndex()].SupplierNum)); //} row.Cells.Add(_tableOrderItems.Rows[i]["CatalogNumber"].ToString()); row.Cells.Add(_tableOrderItems.Rows[i]["Descript"].ToString()); qty = PIn.Int(_tableOrderItems.Rows[i]["Qty"].ToString()); row.Cells.Add(qty.ToString()); price = PIn.Double(_tableOrderItems.Rows[i]["Price"].ToString()); row.Cells.Add(price.ToString("n")); subtotal = ((double)qty) * price; row.Cells.Add(subtotal.ToString("n")); gridItems.Rows.Add(row); if (subtotal == 0) { autocalcTotal = false; } total += subtotal; } gridItems.EndUpdate(); if (gridOrders.GetSelectedIndex() != -1 && autocalcTotal && total != _listOrders[gridOrders.GetSelectedIndex()].AmountTotal) { SupplyOrder order = _listOrders[gridOrders.GetSelectedIndex()].Copy(); order.AmountTotal = total; SupplyOrders.Update(order); FillGridOrders(); for (int i = 0; i < _listOrders.Count; i++) { if (_listOrders[i].SupplyOrderNum == order.SupplyOrderNum) { gridOrders.SetSelected(i, true); } } } }
private void butAddToOrder_Click(object sender, EventArgs e) { if (gridOrder.GetSelectedIndex() == -1) { MsgBox.Show(this, "Please select an order first."); return; } if (gridSupplyMain.SelectedIndices.Length == 0) { MsgBox.Show(this, "Please select one or more supplies first."); return; } SupplyOrderItem item; List <long> itemNums = new List <long>(); List <Supply> skippedSupplies = new List <Supply>(); bool isSkipped; for (int i = 0; i < gridSupplyMain.SelectedIndices.Length; i++) { isSkipped = false; for (int t = 0; t < tableOrderItem.Rows.Count; t++) { if (listSupply[gridSupplyMain.SelectedIndices[i]].SupplyNum.ToString() == tableOrderItem.Rows[t]["SupplyNum"].ToString()) { isSkipped = true; break;; } } if (isSkipped) { skippedSupplies.Add(listSupply[gridSupplyMain.SelectedIndices[i]]); continue; } item = new SupplyOrderItem(); item.SupplyOrderNum = listOrder[gridOrder.GetSelectedIndex()].SupplyOrderNum; item.SupplyNum = listSupply[gridSupplyMain.SelectedIndices[i]].SupplyNum; item.Qty = 1; item.Price = listSupply[gridSupplyMain.SelectedIndices[i]].Price; SupplyOrderItems.Insert(item); itemNums.Add(item.SupplyOrderItemNum); } if (gridSupplyMain.SelectedIndices.Length == 1 && skippedSupplies.Count == 1) { MsgBox.Show(this, "Selected supply is already on the order."); return; } else if (skippedSupplies.Count == gridSupplyMain.SelectedIndices.Length) { MsgBox.Show(this, "Selected supplies are already on the order."); return; } else if (skippedSupplies.Count > 0) { MessageBox.Show(skippedSupplies.Count.ToString() + " " + Lan.g(this, "supplies were skipped because they are already on the order.")); } FillGridOrderItem(); tabControl.SelectedIndex = 1; for (int i = 0; i < tableOrderItem.Rows.Count; i++) { if (itemNums.Contains(PIn.Long(tableOrderItem.Rows[i]["SupplyOrderItemNum"].ToString()))) { gridOrderItem.SetSelected(i, true); } } }
private void butDelete_Click(object sender, EventArgs e) { //don't ask SupplyOrderItems.DeleteObject(SupplyOrderItemCur); DialogResult = DialogResult.OK; }