public EpiForm()
        {
            // Change the sysconfig file name to the sysconfig file name you are using to connect to your app server from your client.
            // If you have web services licenses, use the Session.LicenseType.WebService else use Session.LicenseType.Default.
            using (var _session = new Ice.Core.Session("manager", "manager", Session.LicenseType.Default, @"config\ERP10.sysconfig"))
            {
                // 10.1.600.x For some forms a BASE currency must be added to the Session objects CurrencyInfo Hashtable. SalesOrder is
                // one of these forms.
                using (var svc = WCFServiceSupport.CreateImpl <Erp.Proxy.BO.CurrencyImpl>(_session, Erp.Proxy.BO.CurrencyImpl.UriPath))
                {
                    bool outbool;
                    var  defaultcurrency = svc.GetList("BaseCurr = 'TRUE'", 0, 0, out outbool);
                    if (defaultcurrency.Tables[0].Rows.Count == 0)
                    {
                        MessageBox.Show("No BASE currency code is set for Company " + _session.CompanyID, "No BASE Currency", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    var currencyrow = (Erp.BO.CurrencyListDataSet.CurrencyListRow)defaultcurrency.Tables[0].Rows[0];

                    Session.CurrencyInfo ci = new Session.CurrencyInfo("BASE", currencyrow.CurrSymbol,
                                                                       currencyrow.DecimalsGeneral, currencyrow.DecimalsPrice, currencyrow.DecimalsCost);
                    _session.CurrencyCodes.Add("BASE", ci);
                }

                var iLaunch = new ILauncher(_session);
                oTrans = new PartTransaction(iLaunch);


                // Run your methods here and always try to complete the execution of this using block.
                // If you terminate execution prior to that, you will leave an open session and continue to consume a license.
            }
        }
        public void csvRMAProcImportation(DataTable dtCsvRMAData, string file)
        {
            bool   isSoUpdSuccess = false;
            string UserId         = ConfigurationManager.AppSettings["UserId"];
            string Password       = ConfigurationManager.AppSettings["Password"];
            string Company        = ConfigurationManager.AppSettings["Company"];
            string Plant          = ConfigurationManager.AppSettings["Plant"];

            svcRMAProc.RMAProcSvcContractClient svcRMAProcClient = new svcRMAProc.RMAProcSvcContractClient("BasicHttpBinding_RMAProcSvcContract");

            Ice.Core.Session oConn = new Ice.Core.Session(UserId, Password);
            oConn.CompanyID = Company;
            oConn.PlantID   = Plant;
            svcRMAProcClient.ClientCredentials.UserName.UserName = UserId;
            svcRMAProcClient.ClientCredentials.UserName.Password = Password;
            svcRMAProcClient.Endpoint.EndpointBehaviors.Add(new HookServiceBehavior(new Guid(oConn.SessionID), UserId));
            svcRMAProc.RMAProcTableset dsRMAProc = null;
            try
            {
                var distRMANumsByCustID = dtCsvRMAData.AsEnumerable()
                                          .Select(w => new{ UdRMANum = w.Field <string>("UD_RMANum"), custId = w.Field <string>("CustID") })
                                          .Distinct().ToList();
                foreach (var UdRMANum in distRMANumsByCustID)
                {
                    string udRMANo = UdRMANum.UdRMANum.ToString();
                    string custId  = UdRMANum.custId.ToString();
                    sbFileLog.AppendLine("*****************************");

                    //Detail Data
                    var dtlRMACsvData = dtCsvRMAData.AsEnumerable()
                                        .Where(w => w.Field <string>("UD_RMANum") == udRMANo && w.Field <string>("CustID") == custId)
                                        .Select(s => new
                    {
                        udRMNo        = s.Field <string>("UD_RMANum"),
                        whseCode      = s.Field <string>("Whse_Code"),
                        plant         = s.Field <string>("Plant"),
                        rmaDate       = s.Field <string>("RMADate"),
                        rmaLn         = Convert.ToInt32(s.Field <string>("RMALine")),
                        udCustRTVNo   = s.Field <string>("UD_CustRTVNum"),
                        refrnc        = s.Field <string>("Reference"),
                        partNo        = s.Field <string>("PartNum"),
                        retQty        = s.Field <string>("ReturnQty"),
                        retQtyUom     = s.Field <string>("ReturnQtyUOM"),
                        retReasonCode = s.Field <string>("ReturnReasonCode")
                                        //rcvDate = s.Field<string>("RcvDate"),
                                        //rcvQty = s.Field<string>("ReceivedQty"),
                                        //rcvQtyUom = s.Field<string>("ReceivedQtyUOM"),
                                        //binNum = s.Field<string>("BinNum")
                    }).Distinct()
                                        .ToList().OrderBy(o => o.rmaLn);
                    DateTime  rmaDate            = Convert.ToDateTime(dtlRMACsvData.Select(s => s.rmaDate).FirstOrDefault());
                    int       custNum            = oDAL.GetCustNum(custId);
                    DataTable dtRMAHeadbyUdRMANo = new DataTable();
                    dtRMAHeadbyUdRMANo = oDAL.UdRMANumExistInRMAHead(udRMANo, custNum);
                    int RMAHdNum = 0;
                    if (dtRMAHeadbyUdRMANo.Rows.Count > 0)
                    {
                        RMAHdNum       = dtRMAHeadbyUdRMANo.Rows[0].Field <int>("RMANum");
                        dsRMAProc      = svcRMAProcClient.GetByID(RMAHdNum);
                        isSoUpdSuccess = true;
                        sbFileLog.AppendLine("RMANum=" + RMAHdNum.ToString() + " Already Exist for this UD_RMANum=" + udRMANo + " and CustId=" + custId);
                    }
                    else
                    {
                        dsRMAProc = new svcRMAProc.RMAProcTableset();
                        svcRMAProcClient.GetNewRMAHead(ref dsRMAProc);
                        int lastRMAHeadIndex = dsRMAProc.RMAHead.Count - 1;
                        dsRMAProc.RMAHead[lastRMAHeadIndex].RMADate = rmaDate;
                        svcRMAProcClient.ChangeCustomer(ref dsRMAProc, custId);
                        //svcRMAProcClient.ChangeRMAHeadLegalNumber();
                        svcRMAProcClient.PreUpdate(ref dsRMAProc);
                        svcRMAProcClient.Update(ref dsRMAProc);
                        //UD Table updation by SysRowID
                        string sysRowId    = dsRMAProc.RMAHead[lastRMAHeadIndex].SysRowID.ToString();
                        string udCustRTVNo = dtlRMACsvData.Select(s => s.udCustRTVNo).FirstOrDefault();
                        bool   isUpd       = oDAL.UpdateRMAHead_UDTable(sysRowId, udRMANo, udCustRTVNo);
                        if (isUpd)
                        {
                            //RMAHead_UD table updation Success.
                            sbFileLog.AppendLine("RMAHead_UD table updated.");
                        }
                        isSoUpdSuccess = true;
                        RMAHdNum       = dsRMAProc.RMAHead[lastRMAHeadIndex].RMANum;
                        sbFileLog.AppendLine("RMANum=" + RMAHdNum.ToString() + " Created for this UD_RMANum=" + udRMANo + " and CustId=" + custId);
                    }

                    //int lastRMAHdIndex = dsRMAProc.RMAHead.Count - 1;
                    //int RMAHdNum = dsRMAProc.RMAHead[lastRMAHdIndex].RMANum;
                    foreach (var dtlrow in dtlRMACsvData)
                    {
                        int       rmaLn    = Convert.ToInt32(dtlrow.rmaLn.ToString());
                        int       erpRMALn = 0;
                        DataTable dtRMADtl = new DataTable();
                        dtRMADtl = oDAL.GetRMADtl(udRMANo, RMAHdNum, rmaLn, dtlrow.partNo);
                        if (dtRMADtl.Rows.Count > 0)
                        {
                            //Already exist this record
                            erpRMALn       = dtRMADtl.Rows[0].Field <int>("ErpRMALine");
                            isSoUpdSuccess = true;
                            sbFileLog.AppendLine();
                            sbFileLog.AppendLine("RMALine=" + erpRMALn.ToString() + " Already Exist for this UD_RMANum=" + udRMANo + " and CustId=" + custId + " and CSVRMALine=" + rmaLn.ToString());
                        }
                        else
                        {
                            string      cPartNum       = dtlrow.partNo;
                            System.Guid SysRowID       = new Guid("00000000-0000-0000-0000-000000000000");
                            string      rowType        = string.Empty;
                            string      questionString = string.Empty;
                            bool        multipleMatch  = false;
                            svcRMAProcClient.GetNewRMADtl(ref dsRMAProc, RMAHdNum);
                            int lastRMADtlIndex = dsRMAProc.RMADtl.Count - 1;
                            svcRMAProcClient.ChangePartNum(ref dsRMAProc, ref cPartNum, SysRowID, rowType, out questionString, out multipleMatch);
                            dsRMAProc.RMADtl[lastRMADtlIndex].ReturnQty        = Convert.ToDecimal(dtlrow.retQty);
                            dsRMAProc.RMADtl[lastRMADtlIndex].ReturnQtyUOM     = dtlrow.retQtyUom;
                            dsRMAProc.RMADtl[lastRMADtlIndex].ReturnReasonCode = dtlrow.retReasonCode;
                            svcRMAProcClient.PreUpdate(ref dsRMAProc);
                            svcRMAProcClient.Update(ref dsRMAProc);
                            erpRMALn = dsRMAProc.RMADtl[lastRMADtlIndex].RMALine;

                            //WMSRMADtl table need to update to track csv data history with Erp RMA data.
                            oDAL.InsertWMSRMADtlInDataMigration(udRMANo, rmaLn, dtlrow.partNo, RMAHdNum, erpRMALn);
                            isSoUpdSuccess = true;
                            sbFileLog.AppendLine("RMALine=" + erpRMALn.ToString() + " Created for this UD_RMANum=" + udRMANo + " and CustId=" + custId + " and CSVRMALine=" + rmaLn.ToString());
                        }
                        //RMAReceipt Data processing...

                        var dtlRMARcptCsvData = dtCsvRMAData.AsEnumerable()
                                                .Where(w => w.Field <string>("UD_RMANum") == udRMANo && w.Field <string>("CustID") == custId && w.Field <string>("RMALine") == Convert.ToString(dtlrow.rmaLn))
                                                .Select(s => new
                        {
                            udRMNo        = s.Field <string>("UD_RMANum"),
                            whseCode      = s.Field <string>("Whse_Code"),
                            plant         = s.Field <string>("Plant"),
                            rmaDate       = s.Field <string>("RMADate"),
                            rmaLn         = Convert.ToInt32(s.Field <string>("RMALine")),
                            udCustRTVNo   = s.Field <string>("UD_CustRTVNum"),
                            refrnc        = s.Field <string>("Reference"),
                            partNo        = s.Field <string>("PartNum"),
                            retQty        = s.Field <string>("ReturnQty"),
                            retQtyUom     = s.Field <string>("ReturnQtyUOM"),
                            retReasonCode = s.Field <string>("ReturnReasonCode"),
                            rcvDate       = Convert.ToDateTime(s.Field <string>("RcvDate")),
                            rcvQty        = Convert.ToDecimal(s.Field <string>("ReceivedQty")),
                            rcvQtyUom     = s.Field <string>("ReceivedQtyUOM"),
                            binNum        = s.Field <string>("BinNum")
                        }).Distinct()
                                                .ToList().OrderBy(o => o.rcvDate);
                        foreach (var dtlRcptRow in dtlRMARcptCsvData)
                        {
                            //string partNo = Regex.Replace(dtlRcptRow.partNo, @"\s+", "");
                            int erpRMAReceiptNo  = 0;
                            var matchRMARcptData = dsRMAProc.RMARcpt.AsEnumerable()
                                                   .Where(w =>

                                                          w.RMANum == RMAHdNum &&
                                                          w.RMALine == erpRMALn &&
                                                          w.RcvDate == dtlRcptRow.rcvDate &&
                                                          w.ThisRcptQty == dtlRcptRow.rcvQty &&
                                                          w.PartNum == dtlRcptRow.partNo.Trim() &&
                                                          w.ThisRcptQtyUOM == dtlRcptRow.rcvQtyUom
                                                          ).Select(s => s.RMAReceipt).ToList();
                            int i = matchRMARcptData.Count;
                            if (i > 0)
                            {
                                //already exist data
                                erpRMAReceiptNo = matchRMARcptData.FirstOrDefault();
                                sbFileLog.AppendLine("RMAReceipt=" + erpRMAReceiptNo.ToString() + " Already exist for this RMALine=" + erpRMALn.ToString());
                            }
                            else
                            {
                                svcRMAProcClient.GetNewRMARcpt(ref dsRMAProc, RMAHdNum, erpRMALn);
                                int lastRcptIndex = dsRMAProc.RMARcpt.Count - 1;
                                dsRMAProc.RMARcpt[lastRcptIndex].RcvDate        = dtlRcptRow.rcvDate;
                                dsRMAProc.RMARcpt[lastRcptIndex].ReceivedQty    = dtlRcptRow.rcvQty;
                                dsRMAProc.RMARcpt[lastRcptIndex].ReceivedQtyUOM = dtlRcptRow.rcvQtyUom;
                                dsRMAProc.RMARcpt[lastRcptIndex].WareHouseCode  = dtlRcptRow.binNum;
                                dsRMAProc.RMARcpt[lastRcptIndex].BinNum         = dtlRcptRow.binNum;
                                svcRMAProcClient.ChangeWarehouse(ref dsRMAProc);
                                svcRMAProcClient.PreUpdate(ref dsRMAProc);
                                svcRMAProcClient.Update(ref dsRMAProc);
                                erpRMAReceiptNo = dsRMAProc.RMARcpt[lastRcptIndex].RMAReceipt;
                                sbFileLog.AppendLine("RMAReceipt=" + erpRMAReceiptNo.ToString() + " Created for this RMALine=" + erpRMALn.ToString());
                            }
                        }
                        //RMAReceipt Data Process done.
                    }
                }
            }
            catch (Exception ex)
            {
                isSoUpdSuccess = false;
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                if (isSoUpdSuccess == false)
                {
                    sbFileLog.AppendLine("Error Occured...");
                    MoveFile(failedLocation, file);
                    sbFileLog.AppendLine(file + " File Moved to " + failedLocation);
                }
                else
                {
                    MoveFile(successLocation, file);
                    sbFileLog.AppendLine(file + " File Moved to " + successLocation);
                }
                if (dsRMAProc != null)
                {
                    dsRMAProc = null;
                }

                if (oConn != null)
                {
                    oConn.Dispose();
                    oConn = null;
                }
            }
        }
示例#3
0
        public void csvStockAdjustment(DataTable dtCsvStkAdj, string file)
        {
            bool   isSoUpdSuccess = false;
            string UserId         = ConfigurationManager.AppSettings["UserId"];
            string Password       = ConfigurationManager.AppSettings["Password"];
            string Company        = ConfigurationManager.AppSettings["Company"];
            string Plant          = ConfigurationManager.AppSettings["Plant"];

            svcInvQtyAdj.InventoryQtyAdjSvcContractClient svcInvStkAdjClient = new svcInvQtyAdj.InventoryQtyAdjSvcContractClient("BasicHttpBinding_InventoryQtyAdjSvcContract");
            Ice.Core.Session oConn = new Ice.Core.Session(UserId, Password);
            oConn.CompanyID = Company;
            oConn.PlantID   = Plant;
            svcInvStkAdjClient.ClientCredentials.UserName.UserName = UserId;
            svcInvStkAdjClient.ClientCredentials.UserName.Password = Password;
            svcInvStkAdjClient.Endpoint.EndpointBehaviors.Add(new HookServiceBehavior(new Guid(oConn.SessionID), UserId));
            svcInvQtyAdj.InventoryQtyAdjTableset dsInvStkAdj = null;
            try
            {
                //svcInvQtyAdj.InventoryQtyAdjBrwTableset dsInvStkAdjBrw = null;
                var distCsvStkAdjs = dtCsvStkAdj.AsEnumerable().Select(s => new
                {
                    plant       = s.Field <string>("Plant"),
                    comp        = s.Field <string>("Company"),
                    partNo      = s.Field <string>("PartNum").Trim(),
                    wareHseCode = s.Field <string>("WareHseCode"),
                    binNo       = s.Field <string>("BinNum"),
                    adjQty      = Convert.ToDecimal(s.Field <string>("AdjustQuantity")),
                    uom         = s.Field <string>("UnitOfMeasure"),
                    reasonCode  = s.Field <string>("ReasonCode"),
                    transDate   = Convert.ToDateTime(s.Field <string>("TransDate")),
                    reference   = s.Field <string>("Reference")
                }).Distinct().ToList();

                foreach (var stkAdjrow in distCsvStkAdjs)
                {
                    string fileName = Path.GetFileNameWithoutExtension(file);
                    int    cnt      = oDAL.RowExistInWMSStockAdjHistory(fileName, stkAdjrow.plant, stkAdjrow.comp, stkAdjrow.partNo, stkAdjrow.wareHseCode, stkAdjrow.binNo, stkAdjrow.adjQty, stkAdjrow.uom, stkAdjrow.reasonCode, stkAdjrow.transDate, stkAdjrow.reference);
                    sbFileLog.AppendLine("PartNum=" + stkAdjrow.partNo.ToString() + " AdjQty=" + stkAdjrow.adjQty.ToString() + " TranDate=" + stkAdjrow.transDate.ToString("yyyy-MM-dd") + " Reference=" + stkAdjrow.reference.ToString());
                    if (cnt > 0)
                    {
                        //Already exist...
                        sbFileLog.AppendLine("Already Updated...");
                        isSoUpdSuccess = true;
                    }
                    else
                    {
                        dsInvStkAdj = new svcInvQtyAdj.InventoryQtyAdjTableset();

                        dsInvStkAdj = svcInvStkAdjClient.GetInventoryQtyAdj(stkAdjrow.partNo, "");

                        dsInvStkAdj.InventoryQtyAdj[0].AdjustQuantity = stkAdjrow.adjQty;
                        dsInvStkAdj.InventoryQtyAdj[0].WareHseCode    = stkAdjrow.wareHseCode;
                        dsInvStkAdj.InventoryQtyAdj[0].BinNum         = stkAdjrow.binNo;
                        dsInvStkAdj.InventoryQtyAdj[0].ReasonCode     = stkAdjrow.reasonCode;
                        //dsInvStkAdj.InventoryQtyAdj[0].ReasonCodeDescription = "Cycle Count Difference";
                        //dsInvStkAdj.InventoryQtyAdj[0].WhseBinDescription = "Default";
                        dsInvStkAdj.InventoryQtyAdj[0].UnitOfMeasure = stkAdjrow.uom;
                        svcInvStkAdjClient.PreSetInventoryQtyAdj(ref dsInvStkAdj);

                        dsInvStkAdj.InventoryQtyAdj[0].RowMod = "U";

                        svcInvStkAdjClient.SetInventoryQtyAdj(ref dsInvStkAdj);

                        //Update StkAdjHistory table
                        oDAL.InsertWMSStockAdjHistory(fileName, stkAdjrow.plant, stkAdjrow.comp, stkAdjrow.partNo, stkAdjrow.wareHseCode, stkAdjrow.binNo, stkAdjrow.adjQty, stkAdjrow.uom, stkAdjrow.reasonCode, stkAdjrow.transDate, stkAdjrow.reference);
                        sbFileLog.AppendLine("Quantity Adjustment Updated...");
                        isSoUpdSuccess = true;
                    }
                }
            }
            catch (Exception ex)
            {
                isSoUpdSuccess = false;
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                if (isSoUpdSuccess == false)
                {
                    sbFileLog.AppendLine("Error Occured...");
                    MoveFile(failedLocation, file);
                    sbFileLog.AppendLine(file + " File Moved to " + failedLocation);
                }
                else
                {
                    MoveFile(successLocation, file);
                    sbFileLog.AppendLine(file + " File Moved to " + successLocation);
                }
                if (dsInvStkAdj != null)
                {
                    dsInvStkAdj = null;
                }

                if (oConn != null)
                {
                    oConn.Dispose();
                    oConn = null;
                }
            }
        }