///<summary>Inserts one SupplyOrderItem into the database.  Provides option to use the existing priKey.</summary>
		public static long Insert(SupplyOrderItem supplyOrderItem,bool useExistingPK){
			if(!useExistingPK && PrefC.RandomKeys) {
				supplyOrderItem.SupplyOrderItemNum=ReplicationServers.GetKey("supplyorderitem","SupplyOrderItemNum");
			}
			string command="INSERT INTO supplyorderitem (";
			if(useExistingPK || PrefC.RandomKeys) {
				command+="SupplyOrderItemNum,";
			}
			command+="SupplyOrderNum,SupplyNum,Qty,Price) VALUES(";
			if(useExistingPK || PrefC.RandomKeys) {
				command+=POut.Long(supplyOrderItem.SupplyOrderItemNum)+",";
			}
			command+=
				     POut.Long  (supplyOrderItem.SupplyOrderNum)+","
				+    POut.Long  (supplyOrderItem.SupplyNum)+","
				+    POut.Int   (supplyOrderItem.Qty)+","
				+"'"+POut.Double(supplyOrderItem.Price)+"')";
			if(useExistingPK || PrefC.RandomKeys) {
				Db.NonQ(command);
			}
			else {
				supplyOrderItem.SupplyOrderItemNum=Db.NonQ(command,true);
			}
			return supplyOrderItem.SupplyOrderItemNum;
		}
Пример #2
0
        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();
        }
Пример #3
0
        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();
        }
Пример #4
0
        ///<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);
        }
Пример #5
0
        ///<summary>Inserts one SupplyOrderItem into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(SupplyOrderItem supplyOrderItem, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO supplyorderitem (";

            if (!useExistingPK && isRandomKeys)
            {
                supplyOrderItem.SupplyOrderItemNum = ReplicationServers.GetKeyNoCache("supplyorderitem", "SupplyOrderItemNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "SupplyOrderItemNum,";
            }
            command += "SupplyOrderNum,SupplyNum,Qty,Price) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(supplyOrderItem.SupplyOrderItemNum) + ",";
            }
            command +=
                POut.Long(supplyOrderItem.SupplyOrderNum) + ","
                + POut.Long(supplyOrderItem.SupplyNum) + ","
                + POut.Int(supplyOrderItem.Qty) + ","
                + "'" + POut.Double(supplyOrderItem.Price) + "')";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                supplyOrderItem.SupplyOrderItemNum = Db.NonQ(command, true, "SupplyOrderItemNum", "supplyOrderItem");
            }
            return(supplyOrderItem.SupplyOrderItemNum);
        }
Пример #6
0
 /// <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;
 }
Пример #7
0
 ///<summary>Inserts one SupplyOrderItem into the database.  Returns the new priKey.</summary>
 internal static long Insert(SupplyOrderItem supplyOrderItem)
 {
     if(DataConnection.DBtype==DatabaseType.Oracle) {
         supplyOrderItem.SupplyOrderItemNum=DbHelper.GetNextOracleKey("supplyorderitem","SupplyOrderItemNum");
         int loopcount=0;
         while(loopcount<100){
             try {
                 return Insert(supplyOrderItem,true);
             }
             catch(Oracle.DataAccess.Client.OracleException ex){
                 if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
                     supplyOrderItem.SupplyOrderItemNum++;
                     loopcount++;
                 }
                 else{
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else {
         return Insert(supplyOrderItem,false);
     }
 }
Пример #8
0
        ///<summary>Inserts one SupplyOrderItem into the database.  Provides option to use the existing priKey.</summary>
        internal static long Insert(SupplyOrderItem supplyOrderItem, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                supplyOrderItem.SupplyOrderItemNum = ReplicationServers.GetKey("supplyorderitem", "SupplyOrderItemNum");
            }
            string command = "INSERT INTO supplyorderitem (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "SupplyOrderItemNum,";
            }
            command += "SupplyOrderNum,SupplyNum,Qty,Price) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(supplyOrderItem.SupplyOrderItemNum) + ",";
            }
            command +=
                POut.Long(supplyOrderItem.SupplyOrderNum) + ","
                + POut.Long(supplyOrderItem.SupplyNum) + ","
                + POut.Int(supplyOrderItem.Qty) + ","
                + "'" + POut.Double(supplyOrderItem.Price) + "')";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                supplyOrderItem.SupplyOrderItemNum = Db.NonQ(command, true);
            }
            return(supplyOrderItem.SupplyOrderItemNum);
        }
Пример #9
0
 ///<summary>Inserts one SupplyOrderItem into the database.  Returns the new priKey.</summary>
 internal static long Insert(SupplyOrderItem supplyOrderItem)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         supplyOrderItem.SupplyOrderItemNum = DbHelper.GetNextOracleKey("supplyorderitem", "SupplyOrderItemNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(supplyOrderItem, true));
             }
             catch (Oracle.DataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     supplyOrderItem.SupplyOrderItemNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(supplyOrderItem, false));
     }
 }
Пример #10
0
        public int InsertSupplyOrderItem(SupplyOrderItem objSupplyOrderItem, IDbConnection connection, IDbTransaction trn)
        {
            string sql = @"insert  into SupplyOrderItem(SupplyOrderId,PurchaseRequestItemId,SlNo,BalQty,OrderedQty,Rate,Discount,Amount,OrganizationId,Description) Values (@SupplyOrderId,@PurchaseRequestItemId,@SlNo,@BalQty,@OrderedQty,@Rate,@Discount,@Amount,@OrganizationId,@Description);
                SELECT CAST(SCOPE_IDENTITY() as int)";

            var id = connection.Query <int>(sql, objSupplyOrderItem, trn).Single();

            return(id);
        }
Пример #11
0
        public int UpdateSupplyOrderItem(SupplyOrderItem objSupplyOrderItem)
        {
            using (IDbConnection connection = OpenConnection(dataConnection))
            {
                string sql = @"UPDATE SupplyOrderItem SET SupplyOrderId = @SupplyOrderId ,PurchaseRequestItemId = @PurchaseRequestItemId ,SlNo = @SlNo ,BalQty = @BalQty,OrderedQty = @OrderedQty,Rate = @Rate,Discount = @Discount,Amount = @Amount,CreatedBy = @CreatedBy ,CreatedDate = @CreatedDate   OUTPUT INSERTED.SupplyOrderItemId  WHERE SupplyOrderItemId = @SupplyOrderItemId";


                var id = connection.Execute(sql, objSupplyOrderItem);
                return(id);
            }
        }
Пример #12
0
        ///<summary>Updates one SupplyOrderItem in the database.</summary>
        internal static void Update(SupplyOrderItem supplyOrderItem)
        {
            string command = "UPDATE supplyorderitem SET "
                             + "SupplyOrderNum    =  " + POut.Long(supplyOrderItem.SupplyOrderNum) + ", "
                             + "SupplyNum         =  " + POut.Long(supplyOrderItem.SupplyNum) + ", "
                             + "Qty               =  " + POut.Int(supplyOrderItem.Qty) + ", "
                             + "Price             = '" + POut.Double(supplyOrderItem.Price) + "' "
                             + "WHERE SupplyOrderItemNum = " + POut.Long(supplyOrderItem.SupplyOrderItemNum);

            Db.NonQ(command);
        }
Пример #13
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();
            }
        }
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<SupplyOrderItem> TableToList(DataTable table){
			List<SupplyOrderItem> retVal=new List<SupplyOrderItem>();
			SupplyOrderItem supplyOrderItem;
			for(int i=0;i<table.Rows.Count;i++) {
				supplyOrderItem=new SupplyOrderItem();
				supplyOrderItem.SupplyOrderItemNum= PIn.Long  (table.Rows[i]["SupplyOrderItemNum"].ToString());
				supplyOrderItem.SupplyOrderNum    = PIn.Long  (table.Rows[i]["SupplyOrderNum"].ToString());
				supplyOrderItem.SupplyNum         = PIn.Long  (table.Rows[i]["SupplyNum"].ToString());
				supplyOrderItem.Qty               = PIn.Int   (table.Rows[i]["Qty"].ToString());
				supplyOrderItem.Price             = PIn.Double(table.Rows[i]["Price"].ToString());
				retVal.Add(supplyOrderItem);
			}
			return retVal;
		}
Пример #15
0
 ///<summary>Inserts one SupplyOrderItem into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(SupplyOrderItem supplyOrderItem)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(supplyOrderItem, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             supplyOrderItem.SupplyOrderItemNum = DbHelper.GetNextOracleKey("supplyorderitem", "SupplyOrderItemNum");                  //Cacheless method
         }
         return(InsertNoCache(supplyOrderItem, true));
     }
 }
Пример #16
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <SupplyOrderItem> TableToList(DataTable table)
        {
            List <SupplyOrderItem> retVal = new List <SupplyOrderItem>();
            SupplyOrderItem        supplyOrderItem;

            foreach (DataRow row in table.Rows)
            {
                supplyOrderItem = new SupplyOrderItem();
                supplyOrderItem.SupplyOrderItemNum = PIn.Long(row["SupplyOrderItemNum"].ToString());
                supplyOrderItem.SupplyOrderNum     = PIn.Long(row["SupplyOrderNum"].ToString());
                supplyOrderItem.SupplyNum          = PIn.Long(row["SupplyNum"].ToString());
                supplyOrderItem.Qty   = PIn.Int(row["Qty"].ToString());
                supplyOrderItem.Price = PIn.Double(row["Price"].ToString());
                retVal.Add(supplyOrderItem);
            }
            return(retVal);
        }
Пример #17
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        internal static List <SupplyOrderItem> TableToList(DataTable table)
        {
            List <SupplyOrderItem> retVal = new List <SupplyOrderItem>();
            SupplyOrderItem        supplyOrderItem;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                supplyOrderItem = new SupplyOrderItem();
                supplyOrderItem.SupplyOrderItemNum = PIn.Long(table.Rows[i]["SupplyOrderItemNum"].ToString());
                supplyOrderItem.SupplyOrderNum     = PIn.Long(table.Rows[i]["SupplyOrderNum"].ToString());
                supplyOrderItem.SupplyNum          = PIn.Long(table.Rows[i]["SupplyNum"].ToString());
                supplyOrderItem.Qty   = PIn.Int(table.Rows[i]["Qty"].ToString());
                supplyOrderItem.Price = PIn.Double(table.Rows[i]["Price"].ToString());
                retVal.Add(supplyOrderItem);
            }
            return(retVal);
        }
Пример #18
0
        ///<summary>Updates one SupplyOrderItem in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
        public static bool Update(SupplyOrderItem supplyOrderItem, SupplyOrderItem oldSupplyOrderItem)
        {
            string command = "";

            if (supplyOrderItem.SupplyOrderNum != oldSupplyOrderItem.SupplyOrderNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SupplyOrderNum = " + POut.Long(supplyOrderItem.SupplyOrderNum) + "";
            }
            if (supplyOrderItem.SupplyNum != oldSupplyOrderItem.SupplyNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SupplyNum = " + POut.Long(supplyOrderItem.SupplyNum) + "";
            }
            if (supplyOrderItem.Qty != oldSupplyOrderItem.Qty)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Qty = " + POut.Int(supplyOrderItem.Qty) + "";
            }
            if (supplyOrderItem.Price != oldSupplyOrderItem.Price)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Price = '" + POut.Double(supplyOrderItem.Price) + "'";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE supplyorderitem SET " + command
                      + " WHERE SupplyOrderItemNum = " + POut.Long(supplyOrderItem.SupplyOrderItemNum);
            Db.NonQ(command);
            return(true);
        }
Пример #19
0
 ///<summary>Returns true if Update(SupplyOrderItem,SupplyOrderItem) would make changes to the database.
 ///Does not make any changes to the database and can be called before remoting role is checked.</summary>
 public static bool UpdateComparison(SupplyOrderItem supplyOrderItem, SupplyOrderItem oldSupplyOrderItem)
 {
     if (supplyOrderItem.SupplyOrderNum != oldSupplyOrderItem.SupplyOrderNum)
     {
         return(true);
     }
     if (supplyOrderItem.SupplyNum != oldSupplyOrderItem.SupplyNum)
     {
         return(true);
     }
     if (supplyOrderItem.Qty != oldSupplyOrderItem.Qty)
     {
         return(true);
     }
     if (supplyOrderItem.Price != oldSupplyOrderItem.Price)
     {
         return(true);
     }
     return(false);
 }
Пример #20
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;
 }
Пример #21
0
        //-------PRINT
        public ActionResult PurchaseOrder(int Id)
        {
            ReportDocument rd = new ReportDocument();

            rd.Load(Path.Combine(Server.MapPath("~/Reports"), "SupplyOrder.rpt"));

            DataSet ds = new DataSet();

            ds.Tables.Add("Head");

            ds.Tables.Add("Items");

            //-------HEAD
            ds.Tables["Head"].Columns.Add("SupplyOrderNo");
            ds.Tables["Head"].Columns.Add("SupplyOrderDate");
            ds.Tables["Head"].Columns.Add("QuotaionNoAndDate");
            ds.Tables["Head"].Columns.Add("SpecialRemarks");
            ds.Tables["Head"].Columns.Add("PaymentTerms");
            ds.Tables["Head"].Columns.Add("DeliveryTerms");
            ds.Tables["Head"].Columns.Add("RequiredDate");
            ds.Tables["Head"].Columns.Add("CurrencyName");
            ds.Tables["Head"].Columns.Add("CreatedUser");
            ds.Tables["Head"].Columns.Add("CreateSignature");
            ds.Tables["Head"].Columns.Add("ApprovedUser");
            ds.Tables["Head"].Columns.Add("ApproveSignature");
            ds.Tables["Head"].Columns.Add("CountryName");
            //Organization
            ds.Tables["Head"].Columns.Add("DoorNo");
            ds.Tables["Head"].Columns.Add("Street");
            ds.Tables["Head"].Columns.Add("State");
            ds.Tables["Head"].Columns.Add("Country");
            ds.Tables["Head"].Columns.Add("Phone");
            ds.Tables["Head"].Columns.Add("Fax");
            ds.Tables["Head"].Columns.Add("Email");
            ds.Tables["Head"].Columns.Add("ContactPerson");
            ds.Tables["Head"].Columns.Add("Zip");
            ds.Tables["Head"].Columns.Add("OrganizationName");
            ds.Tables["Head"].Columns.Add("Image1");
            ds.Tables["Head"].Columns.Add("SupplierName");

            ds.Tables["Head"].Columns.Add("SupDoorNo");
            ds.Tables["Head"].Columns.Add("SupState");
            ds.Tables["Head"].Columns.Add("SupCountryName");
            ds.Tables["Head"].Columns.Add("SupPhone");
            ds.Tables["Head"].Columns.Add("SupFax");
            ds.Tables["Head"].Columns.Add("SupEmail");
            ds.Tables["Head"].Columns.Add("SupPostBoxNo");
            ds.Tables["Head"].Columns.Add("CreatedDes");
            ds.Tables["Head"].Columns.Add("ApproveDes");
            ds.Tables["Head"].Columns.Add("NetDiscount");
            ds.Tables["Head"].Columns.Add("NetAmount");


            //-------DT
            ds.Tables["Items"].Columns.Add("PRNODATE");
            ds.Tables["Items"].Columns.Add("PartNo");
            ds.Tables["Items"].Columns.Add("ItemName");
            ds.Tables["Items"].Columns.Add("BalQty");
            ds.Tables["Items"].Columns.Add("OrderedQty");
            ds.Tables["Items"].Columns.Add("Rate");
            ds.Tables["Items"].Columns.Add("Discount");
            ds.Tables["Items"].Columns.Add("Amount");
            ds.Tables["Items"].Columns.Add("ItemRefNo");
            ds.Tables["Items"].Columns.Add("UnitName");
            ds.Tables["Items"].Columns.Add("Description");



            SupplyOrderRepository repo = new SupplyOrderRepository();
            var Head = repo.GetSupplyOrderHDprint(Id, OrganizationId);

            DataRow dr = ds.Tables["Head"].NewRow();

            dr["SupplyOrderNo"]     = Head.SupplyOrderNo;
            dr["SupplyOrderDate"]   = Head.SupplyOrderDate.ToString("dd-MMM-yyyy");
            dr["SupplierName"]      = Head.SupplierName;
            dr["QuotaionNoAndDate"] = Head.QuotaionNoAndDate;
            dr["SpecialRemarks"]    = Head.SpecialRemarks;
            dr["PaymentTerms"]      = Head.PaymentTerms;
            dr["DeliveryTerms"]     = Head.DeliveryTerms;
            dr["RequiredDate"]      = Head.RequiredDate;
            dr["CurrencyName"]      = Head.CurrencyName;
            dr["CreatedUser"]       = Head.CreatedUser;
            dr["CreateSignature"]   = Server.MapPath("~/App_Images/") + Head.CreatedUsersig;
            dr["ApprovedUser"]      = Head.ApprovedUser;
            dr["ApproveSignature"]  = Server.MapPath("~/App_Images/") + Head.ApprovedUsersig;
            dr["CreatedDes"]        = Head.CreatedDes;
            dr["ApproveDes"]        = Head.ApprovedDes;
            dr["CountryName"]       = Head.CountryName;
            // dr["CurrencyName"] = Head.CurrencyName;

            dr["DoorNo"]        = Head.DoorNo;
            dr["Street"]        = Head.Street;
            dr["State"]         = Head.State;
            dr["Country"]       = Head.CountryName;
            dr["Phone"]         = Head.Phone;
            dr["Fax"]           = Head.Fax;
            dr["Email"]         = Head.Email;
            dr["ContactPerson"] = Head.ContactPerson;
            dr["Zip"]           = Head.Zip;
            dr["CurrencyName"]  = Head.CurrencyName;

            dr["SupDoorNo"]      = Head.SupDoorNo;
            dr["SupState"]       = Head.SupState;
            dr["SupCountryName"] = Head.SupCountryName;
            dr["SupPhone"]       = Head.SupPhone;
            dr["SupFax"]         = Head.SupFax;
            dr["SupEmail"]       = Head.SupEmail;
            dr["SupPostBoxNo"]   = Head.SupPostBoxNo;
            dr["NetDiscount"]    = Head.NetDiscount;
            dr["NetAmount"]      = Head.NetAmount;

            dr["OrganizationName"] = Head.OrganizationName;
            dr["Image1"]           = Server.MapPath("~/App_images/") + Head.Image1;
            ds.Tables["Head"].Rows.Add(dr);

            SupplyOrderItemRepository repo1 = new SupplyOrderItemRepository();
            var Items = repo1.GetSupplyOrderItemsDTPrint(Id);

            foreach (var item in Items)
            {
                var pritem = new SupplyOrderItem
                {
                    PRNODATE    = item.PRNODATE,
                    PartNo      = item.PartNo,
                    ItemName    = item.ItemName,
                    BalQty      = item.BalQty,
                    OrderedQty  = item.OrderedQty,
                    Rate        = item.Rate,
                    Discount    = item.Discount,
                    Amount      = item.Amount,
                    ItemRefNo   = item.ItemRefNo,
                    UnitName    = item.UnitName,
                    Description = item.Description
                };


                DataRow dri = ds.Tables["Items"].NewRow();
                dri["PRNODATE"]    = pritem.PRNODATE;
                dri["PartNo"]      = pritem.PartNo;
                dri["ItemName"]    = pritem.ItemName;
                dri["BalQty"]      = pritem.BalQty;
                dri["OrderedQty"]  = pritem.OrderedQty;
                dri["Rate"]        = pritem.Rate;
                dri["Discount"]    = pritem.Discount;
                dri["Amount"]      = pritem.Amount;
                dri["ItemRefNo"]   = pritem.ItemRefNo;
                dri["UnitName"]    = pritem.UnitName;
                dri["Description"] = pritem.Description;

                ds.Tables["Items"].Rows.Add(dri);
            }

            ds.WriteXml(Path.Combine(Server.MapPath("~/XML"), "SupplyOrder.xml"), XmlWriteMode.WriteSchema);

            rd.SetDataSource(ds);

            Response.Buffer = false;
            Response.ClearContent();
            Response.ClearHeaders();


            try
            {
                Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                stream.Seek(0, SeekOrigin.Begin);
                return(File(stream, "application/pdf"));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Пример #22
0
        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);
                }
            }
        }
		///<summary>Updates one SupplyOrderItem in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.</summary>
		public static void Update(SupplyOrderItem supplyOrderItem,SupplyOrderItem oldSupplyOrderItem){
			string command="";
			if(supplyOrderItem.SupplyOrderNum != oldSupplyOrderItem.SupplyOrderNum) {
				if(command!=""){ command+=",";}
				command+="SupplyOrderNum = "+POut.Long(supplyOrderItem.SupplyOrderNum)+"";
			}
			if(supplyOrderItem.SupplyNum != oldSupplyOrderItem.SupplyNum) {
				if(command!=""){ command+=",";}
				command+="SupplyNum = "+POut.Long(supplyOrderItem.SupplyNum)+"";
			}
			if(supplyOrderItem.Qty != oldSupplyOrderItem.Qty) {
				if(command!=""){ command+=",";}
				command+="Qty = "+POut.Int(supplyOrderItem.Qty)+"";
			}
			if(supplyOrderItem.Price != oldSupplyOrderItem.Price) {
				if(command!=""){ command+=",";}
				command+="Price = '"+POut.Double(supplyOrderItem.Price)+"'";
			}
			if(command==""){
				return;
			}
			command="UPDATE supplyorderitem SET "+command
				+" WHERE SupplyOrderItemNum = "+POut.Long(supplyOrderItem.SupplyOrderItemNum);
			Db.NonQ(command);
		}
		///<summary>Updates one SupplyOrderItem in the database.</summary>
		public static void Update(SupplyOrderItem supplyOrderItem){
			string command="UPDATE supplyorderitem SET "
				+"SupplyOrderNum    =  "+POut.Long  (supplyOrderItem.SupplyOrderNum)+", "
				+"SupplyNum         =  "+POut.Long  (supplyOrderItem.SupplyNum)+", "
				+"Qty               =  "+POut.Int   (supplyOrderItem.Qty)+", "
				+"Price             = '"+POut.Double(supplyOrderItem.Price)+"' "
				+"WHERE SupplyOrderItemNum = "+POut.Long(supplyOrderItem.SupplyOrderItemNum);
			Db.NonQ(command);
		}
Пример #25
0
 ///<summary>Inserts one SupplyOrderItem into the database.  Returns the new priKey.</summary>
 public static long Insert(SupplyOrderItem supplyOrderItem)
 {
     return(Insert(supplyOrderItem, false));
 }