Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 2
0
        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();
            }
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
        private void UpdatePriceAndRefresh()
        {
            SupplyOrder gridSelect = gridOrders.SelectedTag <SupplyOrder>();

            SupplyOrders.UpdateOrderPrice(_listSupplyOrders[gridOrders.GetSelectedIndex()].SupplyOrderNum);
            FillGridOrders();
            for (int i = 0; i < gridOrders.ListGridRows.Count; i++)
            {
                if (gridSelect != null && ((SupplyOrder)gridOrders.ListGridRows[i].Tag).SupplyOrderNum == gridSelect.SupplyOrderNum)
                {
                    gridOrders.SetSelected(i, true);
                }
            }
            FillGridOrderItem();
        }
Ejemplo n.º 5
0
 private void butDelete_Click(object sender, EventArgs e)
 {
     //if(Order.IsNew){//never
     //	DialogResult=DialogResult.Cancel;
     //}
     if (textDatePlaced.Text != "")
     {
         MsgBox.Show(this, "Not allowed to delete unless date is blank.");
         return;
     }
     if (!MsgBox.Show(this, true, "Delete entire order?"))
     {
         return;
     }
     SupplyOrders.DeleteObject(Order);
     DialogResult = DialogResult.OK;
 }
Ejemplo n.º 6
0
        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();
        }
Ejemplo n.º 7
0
 private void butOK_Click(object sender, EventArgs e)
 {
     if (textDatePlaced.errorProvider1.GetError(textDatePlaced) != "" ||
         textAmountTotal.errorProvider1.GetError(textAmountTotal) != "")
     {
         MsgBox.Show(this, "Please fix data entry errors first.");
         return;
     }
     if (textDatePlaced.Text == "")
     {
         Order.DatePlaced = new DateTime(2500, 1, 1);
     }
     else
     {
         Order.DatePlaced = PIn.Date(textDatePlaced.Text);
     }
     Order.AmountTotal = PIn.Double(textAmountTotal.Text);
     Order.Note        = textNote.Text;
     SupplyOrders.Update(Order);            //never new
     DialogResult = DialogResult.OK;
 }
Ejemplo n.º 8
0
 /// <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;
 }
Ejemplo n.º 9
0
        private void FillGridOrder()
        {
            long supplier = 0;

            if (comboSupplier.SelectedIndex != -1)
            {
                supplier = listSupplier[comboSupplier.SelectedIndex].SupplierNum;
            }
            listOrder = SupplyOrders.CreateObjects(supplier);
            gridOrder.BeginUpdate();
            gridOrder.Columns.Clear();
            ODGridColumn col = new ODGridColumn(Lan.g(this, "Date Placed"), 80);

            gridOrder.Columns.Add(col);
            col = new ODGridColumn(Lan.g(this, "Amount"), 70, HorizontalAlignment.Right);
            gridOrder.Columns.Add(col);
            col = new ODGridColumn(Lan.g(this, "Note"), 200);
            gridOrder.Columns.Add(col);
            gridOrder.Rows.Clear();
            ODGridRow row;

            for (int i = 0; i < listOrder.Count; i++)
            {
                row = new ODGridRow();
                if (listOrder[i].DatePlaced.Year > 2200)
                {
                    row.Cells.Add(Lan.g(this, "pending"));
                }
                else
                {
                    row.Cells.Add(listOrder[i].DatePlaced.ToShortDateString());
                }
                row.Cells.Add(listOrder[i].AmountTotal.ToString("c"));
                row.Cells.Add(listOrder[i].Note);
                gridOrder.Rows.Add(row);
            }
            gridOrder.EndUpdate();
        }
Ejemplo n.º 10
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 11
0
        private void FillGridOrders()
        {
            long supplierNum = 0;

            if (!comboSupplier.IsAllSelected)
            {
                supplierNum = comboSupplier.GetSelectedKey <Supplier>(x => x.SupplierNum);
            }
            _listSupplyOrders = SupplyOrders.GetList(supplierNum);
            if (!checkShowReceived.Checked)
            {
                _listSupplyOrders = _listSupplyOrders.FindAll(x => x.DateReceived.Year < 1880);
            }
            //Show the not received items at the bottom, then order by date placed.
            _listSupplyOrders = _listSupplyOrders.OrderBy(x => x.DateReceived.Year < 1880)
                                .ThenBy(x => x.DatePlaced).ToList();
            gridOrders.BeginUpdate();
            gridOrders.ListGridColumns.Clear();
            GridColumn col = new GridColumn(Lan.g(this, "Date Placed"), 80);

            gridOrders.ListGridColumns.Add(col);
            col = new GridColumn(Lan.g(this, "Date Received"), 90);
            gridOrders.ListGridColumns.Add(col);
            col = new GridColumn(Lan.g(this, "Amount"), 70, HorizontalAlignment.Right);
            gridOrders.ListGridColumns.Add(col);
            col = new GridColumn(Lan.g(this, "Shipping"), 70, HorizontalAlignment.Right);
            gridOrders.ListGridColumns.Add(col);
            col = new GridColumn(Lan.g(this, "Supplier"), 120);
            gridOrders.ListGridColumns.Add(col);
            col = new GridColumn(Lan.g(this, "Note"), 200);
            gridOrders.ListGridColumns.Add(col);
            col = new GridColumn(Lan.g(this, "Placed By"), 100);
            gridOrders.ListGridColumns.Add(col);
            gridOrders.ListGridRows.Clear();
            GridRow row;

            for (int i = 0; i < _listSupplyOrders.Count; i++)
            {
                row = new GridRow();
                bool isPending = false;
                if (_listSupplyOrders[i].DatePlaced.Year > 2200)
                {
                    isPending = true;
                }
                if (isPending)
                {
                    row.Cells.Add(Lan.g(this, "pending"));
                }
                else
                {
                    row.Cells.Add(_listSupplyOrders[i].DatePlaced.ToShortDateString());
                }
                if (_listSupplyOrders[i].DateReceived.Year < 1880)
                {
                    row.Cells.Add("");
                }
                else
                {
                    row.Cells.Add(_listSupplyOrders[i].DateReceived.ToShortDateString());
                }
                row.Cells.Add(_listSupplyOrders[i].AmountTotal.ToString("c"));
                row.Cells.Add(_listSupplyOrders[i].ShippingCharge.ToString("c"));
                row.Cells.Add(Suppliers.GetName(_listSuppliers, _listSupplyOrders[i].SupplierNum));
                row.Cells.Add(_listSupplyOrders[i].Note);
                if (isPending || _listSupplyOrders[i].UserNum == 0)
                {
                    row.Cells.Add("");
                }
                else
                {
                    row.Cells.Add(Userods.GetName(_listSupplyOrders[i].UserNum));
                }
                row.Tag = _listSupplyOrders[i];
                gridOrders.ListGridRows.Add(row);
            }
            gridOrders.EndUpdate();
        }