Example #1
0
        private void btnPO_Click(object sender, EventArgs e)
        {
            if (InitExcel("Purchase Order") == false)
                return;

            UnitOfWork uow = new UnitOfWork();
            PurchOrderLine poLine;
            int row = 3;
            uow.BeginTransaction();

            while (ExcelHelper.GetCellStringValue(xlSht, row, 1) != "")
            {
                poLine = new PurchOrderLine(uow);
                poLine.SetPurchOrderLineNo(ExcelHelper.GetCellStringValue(xlSht, row, 1));
                poLine.Item = Item.FindItem(uow, ExcelHelper.GetCellStringValue(xlSht, row, 2));
                poLine.OrderType = uow.FindObject<OrderType>(new BinaryOperator("Name", ExcelHelper.GetCellStringValue(xlSht, row, 3)));
                poLine.Vendor = uow.FindObject<Vendor>(new BinaryOperator("No", ExcelHelper.GetCellStringValue(xlSht, row, 4)));
                poLine.PriceUnit = uow.FindObject<Unit>(new BinaryOperator("UnitName", ExcelHelper.GetCellStringValue(xlSht, row, 5)));
                poLine.NeedQty = ExcelHelper.GetCellIntValue(xlSht, row, 8);
                poLine.NeedDate = ExcelHelper.GetCellDateTimeValue(xlSht, row, 9);
                poLine.Price = ExcelHelper.GetCellFloatValue(xlSht, row, 10);
                poLine.Save();
                poLine.ApproveOrder();
                poLine.IssuePurchOrder(uow);

                row++;
            }
            uow.CommitTransaction();
            ReleaseExcel();
        }
        public void ImportHKIPO()
        {
            string ipoPath = "http://nwszmail/public/namwah/WorkOrders/Purchasing/InternalPurchaseOrders";
            string strSQL = "";

            ADODB.Connection cnn = new ADODB.Connection();
            ADODB.Recordset rst = new ADODB.Recordset();
            Item item;
            PurchOrderLine poLine;
            WorkOrder wo;

            string partNo;
            string woNo;
            string ipoNo;

            session.BeginTransaction();

            CacheItem();
            CacheWo();
            CacheIpo();

            ConnectDB(cnn, ipoPath);

            strSQL = "SELECT \"nw:partno\" , \"nw:partname\", \"nw:parttype\", \"nw:wo:no\", \"nw:supplier\",  ";
            strSQL = strSQL + " \"nw:jo:needqty\", \"nw:jo:needdate\", \"nw:jo:arrivedqty\", \"nw:jo:no\" ";
            strSQL = strSQL + " FROM \"" + ipoPath;
            strSQL = strSQL + "\" WHERE (\"DAV:ishidden\" = false)";

            rst.Open(strSQL, cnn, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockBatchOptimistic, 1);

            while (!rst.EOF)
            {
                partNo = rst.Fields["nw:partno"].Value.ToString();
                woNo = rst.Fields["nw:wo:no"].Value.ToString();
                ipoNo = rst.Fields["nw:jo:no"].Value.ToString();

                if (dictPoLine.ContainsKey(ipoNo))
                {
                    PurchOrderLine oldPoLine = dictPoLine[ipoNo];

                    if (oldPoLine.NeedQty != float.Parse(rst.Fields["nw:jo:needqty"].Value.ToString()) ||
                    oldPoLine.ReceivedQty != float.Parse(rst.Fields["nw:jo:arrivedqty"].Value.ToString()))
                    {
                        oldPoLine.NeedQty = float.Parse(rst.Fields["nw:jo:needqty"].Value.ToString());
                        oldPoLine.SetReceivedQty(float.Parse(rst.Fields["nw:jo:arrivedqty"].Value.ToString()));
                        oldPoLine.Save();
                    }
                }
                else
                {
                    if (dictItem.ContainsKey(partNo) && dictWo.ContainsKey(woNo))
                    {
                        item = dictItem[partNo];
                        wo = dictWo[woNo];

                        poLine = new PurchOrderLine(session);
                        poLine.WorkOrder = wo;
                        poLine.Item = item;
                        poLine.SetPurchOrderLineNo(ipoNo);
                        poLine.NeedDate = DateTime.Parse(rst.Fields["nw:jo:needdate"].Value.ToString());
                        poLine.NeedQty = float.Parse(rst.Fields["nw:jo:needqty"].Value.ToString());
                        poLine.Vendor = GetVendor(rst.Fields["nw:supplier"].Value.ToString());
                        poLine.SetReceivedQty(float.Parse(rst.Fields["nw:jo:arrivedqty"].Value.ToString()));
                        poLine.Unit = item.Unit;
                        poLine.Warehouse = item.Warehouse;
                        poLine.Save();
                    }
                }
                rst.MoveNext();
            }

            session.CommitTransaction();
        }