예제 #1
0
파일: Service.cs 프로젝트: Osama91/CCWFM
 private TblService UpdateOrInsertTblService(TblService newRow, bool save, int index, int user, out int outindex)
 {
     outindex = index;
     using (var context = new WorkFlowManagerDBEntities())
     {
         if (save)
         {
             context.TblServices.AddObject(newRow);
         }
         else
         {
             var oldRow = (from e in context.TblServices
                           where e.Iserial == newRow.Iserial
                           select e).SingleOrDefault();
             if (oldRow != null)
             {
                 GenericUpdate(oldRow, newRow, context);
             }
         }
         context.SaveChanges();
         if (SharedOperation.UseAx())
         {
             if (save)
             {
                 InsertServiceItem(newRow, user);
             }
         }
         return(newRow);
     }
 }
예제 #2
0
        public tbl_AccessoryAttributesHeader UpdateAccessoriesAttributes(
            tbl_AccessoryAttributesHeader header
            , List <tbl_AccessoryAttributesDetails> detailsToAdd
            , List <tbl_AccessoryAttributesDetails> detailsToUpdate, int userIserial)
        {
            try
            {
                //InsertAllNewAccessoryToAx(detailsToAdd, header, true);
                using (var context = new WorkFlowManagerDBEntities())
                {
                    //       var htemp = context.tbl_AccessoryAttributesHeader.FirstOrDefault(x => x.Code == header.Code);
                    //     GenericUpdate(htemp, header, context);
                    //      var colorGroup = context.TblLkpColorGroups.FirstOrDefault(x => x.Code == "Acc").Iserial;
                    foreach (var item in detailsToUpdate)
                    {
                        var dtemp =
                            context.tbl_AccessoryAttributesDetails.FirstOrDefault(
                                x => x.Iserial == item.Iserial);
                        GenericUpdate(dtemp, item, context);
                    }

                    if (SharedOperation.UseAx())
                    {
                        try
                        {
                            UpdateAccDetailsInAX(detailsToUpdate, userIserial);
                            InsertAllNewAccessoryToAx(detailsToUpdate, header, false, userIserial);
                        }
                        catch (Exception)
                        {
                        }
                    }
                    foreach (var item in detailsToAdd)
                    {
                        context.tbl_AccessoryAttributesDetails.AddObject(item);
                    }
                    if (SharedOperation.UseAx())
                    {
                        try
                        {
                            UpdateAccDetailsInAX(detailsToAdd, userIserial);
                        }
                        catch (Exception)
                        {
                        }
                    }

                    context.SaveChanges();

                    return(context.tbl_AccessoryAttributesHeader.Include(nameof(tbl_AccessoryAttributesHeader.tbl_AccessoryAttributesDetails)).FirstOrDefault(x => x.Code == header.Code));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #3
0
        public void DeleteReservationOrder(Tbl_ReservationHeader reservationHeader, int userIserial)
        {
            var axapta = new Axapta();//Ready To be Dependent from Ax

            if (SharedOperation.UseAx())
            {
                var         credential = new NetworkCredential("bcproxy", "around1");
                TblAuthUser userToLogin;
                using (var model = new WorkFlowManagerDBEntities())
                {
                    userToLogin = model.TblAuthUsers.SingleOrDefault(x => x.Iserial == userIserial);
                }
                axapta.LogonAs(userToLogin.User_Win_Login, userToLogin.User_Domain, credential, "Ccm", null, null, null);
            }
            using (var entities = new WorkFlowManagerDBEntities())
            {
                var headerRow =
                    entities.Tbl_ReservationHeader.SingleOrDefault(x => x.Iserial == reservationHeader.Iserial);
                var rows = entities.Tbl_ReservationMainDetails.Include("Tbl_ReservationDetails").Include("Tbl_ReservationHeader1").Where(x => x.Tbl_ReservationHeader == reservationHeader.Iserial);

                foreach (var mainRow in rows)
                {
                    foreach (var detailsRow in mainRow.Tbl_ReservationDetails.ToList())
                    {
                        entities.DeleteObject(detailsRow);
                        if (SharedOperation.UseAx())
                        {
                            var importNew = axapta.CreateAxaptaObject("CreateProductionJournals");

                            if (detailsRow.AxPicklingListJournal != null)
                            {
                                importNew.Call("deletejournal", 0, detailsRow.AxPicklingListJournal, 0);
                            }
                        }
                    }
                    entities.DeleteObject(mainRow);
                }

                entities.DeleteObject(headerRow);
                entities.SaveChanges();
            }
            if (SharedOperation.UseAx())
            {
                axapta.Logoff();
            }
        }
예제 #4
0
        public void DeleteRoutCard(int routeHeader, int userIserial)
        {
            using (var context = new WorkFlowManagerDBEntities())
            {
                var rch = (context.RouteCardHeaders.SingleOrDefault(x => x.Iserial == routeHeader));

                var det = context.RouteCardDetails.Where(x => x.Direction == rch.Direction && x.RoutGroupID == rch.RoutGroupID &&
                                                         x.Trans_TransactionHeader == rch.TransID);
                foreach (var item in det)
                {
                    context.DeleteObject(item);
                }
                if (SharedOperation.UseAx())
                {
                    DeleteAXroute(rch, userIserial);
                }
                context.DeleteObject(rch);
                context.SaveChanges();
            }
        }
예제 #5
0
        private void TerminateEmp(string emp)
        {
            if (SharedOperation.UseAx())
            {
                var Axapta     = new Axapta();
                var credential = new NetworkCredential("bcproxy", "around1");
                Axapta.LogonAs("Osama.Gamal", "ccasual.loc", credential, "Ccm", "", "", "");
                var AxaptaRecord = Axapta.CreateAxaptaRecord("EMPLTABLE");
                AxaptaRecord.Clear();
                AxaptaRecord.InitValue();

                AxaptaRecord.ExecuteStmt("select forupdate * from %1 where %1.Emplid == '" + emp + "");
                if (AxaptaRecord.Found)
                {
                    AxaptaRecord.set_Field("CSPPeriodID", "2012");
                    AxaptaRecord.Update();
                    Axapta.TTSCommit();
                }
            }
        }
예제 #6
0
        public tbl_AccessoryAttributesHeader AddAllNewAccessoriesAttributes(tbl_AccessoryAttributesHeader header
                                                                            , List <tbl_AccessoryAttributesDetails> details, bool isSizeInHeader, int userIserial)
        {
            try
            {
                using (var context = new WorkFlowManagerDBEntities())
                {
                    if (!context.tbl_AccessoryAttributesHeader.Any(x => x.Code == header.Code))
                    {
                        context.tbl_AccessoryAttributesHeader.AddObject(header);
                    }
                    //       var colorGroup = context.TblLkpColorGroups.FirstOrDefault(x => x.Code == "Acc").Iserial;

                    if (SharedOperation.UseAx())
                    {
                        try
                        {
                            InsertAllNewAccessoryToAx(details, header, isSizeInHeader, userIserial);
                        }
                        catch (Exception)
                        {
                        }
                    }
                    foreach (var item in details)
                    {
                        context.tbl_AccessoryAttributesDetails.AddObject(item);
                    }

                    context.SaveChanges();

                    return(context.tbl_AccessoryAttributesHeader.Include(nameof(tbl_AccessoryAttributesHeader.tbl_AccessoryAttributesDetails)).FirstOrDefault(x => x.Code == header.Code));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #7
0
        private int DeleteAccDetail(tbl_AccessoryAttributesDetails row, int userIserial)
        {
            using (var context = new WorkFlowManagerDBEntities())
            {
                var oldRow = (from e in context.tbl_AccessoryAttributesDetails.Include(nameof(tbl_AccessoryAttributesDetails.tbl_AccessoryAttributesHeader))
                              where e.Iserial == row.Iserial
                              select e).SingleOrDefault();
                if (oldRow != null)
                {
                    if (SharedOperation.UseAx())
                    {
                        if (!DeletedAxComination(oldRow, userIserial))
                        {
                            return(0);
                        }
                    }

                    context.DeleteObject(oldRow);
                    context.SaveChanges();
                }
            }
            return(row.Iserial);
        }
예제 #8
0
        private void IssueJournalTransfer(TblIssueJournalHeader row, int userIserial)
        {
            using (var entities = new WorkFlowManagerDBEntities())
            {
                if (SharedOperation.UseAx())
                {
                    var          transactionGuid   = Guid.NewGuid().ToString();
                    var          vendorWmsLocation = entities.GetWmsLocations.SingleOrDefault(x => x.VENDID == row.Vendor);
                    const string tableName         = "PRODCONNECTION";
                    var          vendorLoc         = entities.GetLocations.SingleOrDefault(x => x.INVENTLOCATIONID == vendorWmsLocation.INVENTLOCATIONID);
                    var          axapta            = new Axapta();
                    var          credential        = new NetworkCredential("bcproxy", "around1");
                    var          detail            = entities.TblIssueJournalDetails.Where(w => w.TblIssueJournalHeader == row.Iserial).ToList();

                    var userToLogin = entities.TblAuthUsers.SingleOrDefault(x => x.Iserial == userIserial);
                    axapta.LogonAs(userToLogin.User_Win_Login, userToLogin.User_Domain, credential, "Ccm", null, null, null);
                    axapta.CallStaticClassMethod("SysFlushAOD", "doFlush");
                    foreach (var item in detail)
                    {
                        var locationLoc = entities.GetLocations.SingleOrDefault(x => x.INVENTLOCATIONID == item.Location);

                        AxaptaRecord AxaptaRecord = axapta.CreateAxaptaRecord(tableName);
                        AxaptaRecord.Clear();
                        AxaptaRecord.InitValue();

                        //Transfer To Vendor's Location
                        var fabriccode = entities.Fabric_UnitID.FirstOrDefault(w => w.Iserial == item.ItemCode);
                        AxaptaRecord.set_Field("TRANSID", row.Iserial);
                        AxaptaRecord.set_Field("RAWID", fabriccode.Fabric_Code);
                        AxaptaRecord.set_Field("RAWQTY", item.Qty);
                        AxaptaRecord.set_Field("UNITID", fabriccode.UnitID);
                        if (locationLoc != null)
                        {
                            AxaptaRecord.set_Field("FROMSITE", locationLoc.INVENTSITEID);
                        }
                        AxaptaRecord.set_Field("FROMLOCATION", item.Location);
                        AxaptaRecord.set_Field("FROMWAREHOUSE", item.Location);
                        AxaptaRecord.set_Field("FROMBATCH", item.Size ?? "Free");
                        AxaptaRecord.set_Field("FROMCONFIG",
                                               entities.TblColors.FirstOrDefault(x => x.Iserial == item.TblColor).Code);
                        if (vendorLoc != null)
                        {
                            AxaptaRecord.set_Field("TOSITE", vendorLoc.INVENTSITEID);
                        }
                        if (vendorWmsLocation != null)
                        {
                            AxaptaRecord.set_Field("TOLOCATION", vendorWmsLocation.WMSLOCATIONID);
                            AxaptaRecord.set_Field("TOWAREHOUSE", vendorWmsLocation.INVENTLOCATIONID);
                        }
                        AxaptaRecord.set_Field("TOBATCH", item.Size ?? item.BatchNo ?? "Free");
                        AxaptaRecord.set_Field("TOCONFIG",
                                               entities.TblColors.FirstOrDefault(x => x.Iserial == item.TblColor).Code);
                        AxaptaRecord.set_Field("TRANSTYPE", Convert.ToInt64(0));
                        AxaptaRecord.set_Field("JOURNALLINKID", row.Iserial);
                        AxaptaRecord.set_Field("TransactionGuid", transactionGuid);
                        AxaptaRecord.Insert();
                    }
                    var import = axapta.CreateAxaptaObject("CLEDyeProcesse");
                    try
                    {
                        var transfer = import.Call("run", row.Iserial, row.Iserial, 0, "Name", 1, DateTime.UtcNow.ToUniversalTime());
                        row.AxTransaction = transfer.ToString();
                        row.IsPosted      = true;
                        entities.SaveChanges();
                    }
                    catch (Exception)
                    {
                        throw;
                    }

                    SharedOperation.ClearAxTable("PRODCONNECTION", axapta, transactionGuid);
                    axapta.Logoff();
                }
                else
                {
                    row.AxTransaction = "1111";
                    row.IsPosted      = true;
                    entities.SaveChanges();
                }
            }
        }
예제 #9
0
        private bool PostBomToAx(TblSalesOrder row, int userIserial)
        {
            var credential = new NetworkCredential("bcproxy", "around1");
            var success    = false;

            try
            {
                if (SharedOperation.UseAx())
                {
                    var         ax = new Axapta();//Ready To be Dependent from Ax;
                    TblAuthUser userToLogin;
                    using (var model = new WorkFlowManagerDBEntities())
                    {
                        userToLogin = model.TblAuthUsers.SingleOrDefault(x => x.Iserial == userIserial);
                    }
                    ax.LogonAs(userToLogin.User_Win_Login, userToLogin.User_Domain, credential, "Ccm", null, null, null);
                    AxaptaObject import = ax.CreateAxaptaObject("NRunIntegration1");
                    var          retval = import.Call("run", row.SalesOrderCode);
                    if (retval.ToString() == "")
                    {
                        success = true;
                    }
                    ax.Logoff();
                }
                using (var context = new WorkFlowManagerDBEntities())
                {
                    var temp = context.TblSalesOrders.Include("TblSalesOrderColors.TblSalesOrderSizeRatios").FirstOrDefault(x => x.SalesOrderCode == row.SalesOrderCode && x.SalesOrderType == 2);
                    temp.Status = 1;
                    foreach (var VARIABLE in temp.TblSalesOrderColors)
                    {
                        VARIABLE.ManualCalculationForProduction = true;
                        VARIABLE.TotalForProduction             = VARIABLE.Total;
                        var Min =
                            VARIABLE.TblSalesOrderSizeRatios.Where(x => x.ProductionPerSize > 0)
                            .OrderBy(x => x.ProductionPerSize)
                            .FirstOrDefault()
                            .ProductionPerSize;
                        foreach (var roww in VARIABLE.TblSalesOrderSizeRatios)
                        {
                            roww.ProductionPerSizeForProduction = roww.ProductionPerSize;

                            if (VARIABLE.Total > 0 && roww.ProductionPerSize > 0)
                            {
                                if (roww.ProductionPerSize == Min)
                                {
                                    roww.RatioForProduction = 1;
                                }
                                else
                                {
                                    roww.RatioForProduction = (double)roww.ProductionPerSize / Min;
                                }
                            }
                            else
                            {
                                roww.RatioForProduction = 0;
                            }
                        }
                    }

                    temp.IsPostedOnAxapta = true;
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                success = false;
                throw ex;
            }
            return(success);
        }