Esempio n. 1
0
        private void ClearAxTable(string tableName, Axapta axapta)
        {
            var axRecord = axapta.CreateAxaptaRecord(tableName);

            axRecord.Clear();
            axRecord.InitValue();

            using (axRecord = axapta.CreateAxaptaRecord(tableName))
            {
                // Execute a query to retrieve an editable record where the StatGroupName is “High Priority Customer”.

                string query = "select forupdate * from %1";
                //    " %1.WORKFLOWJOURID ==  " + iserial + "";
                axRecord.ExecuteStmt(query);
                // If the record is found then delete the record.
                if (axRecord.Found)
                {
                    // Start a transaction that can be committed.
                    axapta.TTSBegin();
                    axRecord.Delete();
                    // Commit the transaction.
                    axapta.TTSCommit();
                    axRecord.Next();
                }
            }
        }
        public JsonResult GetWorkTypes(string userName, string password, string domain, string companies, string utcTime, string signatureValue)
        {
            ValidateSignature.Check(userName, password, utcTime, signatureValue);

            using (Axapta ax = AxaptaInstanceContainer.GetInstance(userName, new SecurityHelper().Decrypt(password, true), domain, ""))
            {
                List <WorkType> list = new List <WorkType>();
                if (companies != null && companies.Length > 0)
                {
                    using (AxaptaRecord workflowWorkItemTableRecord = ax.CreateAxaptaRecord("WorkflowWorkItemTable"))
                    {
                        using (AxaptaRecord workflowTrackingStatusTableRecord = ax.CreateAxaptaRecord("WorkflowTrackingStatusTable"))
                        {
                            string query = "select RecId from %1 " +
                                           "where %1.UserId == curUserId() && %1.Status == WorkflowWorkItemStatus::Pending " +
                                           "join DocumentType, ContextTableId, count(RecId) from %2 group by DocumentType, ContextTableId " +
                                           "where %1.CorrelationId == %2.CorrelationId " +
                                           "&& %2.TrackingStatus == WorkflowTrackingStatus::Pending";

                            ax.ExecuteStmt(query, workflowWorkItemTableRecord, workflowTrackingStatusTableRecord);
                            string axRecCount = ax.ToString();
                            while (workflowWorkItemTableRecord.Found == true)
                            {
                                string empty = string.Empty;
                                if (workflowTrackingStatusTableRecord.Found == true)
                                {
                                    empty = workflowTrackingStatusTableRecord.get_Field("ContextTableId").ToString();
                                }
                                if (DataAreaIncluding.Check(empty, companies))
                                {
                                    object contextTableId = workflowTrackingStatusTableRecord.get_Field("ContextTableId");
                                    object documentType   = workflowTrackingStatusTableRecord.get_Field("DocumentType");
                                    object recId          = workflowTrackingStatusTableRecord.get_Field("RecId");
                                    object tblName        = ax.CallStaticClassMethod("Global", "tableId2Name", recId);

                                    list.Add(new WorkType()
                                    {
                                        WorkTypeName = documentType.ToString(), WorkTypeCount = Convert.ToInt32(recId)
                                    });
                                    workflowWorkItemTableRecord.Next();
                                }
                            }
                        }
                    }
                }
                return(Json(list, JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 3
0
        public void Insert()
        {
            Axapta       ax;
            AxaptaRecord axRecord;

            try
            {
                ax = new Axapta();
                ax.Logon(null, null, null, null);
                using (axRecord = ax.CreateAxaptaRecord(TABLE_NAME))
                {
                    ax.TTSBegin();

                    axRecord.Call("ESS_WriteValues",
                                  this.LeaveApplicationType,
                                  this.EmplId,
                                  this.RequestedBy,
                                  this.ScheduledLeaveDate,
                                  this.ScheduledReturnDate,
                                  this.ApprovalStatus,
                                  this.ExitVisaType,
                                  this.Comments,
                                  this.CommentsApproval);
                    axRecord.Insert();
                    ax.TTSCommit();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
        }
Esempio n. 4
0
        public void UpdateFabItem(tbl_FabricAttriputes objToPost, int userIserial)
        {
            var axapta = new Axapta();

            try
            {
                using (var context = new WorkFlowManagerDBEntities())
                {
                    var credential = new NetworkCredential("bcproxy", "around1");
                    var user       = context.TblAuthUsers.FirstOrDefault(x => x.Iserial == userIserial);

                    axapta.LogonAs(user.User_Win_Login, user.User_Domain, credential, "Ccm", null, null, null);

                    axapta.TTSBegin();
                    var itemId    = objToPost.FabricID;
                    var tableName = "InventTable";

                    var axaptaRecord = axapta.CreateAxaptaRecord(tableName);
                    axaptaRecord.Clear();
                    axaptaRecord.InitValue();
                    var header = axapta.CallStaticRecordMethod("InventTable", "find", itemId, true) as AxaptaRecord;
                    header.set_Field("ItemName", objToPost.FabricDescription);

                    context.SaveChanges();
                    axapta.TTSCommit();
                }
            }
            catch (Exception ex)
            {
                axapta.TTSAbort();
                throw ex;
            }
        }
Esempio n. 5
0
        public void Update()
        {
            Axapta       ax;
            AxaptaRecord axRecord;

            try
            {
                ax = new Axapta();
                ax.Logon(null, null, null, null);
                using (axRecord = ax.CreateAxaptaRecord(TABLE_NAME))
                {
                    string sql = string.Format("select forupdate * from %1 where %1.{0} == '{1}'", APPLICATION_ID, this.ApplicationId);
                    axRecord.ExecuteStmt(sql);
                    if (axRecord.Found)
                    {
                        ax.TTSBegin();
                        axRecord.set_Field(LEAVE_APP_TYPE, this.LeaveApplicationType);
                        axRecord.set_Field(SCH_LEAVE_DATE, this.ScheduledLeaveDate);
                        axRecord.set_Field(SCH_RETURN_DATE, this.ScheduledReturnDate);
                        axRecord.set_Field(APPROVAL_STATUS, this.ApprovalStatus);
                        axRecord.set_Field(EXIT_VISA_TYPE, this.ExitVisaType);
                        axRecord.set_Field(COMMENTS, this.Comments);
                        axRecord.set_Field(COMMENTS_APPROVAL, this.CommentsApproval);
                        axRecord.Update();
                        ax.TTSCommit();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
        }
Esempio n. 6
0
    static void Main(string[] args)
    {
        // Create the .NET Business Connector objects.
        Axapta ax;
        AxaptaRecord axRecord;
        string tableName = "LabX_ResultTable";

        // The Table field names for calls to
        // the AxRecord.get_field method.
        string strSampleField = "SampleID";
        string strDescriptionField = "Description";

        // The output variables for calls to the
        // AxRecord.get_Field method.
        object fieldSampleId, fieldDescription;

        try
        {
            // Login to Microsoft Dynamics AX.
            ax = new Axapta();
            ax.Logon(null, null, null, null);

            // Create a query using the AxaptaRecord class
            // for the StateAddress table.
            using (axRecord = ax.CreateAxaptaRecord(tableName))
            {

                // Execute the query on the table.
                axRecord.ExecuteStmt("select * from %1");
                // Create output with a title and column headings
                // for the returned records.
                Console.WriteLine("List of selected records from {0}",
                    tableName);
                Console.WriteLine("{0}\t{1}", strSampleField, strDescriptionField);

                // Loop through the set of retrieved records.
                while (axRecord.Found)
                {
                    // Retrieve the record data for the specified fields.
                    fieldSampleId = axRecord.get_Field(strSampleField);
                    fieldDescription = axRecord.get_Field(strDescriptionField);

                    // Display the retrieved data.
                    Console.WriteLine(fieldSampleId + "\t" + fieldDescription);

                    // Advance to the next row.
                    axRecord.Next();
                }
            }
        }

        catch (Exception e)
        {
            Console.WriteLine("Error encountered: {0}", e.Message);
            // Take other error action as needed.
        }

        Console.Read();
    }
Esempio n. 7
0
    static void Main(string[] args)
    {
        // Create the .NET Business Connector objects.
        Axapta       ax;
        AxaptaRecord axRecord;
        string       tableName = "LabX_ResultTable";

        // The Table field names for calls to
        // the AxRecord.get_field method.
        string strSampleField      = "SampleID";
        string strDescriptionField = "Description";

        // The output variables for calls to the
        // AxRecord.get_Field method.
        object fieldSampleId, fieldDescription;

        try
        {
            // Login to Microsoft Dynamics AX.
            ax = new Axapta();
            ax.Logon(null, null, null, null);

            // Create a query using the AxaptaRecord class
            // for the StateAddress table.
            using (axRecord = ax.CreateAxaptaRecord(tableName))
            {
                // Execute the query on the table.
                axRecord.ExecuteStmt("select * from %1");
                // Create output with a title and column headings
                // for the returned records.
                Console.WriteLine("List of selected records from {0}",
                                  tableName);
                Console.WriteLine("{0}\t{1}", strSampleField, strDescriptionField);

                // Loop through the set of retrieved records.
                while (axRecord.Found)
                {
                    // Retrieve the record data for the specified fields.
                    fieldSampleId    = axRecord.get_Field(strSampleField);
                    fieldDescription = axRecord.get_Field(strDescriptionField);

                    // Display the retrieved data.
                    Console.WriteLine(fieldSampleId + "\t" + fieldDescription);

                    // Advance to the next row.
                    axRecord.Next();
                }
            }
        }

        catch (Exception e)
        {
            Console.WriteLine("Error encountered: {0}", e.Message);
            // Take other error action as needed.
        }

        Console.Read();
    }
Esempio n. 8
0
        public void PostIssueHeader(int iserial, int userIserial)
        {
            using (var entities = new WorkFlowManagerDBEntities())
            {
                var axapta     = new Axapta();
                var credential = new NetworkCredential("bcproxy", "around1");

                TblAuthUser userToLogin;
                using (var model = new WorkFlowManagerDBEntities())
                {
                    userToLogin = model.TblAuthUsers.FirstOrDefault(x => x.Iserial == userIserial);
                }
                var header = entities.TblIssueJournalHeaders.Include("TblIssueJournalDetails").FirstOrDefault(x => x.Iserial == iserial);

                var vendorWmsLocation = entities.GetWmsLocations.FirstOrDefault(x => x.VENDID == header.Vendor);
                var vendorLoc         = entities.GetLocations.FirstOrDefault(x => x.INVENTLOCATIONID == vendorWmsLocation.INVENTLOCATIONID);
                axapta.LogonAs(userToLogin.User_Win_Login, userToLogin.User_Domain, credential, "Ccm", null, null, null);
                const string tableName       = "PRODCONNECTION";
                var          transactionGuid = Guid.NewGuid().ToString();

                if (header != null)
                {
                    foreach (var item in header.TblIssueJournalDetails)
                    {
                        var locationLoc = entities.GetLocations.FirstOrDefault(x => x.INVENTLOCATIONID == item.Location);

                        AxaptaRecord axaptaRecord = axapta.CreateAxaptaRecord(tableName);
                        axaptaRecord.Clear();
                        axaptaRecord.InitValue();
                        //Transfer To Vendor's Location

                        var itemcode = GetItemCode(item.ItemCode, item.ItemType);
                        axaptaRecord.set_Field("DYEDITEM", itemcode.Code);
                        axaptaRecord.set_Field("TRANSID", item.TblIssueJournalHeader);
                        axaptaRecord.set_Field("RAWID", itemcode.Code);
                        axaptaRecord.set_Field("RAWQTY", item.Qty);
                        axaptaRecord.set_Field("DYEDQTY", item.Qty);
                        axaptaRecord.set_Field("UNITID", itemcode.Unit);
                        axaptaRecord.set_Field("FROMSITE", locationLoc.INVENTSITEID);
                        axaptaRecord.set_Field("FROMLOCATION", item.Location);
                        axaptaRecord.set_Field("FROMWAREHOUSE", item.Location);
                        axaptaRecord.set_Field("FROMBATCH", item.BatchNo);
                        axaptaRecord.set_Field("FROMCONFIG", item.TblColor1.Code);
                        axaptaRecord.set_Field("TOSITE", vendorLoc.INVENTSITEID);
                        axaptaRecord.set_Field("TOLOCATION", vendorWmsLocation.WMSLOCATIONID);
                        axaptaRecord.set_Field("TOWAREHOUSE", vendorWmsLocation.INVENTLOCATIONID);
                        axaptaRecord.set_Field("TOBATCH", item.BatchNo);
                        axaptaRecord.set_Field("TOCONFIG", item.TblColor1.Code);
                        axaptaRecord.set_Field("TRANSTYPE", Convert.ToInt64(0));
                        axaptaRecord.set_Field("JOURNALLINKID", item.TblIssueJournalHeader);
                        axaptaRecord.set_Field("TransactionGuid", transactionGuid);
                        axaptaRecord.Insert();
                    }
                }
            }
        }
Esempio n. 9
0
        private void ReceivepackingSlip(int Iserial, int userIserial)
        {
            var axapta          = new Axapta();
            var transactionGuid = Guid.NewGuid().ToString();
            var credential      = new NetworkCredential("bcproxy", "around1");
            var header          = new TblPurchaseReceiveHeader();

            using (var model = new WorkFlowManagerDBEntities())
            {
                header =
                    model.TblPurchaseReceiveHeaders.Include("TblPurchaseOrderHeaderRequest1")
                    .Include("TblPurchaseReceiveDetails.TblPurchaseOrderDetailRequest1")
                    .FirstOrDefault(w => w.Iserial == Iserial);

                TblAuthUser userToLogin = model.TblAuthUsers.SingleOrDefault(x => x.Iserial == userIserial);

                var warehouse = model.TblWarehouses.FirstOrDefault(w => w.Iserial == header.TblWarehouse);
                if (userToLogin != null)
                {
                    axapta.LogonAs(userToLogin.User_Win_Login, userToLogin.User_Domain, credential, "Ccm", null, null, null);
                }
                const string tableName    = "AutoPICKING";
                var          axaptaRecord = axapta.CreateAxaptaRecord(tableName);
                foreach (var variable in header.TblPurchaseReceiveDetails)
                {
                    var color = model.TblColors.FirstOrDefault(e => e.Iserial == variable.TblPurchaseOrderDetailRequest1.FabricColor).Code;

                    var purchdim = model.PurchlineInventDimWithoutRecs.Where(w => w.ITEMID == variable.TblPurchaseOrderDetailRequest1.ItemId &&
                                                                             w.CONFIGID == color && w.PURCHID == header.TblPurchaseOrderHeaderRequest1.AxPurchase);

                    if (variable.TblPurchaseOrderDetailRequest1.BatchNo != null)
                    {
                        purchdim = purchdim.Where(x => x.INVENTBATCHID == variable.TblPurchaseOrderDetailRequest1.BatchNo);
                    }
                    if (variable.TblPurchaseOrderDetailRequest1.Size != null)
                    {
                        purchdim = purchdim.Where(x => x.INVENTSIZEID == variable.TblPurchaseOrderDetailRequest1.Size);
                    }
                    axaptaRecord.Clear();
                    axaptaRecord.InitValue();
                    axaptaRecord.set_Field("DATAAREAID", "Ccm");
                    axaptaRecord.set_Field("TransactionGuid", transactionGuid);
                    axaptaRecord.set_Field("FABRICLOCATION", warehouse.Code);
                    axaptaRecord.set_Field("QTY", Convert.ToDecimal(variable.Qty));
                    axaptaRecord.set_Field("WORKFLOWJOURID", header.Iserial);
                    axaptaRecord.set_Field("LineNum", purchdim.OrderByDescending(w => w.LINENUM).FirstOrDefault().LINENUM);
                    axaptaRecord.Insert();
                }
            }
            CreatePackingSlip(header.DocCode + "_" + header.RefNo, header.TblPurchaseOrderHeaderRequest1.AxPurchase, transactionGuid, userIserial);
        }
Esempio n. 10
0
        public static List <LeaveApp> GetLeaveApps()
        {
            var          leaveApps = new List <LeaveApp>();
            Axapta       ax;
            AxaptaRecord axRecord;

            try
            {
                // Login to Microsoft Dynamics AX.
                ax = new Axapta();
                ax.Logon(null, null, null, null);

                // Create a query using the AxaptaRecord class
                using (axRecord = ax.CreateAxaptaRecord(TABLE_NAME))
                {
                    // Execute the query on the table.
                    axRecord.ExecuteStmt("select * from %1 ");

                    while (axRecord.Found)
                    {
                        var leaveApp = new LeaveApp()
                        {
                            ApplicationId        = axRecord.get_Field(APPLICATION_ID).ToString(),
                            CreatedDateTime      = (DateTime)axRecord.get_Field(CREATE_DATETIME),
                            LeaveApplicationType = axRecord.get_Field(LEAVE_APP_TYPE).ToString(),
                            DefaultLeaveCode     = axRecord.get_Field(LEAVE_CODE).ToString(),
                            EmplId              = axRecord.get_Field(EMPLOYEE_ID).ToString(),
                            RequestedBy         = (long)axRecord.get_Field(REQUESTED_BY),
                            ScheduledLeaveDate  = (DateTime)axRecord.get_Field(SCH_LEAVE_DATE),
                            ScheduledReturnDate = (DateTime)axRecord.get_Field(SCH_RETURN_DATE),
                            Days             = (int)axRecord.get_Field(DAYS),
                            ApprovalStatus   = axRecord.get_Field(APPROVAL_STATUS).ToString(),
                            ExitVisaType     = axRecord.get_Field(EXIT_VISA_TYPE).ToString(),
                            Comments         = axRecord.get_Field(COMMENTS).ToString(),
                            CommentsApproval = axRecord.get_Field(COMMENTS_APPROVAL).ToString()
                        };
                        leaveApps.Add(leaveApp);
                        axRecord.Next();
                    }
                    return(leaveApps);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error encountered: {0}", ex.Message);
                throw;
            }
        }
Esempio n. 11
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();
                }
            }
        }
Esempio n. 12
0
        public static Employee GetEmployee(string personnelNumber)
        {
            Axapta       ax;
            AxaptaRecord axRecord;

            try
            {
                // Login to Microsoft Dynamics AX.
                ax = new Axapta();
                ax.Logon(null, null, null, null);

                // Create a query using the AxaptaRecord class
                // for the StateAddress table.
                using (axRecord = ax.CreateAxaptaRecord(TABLE_NAME))
                {
                    // Execute the query on the table.
                    axRecord.ExecuteStmt(string.Format("select * from %1 where %1.PersonnelNumber == '{0}'", personnelNumber));

                    if (axRecord.Found)
                    {
                        var emp = new Employee()
                        {
                            PersonnelNumber = axRecord.get_Field(PERSONNEL_NUMBER).ToString(),
                            Worker          = (long)axRecord.get_Field(WORKER),
                            EmplCompany     = axRecord.Company,
                            Name            = axRecord.Call("name").ToString()
                        };
                        return(emp);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error encountered: {0}", ex.Message);
                return(null);
            }
        }
Esempio n. 13
0
        }                                       // AX Company for create Employee Leaves
        #endregion

        #region Methods
        public static List <Employee> GetEmployees(string _supervisor = "")
        {
            var          employees = new List <Employee>();
            Axapta       ax;
            AxaptaRecord axRecord;

            try
            {
                // Login to Microsoft Dynamics AX.
                ax = new Axapta();
                ax.Logon(null, null, null, null);

                // Create a query using the AxaptaRecord class
                // for the StateAddress table.
                using (axRecord = ax.CreateAxaptaRecord(TABLE_NAME))
                {
                    // Execute the query on the table.
                    axRecord.ExecuteStmt("select * from %1 ");

                    while (axRecord.Found)
                    {
                        var emp = new Employee()
                        {
                            PersonnelNumber = axRecord.get_Field(PERSONNEL_NUMBER).ToString(),
                            Worker          = (long)axRecord.get_Field(WORKER),
                            EmplCompany     = axRecord.Company,
                            Name            = axRecord.Call("name").ToString()
                        };
                        employees.Add(emp);
                        axRecord.Next();
                    }
                    return(employees);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error encountered: {0}", ex.Message);
                throw;
            }
        }
Esempio n. 14
0
        public ActionResult CreateTransfer(Transfer transfer)
        {
            try
            {
                Axapta axDB1 = new Axapta();
                System.Net.NetworkCredential ncDB1 = new System.Net.NetworkCredential("EP_AX2012", "VendTable1", "RIWAL01");
                axDB1.LogonAs(ConfigurationManager.AppSettings["User"], ConfigurationManager.AppSettings["Domain"], ncDB1, transfer.DataAreaId, ConfigurationManager.AppSettings["Language"], ConfigurationManager.AppSettings["AOS"], "");

                axDB1.TTSBegin();
                AxaptaRecord transferRequest = axDB1.CreateAxaptaRecord("A4URequests");
                transferRequest.Call("InitValue");
                if (!string.IsNullOrWhiteSpace(transfer.ContactPersonId))
                {
                    transferRequest.set_Field("ContactPersonId", transfer.ContactPersonId);
                }
                transferRequest.set_Field("CustAccount", transfer.CustAccount);
                if (!string.IsNullOrWhiteSpace(transfer.TransferFromContactPersonid))
                {
                    transferRequest.set_Field("TransferFromContactPersonId", transfer.TransferFromContactPersonid);
                }
                transferRequest.set_Field("TransferFromCustAccount", transfer.TransferFromCustAccount);
                transferRequest.set_Field("Type", (Int32)RequestTypes.Transfer);
                transferRequest.set_Field("Status", (Int32)TransferStates.Requested);
                transferRequest.set_Field("TransferfromInventTransId", transfer.TransferfromInventTransId);
                transferRequest.set_Field("DateOnHire", transfer.DateOnHire);
                transferRequest.set_Field("UserId", transfer.UserId);
                transferRequest.set_Field("TransferFromUserId", transfer.TransferFromUserId);
                transferRequest.set_Field("TransferFromSalesName", transfer.TransferFromSalesName);
                transferRequest.set_Field("SalesName", transfer.SalesName);
                transferRequest.Insert();
                axDB1.TTSCommit();
                axDB1.Logoff();
                axDB1.Dispose();
                return(Content("true"));
            }
            catch
            {
                return(Content("false"));
            }
        }
        public List <IntershopWebService.SizeStock> getItemDims(string itemId, string company)
        {
            List <IntershopWebService.SizeStock> sizeStockList = new List <IntershopWebService.SizeStock>();
            Axapta axapta = (Axapta)null;

            try
            {
                axapta = this.axLogon(company);
                string       str          = "select * from %1 where %1.ItemId == '" + itemId + "'";
                AxaptaRecord axaptaRecord = axapta.CreateAxaptaRecord("InventSize");
                axaptaRecord.ExecuteStmt(str);
                while (axaptaRecord.Found)
                {
                    IntershopWebService.SizeStock sizeStock = new IntershopWebService.SizeStock();
                    if (Convert.ToBoolean(axaptaRecord.get_Field("Color")))
                    {
                        sizeStock.color = Convert.ToString(axaptaRecord.get_Field("InventSizeId"));
                    }
                    else
                    {
                        sizeStock.size = Convert.ToString(axaptaRecord.get_Field("InventSizeId"));
                    }
                    sizeStockList.Add(sizeStock);
                    axaptaRecord.Next();
                }
                return(sizeStockList);
            }
            catch (Exception ex)
            {
                MessageLogger.info(string.Format("getItemDims(itemId={0}, company={1} -> error: {2})", itemId, company, ex.Message));
                return((List <IntershopWebService.SizeStock>)null);
            }
            finally
            {
                axapta.Logoff();
            }
        }
Esempio n. 16
0
        private void UpdateAccDetailsInAX(List <tbl_AccessoryAttributesDetails> detailsToUpdate, int userIserial)
        {
            var axapta = new Axapta();//Ready To be Dependent from Ax

            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);

            foreach (var item in detailsToUpdate.Select(x => x.Configuration).Distinct())
            {
                try
                {
                    var importNew = axapta.CreateAxaptaObject("CreateProductionJournals");
                    importNew.Call("CreateConfig", detailsToUpdate.Select(x => x.Code).FirstOrDefault(), item);
                }
                catch (Exception)
                {
                }
            }

            foreach (var item in detailsToUpdate.Select(x => x.Size).Distinct())
            {
                try
                {
                    var importNew = axapta.CreateAxaptaObject("CreateProductionJournals");
                    importNew.Call("CreateSize", detailsToUpdate.Select(x => x.Code).FirstOrDefault(), item);
                }
                catch (Exception)
                {
                }
                //--------------------------------------------//
                //--------------------------------------------//
                //--------------------------------------------//C:\Users\GDE\Desktop\CCWFM\CCWFM.Web\Service\Operations\AccessoriesOperations.cs
            }

            foreach (var item in detailsToUpdate)
            {
                try
                {
                    const string tableName    = "InventDimCombination";
                    var          axaptaRecord = axapta.CreateAxaptaRecord(tableName);
                    axaptaRecord.Clear();
                    axaptaRecord.InitValue();

                    axaptaRecord.set_Field("ItemId", item.Code);
                    axaptaRecord.set_Field("InventSizeID", item.Size);
                    axaptaRecord.set_Field("ConfigId", item.Configuration);
                    //Commit the record to the database.
                    axaptaRecord.Insert();
                }
                catch (Exception)
                {
                }
            }

            axapta.Logoff();
        }
Esempio n. 17
0
        private void InsertAllNewAccessoryToAx(IEnumerable <tbl_AccessoryAttributesDetails> listObjToPost
                                               , tbl_AccessoryAttributesHeader objToPost, bool isSizeInCode, int userIserial)
        {
            try
            {
                using (var context = new WorkFlowManagerDBEntities())
                {
                    var axapta = new Axapta();//Ready To be Dependent from Ax;

                    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);
                    var itemId    = objToPost.Code.Trim();
                    var tableName = "InventTable";

                    var axaptaRecord = axapta.CreateAxaptaRecord(tableName);
                    axaptaRecord.Clear();
                    axaptaRecord.InitValue();
                    var tblLkpItemGroupType = context.tbl_lkp_ItemGroupType.FirstOrDefault(x => x.Iserial ==
                                                                                           context.tbl_lkp_AccessoryGroup
                                                                                           .FirstOrDefault(
                                                                                               g =>
                                                                                               g.Iserial ==
                                                                                               objToPost.AccGroup)
                                                                                           .tbl_lkp_ItemGroupType);
                    if (tblLkpItemGroupType != null)
                    {
                        var itmGroup = tblLkpItemGroupType.Code;
                        axaptaRecord.set_Field("ItemGroupId", itmGroup);
                    }
                    else
                    {
                        axaptaRecord.set_Field("ItemGroupId", "ACCESSORIES");
                    }
                    axaptaRecord.set_Field("ItemId", itemId);
                    axaptaRecord.set_Field("ItemName", objToPost.Descreption ?? itemId);
                    axaptaRecord.set_Field("ModelGroupID", "STD");
                    axaptaRecord.set_Field("ItemType", 0);
                    axaptaRecord.set_Field("DimGroupId", "ACC");
                    //Commit the record to the database.
                    axaptaRecord.Insert();
                    tableName    = "InventTableModule";
                    axaptaRecord = axapta.CreateAxaptaRecord(tableName);
                    axaptaRecord.Clear();
                    axaptaRecord.InitValue();

                    axaptaRecord.set_Field("ItemId", itemId);
                    axaptaRecord.set_Field("ModuleType", 0);
                    if (objToPost.UoMID != null)
                    {
                        axaptaRecord.set_Field
                            ("UnitId",
                            context.tbl_lkp_UoM
                            .Where(x => x.Iserial == objToPost.UoMID)
                            .Select(x => x.Ename)
                            .SingleOrDefault()
                            );
                    }
                    //
                    axaptaRecord.Insert();

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

                    axaptaRecord.set_Field("ItemId", itemId);
                    axaptaRecord.set_Field("ModuleType", 1);

                    //
                    axaptaRecord.Insert();

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

                    axaptaRecord.set_Field("ItemId", itemId);
                    axaptaRecord.set_Field("ModuleType", 2);

                    //
                    axaptaRecord.Insert();

                    tableName = "InventItemLocation";

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

                    axaptaRecord.set_Field("ItemId", itemId);
                    axaptaRecord.set_Field("InventDIMID", "AllBlank");

                    // Commit the record to the database.
                    axaptaRecord.Insert();
                    foreach (var item in listObjToPost)
                    {
                        try
                        {
                            var importNew = axapta.CreateAxaptaObject("CreateProductionJournals");
                            importNew.Call("CreateConfig", listObjToPost.Select(x => x.Code).FirstOrDefault(), item);
                        }
                        catch (Exception)
                        {
                        }
                        //    if (!isSizeInCode)
                        //      {
                        try
                        {
                            var importNew = axapta.CreateAxaptaObject("CreateProductionJournals");
                            importNew.Call("CreateSize", listObjToPost.Select(x => x.Code).FirstOrDefault(), item);
                        }
                        catch (Exception)
                        {
                        }

                        //--------------------------------------------//
                        //--------------------------------------------//
                        //--------------------------------------------//
                        try
                        {
                            tableName    = "InventDimCombination";
                            axaptaRecord = axapta.CreateAxaptaRecord(tableName);
                            axaptaRecord.Clear();
                            axaptaRecord.InitValue();

                            axaptaRecord.set_Field("ItemId", itemId);
                            axaptaRecord.set_Field("InventSizeID", item.Size);
                            axaptaRecord.set_Field("ConfigId", item.Configuration);
                            //Commit the record to the database.
                            axaptaRecord.Insert();
                        }
                        catch (Exception)
                        {
                        }

                        //--------------------------------------------//
                        //--------------------------------------------//
                        //--------------------------------------------//
                        //      }
                    }
                    axapta.Logoff();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 18
0
        public void PostPOWithPurchIDToAx(TblSalesOrder po, int userIserial)
        {
            using (var context = new WorkFlowManagerDBEntities())
            {
                var headerObjToPost  = context.TblSalesOrders.Include("TblStyle1").SingleOrDefault(x => x.Iserial == po.Iserial);
                var detailsObjToPost = context.TblSalesOrderColors.Include("TblSalesOrderSizeRatios").Include("TblSalesOrderSizeRatios").Where(x => x.TblSalesOrder == po.Iserial).ToList();
                var axapta           = new Axapta();

                var credential = new NetworkCredential("bcproxy", "around1");

                TblAuthUser userToLogin;
                using (var model = new WorkFlowManagerDBEntities())
                {
                    userToLogin = model.TblAuthUsers.SingleOrDefault(x => x.Iserial == userIserial);
                }
                string dataarea = "CCM";
                if (headerObjToPost.SalesOrderType == (int)Enums.SalesOrderType.RetailPo)
                {
                    dataarea = "CCR";
                }
                axapta.LogonAs(userToLogin.User_Win_Login, userToLogin.User_Domain, credential, dataarea, null, null, null);

                var inventDim = axapta.CreateAxaptaRecord("InventDim");

                try
                {
                    //Start Transaction
                    axapta.TTSBegin();

                    var tableName    = "PurchTable";
                    var _PurchID     = headerObjToPost.SalesOrderCode;
                    var axaptaRecord = axapta.CreateAxaptaRecord(tableName);
                    axaptaRecord.Clear();
                    axaptaRecord.InitValue();

                    axaptaRecord.set_Field("PurchId", _PurchID);
                    axaptaRecord.set_Field("DeliveryDate", headerObjToPost.DeliveryDate);

                    var header = axapta.CallStaticRecordMethod("VendTable", "find", headerObjToPost.TblSupplier) as AxaptaRecord;
                    axaptaRecord.Call("initFromVendTable", header);

                    axaptaRecord.Insert();

                    tableName = "PurchLine";
                    foreach (var item in detailsObjToPost)
                    {
                        foreach (var sizeRow in item.TblSalesOrderSizeRatios)
                        {
                            var styleId = headerObjToPost.TblStyle1.StyleCode;

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

                            inventDim.Clear();
                            //  InventDim.set_Field("InventLocationId", headerObjToPost.WareHouseID);
                            inventDim.set_Field("InventColorId", item.TblColor1.Code);
                            inventDim.set_Field("InventSizeId", sizeRow.Size);
                            inventDim = axapta.CallStaticRecordMethod("InventDim", "findOrCreate", inventDim) as AxaptaRecord;

                            var tempx = inventDim.get_Field("inventDimId").ToString();
                            axaptaRecord.set_Field("InventDimId", tempx);

                            axaptaRecord.set_Field("ItemId", styleId);
                            axaptaRecord.set_Field("purchId", _PurchID);

                            axaptaRecord.set_Field("QtyOrdered", Convert.ToDecimal(sizeRow.ProductionPerSize.ToString()));
                            axaptaRecord.set_Field("PurchPrice", item.LocalCost + item.AdditionalCost);
                            axaptaRecord.set_Field("PurchQty", Convert.ToDecimal(sizeRow.ProductionPerSize.ToString()));
                            axaptaRecord.set_Field("LineAmount", Convert.ToDecimal(sizeRow.ProductionPerSize.ToString()));
                            axaptaRecord.Call("createLine", true, true, false, true, true, false);
                        }
                    }

                    //No errors occured, Commit!
                    //Axapta.TTSCommit();
                }
                catch (Exception ex)
                {
                    //There was some errors, Abort transaction and Raise error!
                    //Axapta.TTSAbort();
                    throw new Exception(ex.Message);
                }
                finally
                {
                    //Finally logoff the Axapta Session
                    axapta.Logoff();
                }
            }
        }
Esempio n. 19
0
        private void PostNewPoToAx(tblNewRFQPurchaseOrderHeader paramHeaderObjToPost)
        {
            var context         = new WorkFlowManagerDBEntities();
            var headerObjToPost =
                context.tblNewRFQPurchaseOrderHeaders.Include("tblNewRFQPurchLines.tbl_PurchaseOrderSizeDetails")
                .FirstOrDefault(x => x.TransID == paramHeaderObjToPost.TransID);

            var axapta = new Axapta();

            var credential = new NetworkCredential("bcproxy", "around1");

            try
            {
                axapta.LogonAs("ahmed.gamal", "ccasual.loc", credential, "ccr", null, null, null);
            }
            catch (Exception)
            {
                throw new Exception("There was a problem logging to ax");
            }
            try
            {
                axapta.TTSBegin();
                var inventDimTable       = axapta.CreateAxaptaRecord("InventDim");
                var inventColorTable     = axapta.CreateAxaptaRecord("InventColor");
                var inventDimCombination = axapta.CreateAxaptaRecord("InventDimCombination");

                var axaptaRecord = axapta.CreateAxaptaRecord("PurchTable");
                axaptaRecord.Clear();
                axaptaRecord.InitValue();
                var purchId = headerObjToPost.PurchaseID;
                axaptaRecord.set_Field("PurchId", purchId);

                var header =
                    axapta.CallStaticRecordMethod("VendTable", "find", headerObjToPost.Vendor) as AxaptaRecord;
                axaptaRecord.Call("initFromVendTable", header);

                axaptaRecord.Insert();
                context.tbl_PurchaseOrderDetails.MergeOption = MergeOption.NoTracking;
                context.V_Warehouse.MergeOption = MergeOption.NoTracking;
                var detailHeadersFull = headerObjToPost.tblNewRFQPurchLines;

                foreach (var ditem in detailHeadersFull)
                {
                    foreach (var sdItem in ditem.tblNewRFQPurchLineSizes)
                    {
                        var itemId = ditem.StyleCode;

                        axaptaRecord = axapta.CreateAxaptaRecord("PurchLine");
                        axaptaRecord.Clear();
                        axaptaRecord.InitValue();

                        inventDimTable.Clear();
                        inventDimTable.set_Field("InventLocationId", headerObjToPost.WareHouseID);

                        var warehouse =
                            context.V_Warehouse.SingleOrDefault(
                                x => x.DataAreaID == "ccr" && x.WarehouseID == headerObjToPost.WareHouseID);
                        if (warehouse !=
                            null)
                        {
                            inventDimTable.set_Field("InventSiteId", warehouse.SiteId);
                        }

                        inventColorTable.set_Field("ItemID", ditem.StyleCode);
                        inventColorTable.set_Field("InventColorId", ditem.ColorCode);
                        var clr =
                            (bool)
                            axapta.CallStaticRecordMethod("InventColor", "checkExist", ditem.StyleCode, ditem.ColorCode);
                        if (!clr)
                        {
                            inventColorTable.Insert();
                        }
                        else
                        {
                            inventColorTable.Clear();
                        }

                        try
                        {
                            inventDimCombination.set_Field("ItemID", ditem.StyleCode);
                            inventDimCombination.set_Field("InventSizeId", sdItem.Size);
                            inventDimCombination.set_Field("InventColorId", ditem.ColorCode);
                            inventDimCombination.Insert();
                        }
                        catch
                        {
                        }

                        inventDimTable.set_Field("InventColorId", ditem.ColorCode);
                        inventDimTable.set_Field("InventSizeId", sdItem.Size);

                        inventDimTable =
                            axapta.CallStaticRecordMethod("InventDim", "findOrCreate", inventDimTable) as
                            AxaptaRecord;

                        var tempx = inventDimTable.get_Field("inventDimId").ToString();
                        axaptaRecord.set_Field("InventDimId", tempx);

                        if (ditem.DeliveryDate != null)
                        {
                            axaptaRecord.set_Field("DeliveryDate", ditem.DeliveryDate);
                        }

                        axaptaRecord.set_Field("ItemId", itemId);
                        axaptaRecord.set_Field("purchId", purchId);
                        axaptaRecord.set_Field("PurchUnit", "Pcs");
                        axaptaRecord.set_Field("QtyOrdered", Convert.ToDecimal(sdItem.Qty.ToString()));
                        axaptaRecord.set_Field("PurchPrice", Convert.ToDecimal(ditem.PurchasePrice));
                        axaptaRecord.set_Field("PurchQty", Convert.ToDecimal(sdItem.Qty.ToString()));
                        axaptaRecord.set_Field("LineAmount",
                                               Convert.ToDecimal((sdItem.Qty * ditem.PurchasePrice).ToString()));

                        axaptaRecord.Call("createLine", true, true, false, true, true, false);
                    }

                    //TO DO: Add Posting TO Retail Plus Logic Here!

                    //-////////////////////////////////////////////
                    var retailContext = new ccnewEntities();
                    //var retailPoHeader = new TblPOHeader
                    //{
                    //    Code = headerObjToPost.PurchaseID,
                    //    tblstore = headerObjToPost.WareHouseID,
                    //     tblseason = headerObjToPost.tbl_RFQHeader.SeasonCode,

                    //};
                    var retailPoMainDetail = new TblPOMainDetail();
                    var retailPoDetail     = new TblPODetail();

                    axapta.TTSCommit();
                    headerObjToPost.IsPosted = true;
                    context.SaveChanges();
                }
            }
            catch (Exception)
            {
                axapta.TTSAbort();
                throw;
            }
            finally
            {
                axapta.Logoff();
                axapta.Dispose();
            }
        }
Esempio n. 20
0
        public DataTable GetRespairStageList(string userName)
        {
            DataTable resultTable = new DataTable();
            Axapta ax = null;
            AxaptaRecord axRecord;
            try
            {
                // Login to Microsoft Dynamics AX.
                ax = new Axapta();
                ax.LogonAs(userName.Trim(), "", networkCredentials, axCompany, "", "", "");
                resultTable.Columns.Add("Name", typeof(String));
                resultTable.Columns.Add("RepairStageId", typeof(String));

                using (axRecord = ax.CreateAxaptaRecord("SMARepairStage"))
                {
                    // Execute the query on the table.
                    axRecord.ExecuteStmt("select RepairStageId, Name from %1 where %1.DataAreaID=='" + axCompany + "'");
                    // Loop through the set of retrieved records.
                    while (axRecord.Found)
                    {

                        DataRow row = resultTable.NewRow();
                        row["Name"] = axRecord.get_Field("Name");
                        row["RepairStageId"] = axRecord.get_Field("RepairStageId");

                        resultTable.Rows.Add(row);
                        axRecord.Next();

                    }

                }
            }
            catch (Exception e)
            {
                throw e;
                // Take other error action as needed.
            }
            finally
            {
                if (ax != null) ax.Logoff();
            }
            return resultTable;
        }
Esempio n. 21
0
        public DataTable GetSpecialityCodeList(string userName, string transactionId)
        {
            DataTable resultTable = new DataTable();
            Axapta ax = null;
            AxaptaRecord axRecord;
            try
            {
                // Login to Microsoft Dynamics AX.
                ax = new Axapta();
                ax.LogonAs(userName.Trim(), "", networkCredentials, axCompany, "", "", "");
                resultTable.Columns.Add("SpecialityCode", typeof(String));
                resultTable.Columns.Add("SpecialityDescription", typeof(String));
                using (axRecord = ax.CreateAxaptaRecord("CategoryTable"))
                {
                    // Execute the query on the table.e
                    //axRecord.ExecuteStmt("select CategoryID, CategoryName from %1 where %1.DataAreaID=='" + axCompany + "'");
                    axRecord = (AxaptaRecord)ax.CallStaticClassMethod("ServiceOrderManagement", "getSMACategoryTable", transactionId);
                    axRecord.ExecuteStmt("select * from %1");

                    // Loop through the set of retrieved records.
                    while (axRecord.Found)
                    {

                        DataRow row = resultTable.NewRow();
                        row["SpecialityCode"] = axRecord.get_Field("CategoryId");
                        row["SpecialityDescription"] = axRecord.get_Field("CategoryName");
                        resultTable.Rows.Add(row);
                        axRecord.Next();

                    }

                }
            }
            catch (Exception e)
            {
                throw e;
                // Take other error action as needed.
            }
            finally
            {
                if (ax != null) ax.Logoff();
            }
            return resultTable;
        }
Esempio n. 22
0
        public void PostPOWithPurchIDToAx(int purchID)
        {
            using (var context = new WorkFlowManagerDBEntities())
            {
                var headerObjToPost  = context.tbl_PurchaseOrderHeader.SingleOrDefault(x => x.TransID == purchID);
                var detailsObjToPost = context.v_PurchaseOrderDetailsWithSizes.Where(x => x.Trans_TransactionHeader == purchID).ToList();
                var axapta           = new Axapta();

                var credential = new NetworkCredential("bcproxy", "around1");

                axapta.LogonAs("osama.gamal", "ccasual.loc", credential, "ccr", null, null, null);

                var inventTable = axapta.CreateAxaptaRecord("InventDim");
                //var inventColorTable = axapta.CreateAxaptaRecord("InventColor");
                //var inventSizeTable = axapta.CreateAxaptaRecord("InventSize");

                try
                {
                    //Start Transaction
                    //Axapta.TTSBegin();

                    //string _journalid = "143887_109";
                    var tableName    = "PurchTable";
                    var _PurchID     = "143887_109";
                    var axaptaRecord = axapta.CreateAxaptaRecord(tableName);
                    axaptaRecord.Clear();
                    axaptaRecord.InitValue();

                    axaptaRecord.set_Field("PurchId", _PurchID);
                    axaptaRecord.set_Field("DeliveryDate", headerObjToPost.DelivaryDate);
                    axaptaRecord.set_Field("PurchId", _PurchID);

                    var header = axapta.CallStaticRecordMethod("VendTable", "find", headerObjToPost.Vendor) as AxaptaRecord;
                    axaptaRecord.Call("initFromVendTable", header);

                    axaptaRecord.Insert();

                    tableName = "PurchLine";
                    foreach (var item in detailsObjToPost)
                    {
                        var styleID = context.StyleHeader_SalesOrder
                                      .Where(x => x.SalesOrderID == item.SalesOrder)
                                      .Select(x => x.StyleHeader).FirstOrDefault().ToString();

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

                        inventTable.Clear();
                        inventTable.set_Field("InventLocationId", headerObjToPost.WareHouseID);
                        inventTable.set_Field("InventColorId", item.Color);
                        inventTable.set_Field("InventSizeId", item.Size);
                        inventTable = axapta.CallStaticRecordMethod("InventDim", "findOrCreate", inventTable) as AxaptaRecord;

                        var tempx = inventTable.get_Field("inventDimId").ToString();
                        axaptaRecord.set_Field("InventDimId", tempx);

                        axaptaRecord.set_Field("ItemId", styleID);
                        axaptaRecord.set_Field("purchId", _PurchID);
                        axaptaRecord.set_Field("QtyOrdered", Convert.ToDecimal(item.TotalQty.ToString()));
                        axaptaRecord.set_Field("PurchPrice", item.PurchasePrice);
                        axaptaRecord.set_Field("PurchQty", Convert.ToDecimal(item.TotalQty.ToString()));
                        axaptaRecord.set_Field("LineAmount", Convert.ToDecimal(item.TotalQty.ToString()));
                        axaptaRecord.Call("createLine", true, true, true, true, true, true);
                    }
                    //No errors occured, Commit!
                    //Axapta.TTSCommit();
                }
                catch (Exception ex)
                {
                    //There was some errors, Abort transaction and Raise error!
                    //Axapta.TTSAbort();
                    throw new Exception(ex.Message);
                }
                finally
                {
                    //Finally logoff the Axapta Session
                    axapta.Logoff();
                }
            }
        }
Esempio n. 23
0
        public void PurchaseDyeingServicesToAx(TblDyeingOrdersHeader objToPost, TblDyeingOrdersMainDetail headerObjToPost, int postPostOrNo, int userIserial, string transactionGuid)
        {
            using (var context = new WorkFlowManagerDBEntities())
            {
                using (var axapta = new Axapta())
                {
                    var credential = new NetworkCredential("bcproxy", "around1");

                    TblAuthUser userToLogin = context.TblAuthUsers.SingleOrDefault(x => x.Iserial == userIserial);

                    axapta.LogonAs(userToLogin.User_Win_Login, userToLogin.User_Domain, credential, "Ccm", null, null, null);

                    var inventTable = axapta.CreateAxaptaRecord("InventDim");

                    try
                    {
                        var vendorWmsLocation = context.GetWmsLocations.FirstOrDefault(x => x.VENDID == objToPost.Vendor);

                        var vendorLoc =
                            context.GetLocations.FirstOrDefault(x => x.INVENTLOCATIONID == vendorWmsLocation.INVENTLOCATIONID);
                        var purchId   = "Rc_ " + objToPost.DocPlan.ToString() + objToPost.DyeingProductionOrder + headerObjToPost.TransId.ToString() + headerObjToPost.TransactionType;
                        var tableName = "PurchTable";
                        purchId = GenerateNewPurchase(purchId);

                        var purchTableRecord = axapta.CreateAxaptaRecord(tableName);
                        purchTableRecord.Clear();
                        purchTableRecord.InitValue();

                        purchTableRecord.set_Field("PurchId", purchId);
                        purchTableRecord.set_Field("DeliveryDate", headerObjToPost.TblDyeingOrdersDetails.OrderByDescending(x => x.EstimatedDeliveryDate).FirstOrDefault().EstimatedDeliveryDate ?? DateTime.Now);

                        var headerax = axapta.CallStaticRecordMethod("VendTable", "find", objToPost.Vendor) as AxaptaRecord;
                        purchTableRecord.Call("initFromVendTable", headerax);

                        purchTableRecord.Insert();

                        foreach (var item in headerObjToPost.TblDyeingOrdersDetails)
                        {
                            tableName = "PurchLine";
                            foreach (var servicerow in item.DyeingOrderDetailsServices)
                            {
                                var axaptaRecord = axapta.CreateAxaptaRecord(tableName);
                                axaptaRecord.Clear();
                                axaptaRecord.InitValue();

                                inventTable.Clear();
                                inventTable.set_Field("InventLocationId", vendorLoc.INVENTLOCATIONID);
                                inventTable.set_Field("wMSLocationId", vendorWmsLocation.WMSLOCATIONID);
                                if (item.Color != null)
                                {
                                    inventTable.set_Field("InventColorId", item.Color);
                                }

                                var importNew        = axapta.CreateAxaptaObject("CreateProductionJournals");
                                var producationOrder = "Free";
                                using (var model = new ax2009_ccEntities())
                                {
                                    var firstOrDefault = model.PRODCONNECTIONs.FirstOrDefault(
                                        x =>
                                        x.DYEDITEM == item.DyedFabric && x.TRANSID == item.DyeingProductionOrder &&
                                        x.TOCONFIG == item.Color && x.PRODID != "");
                                    if (firstOrDefault != null)
                                    {
                                        producationOrder =
                                            firstOrDefault.PRODID;
                                    }
                                }
                                if (producationOrder == null || (string)producationOrder == "")
                                {
                                    producationOrder = "Free";
                                }

                                importNew.Call("CreateConfig", servicerow.ServiceCode, item.Color);
                                importNew.Call("CreateBatch", servicerow.ServiceCode, producationOrder);
                                inventTable.set_Field("configId", item.Color);
                                inventTable.set_Field("inventBatchId", producationOrder);
                                inventTable.set_Field("INVENTSITEID", vendorLoc.INVENTSITEID);
                                inventTable = axapta.CallStaticRecordMethod("InventDim", "findOrCreate", inventTable) as AxaptaRecord;

                                if (inventTable != null)
                                {
                                    var tempx = inventTable.get_Field("inventDimId").ToString();
                                    axaptaRecord.set_Field("InventDimId", tempx);
                                }
                                axaptaRecord.set_Field("PurchUnit", "Kg");

                                axaptaRecord.set_Field("ItemId", servicerow.ServiceCode);
                                axaptaRecord.set_Field("purchId", purchId);
                                axaptaRecord.set_Field("QtyOrdered", Convert.ToDecimal(item.CalculatedTotalQty.ToString()));
                                decimal price = 1;
                                price = (decimal)servicerow.Qty;
                                axaptaRecord.set_Field("PurchPrice", Convert.ToDecimal(price));
                                axaptaRecord.set_Field("PurchQty", Convert.ToDecimal(item.CalculatedTotalQty.ToString()));
                                axaptaRecord.set_Field("LineAmount", Convert.ToDecimal(price * (decimal)item.CalculatedTotalQty));
                                axaptaRecord.Call("createLine", true, true, false, true, true, false);
                            }
                        }
                        if (postPostOrNo == 1)
                        {
                            var importNew = axapta.CreateAxaptaObject("CreateProductionJournals");
                            importNew.Call("PostPurchaseOrder", purchId, objToPost.TransactionDate ?? DateTime.Now);
                            PickingListForAxServices(objToPost, headerObjToPost, postPostOrNo, userIserial,
                                                     transactionGuid);
                        }
                    }

                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                    finally
                    {
                        axapta.Logoff();
                    }
                }
            }
        }
Esempio n. 24
0
        public void PurchaseDyeingServicesToAxAcc(TblDyeingOrdersHeaderAcc objToPost, TblDyeingOrdersMainDetailsACC headerObjToPost, int postPostOrNo, int userIserial, string transactionGuid)
        {
            using (var context = new WorkFlowManagerDBEntities())
            {
                using (var axapta = new Axapta())
                {
                    var credential = new NetworkCredential("bcproxy", "around1");

                    TblAuthUser userToLogin;

                    userToLogin = context.TblAuthUsers.SingleOrDefault(x => x.Iserial == userIserial);

                    axapta.LogonAs(userToLogin.User_Win_Login, userToLogin.User_Domain, credential, "Ccm", null, null, null);

                    var inventTable = axapta.CreateAxaptaRecord("InventDim");

                    try
                    {
                        var vendorWmsLocation = context.GetWmsLocations.SingleOrDefault(x => x.VENDID == objToPost.Vendor);

                        var vendorLoc =
                            context.GetLocations.SingleOrDefault(x => x.INVENTLOCATIONID == vendorWmsLocation.INVENTLOCATIONID);
                        var purchId          = "Rc_ " + headerObjToPost.DyeingProductionOrder.ToString() + headerObjToPost.TransId.ToString() + headerObjToPost.TransactionType;
                        var tableName        = "PurchTable";
                        var purchTableRecord = axapta.CreateAxaptaRecord(tableName);
                        purchTableRecord.Clear();
                        purchTableRecord.InitValue();

                        purchTableRecord.set_Field("PurchId", purchId);
                        purchTableRecord.set_Field("DeliveryDate", headerObjToPost.TblDyeingOrdersDetailsAccs.OrderByDescending(x => x.EstimatedDeliveryDate).FirstOrDefault().EstimatedDeliveryDate ?? DateTime.Now);

                        var headerax = axapta.CallStaticRecordMethod("VendTable", "find", objToPost.Vendor) as AxaptaRecord;
                        purchTableRecord.Call("initFromVendTable", headerax);

                        purchTableRecord.Insert();

                        foreach (var item in headerObjToPost.TblDyeingOrdersDetailsAccs)
                        {
                            tableName = "PurchLine";
                            foreach (var servicerow in item.DyeingOrderDetailsServicesAccs)
                            {
                                var axaptaRecord = axapta.CreateAxaptaRecord(tableName);
                                axaptaRecord.Clear();
                                axaptaRecord.InitValue();

                                inventTable.Clear();
                                inventTable.set_Field("InventLocationId", vendorLoc.INVENTLOCATIONID);
                                if (item.Color != null)
                                {
                                    inventTable.set_Field("InventColorId", item.Color);
                                }

                                var importNew        = axapta.CreateAxaptaObject("CreateProductionJournals");
                                var producationOrder = "Free";
                                using (var model = new ax2009_ccEntities())
                                {
                                    //  var batch = item.BatchNo.ToString();

                                    var firstOrDefault = model.PRODCONNECTIONs.FirstOrDefault(
                                        x =>
                                        x.DYEDITEM == item.DyedFabric && x.TRANSID == item.DyeingProductionOrder &&
                                        x.FROMCONFIG == item.Color &&
                                        // x.FROMBATCH == batch &&
                                        x.JOURNALLINKID == item.TransId);
                                    if (firstOrDefault != null)
                                    {
                                        producationOrder =
                                            firstOrDefault.PRODID;
                                    }
                                }
                                if (producationOrder == null || producationOrder == "")
                                {
                                    producationOrder = "Free";
                                }

                                importNew.Call("CreateConfig", servicerow.ServiceCode, item.Color);
                                importNew.Call("CreateBatch", servicerow.ServiceCode, producationOrder);
                                inventTable.set_Field("configId", item.Color);
                                inventTable.set_Field("inventBatchId", producationOrder);
                                inventTable = axapta.CallStaticRecordMethod("InventDim", "findOrCreate", inventTable) as AxaptaRecord;

                                if (inventTable != null)
                                {
                                    var tempx = inventTable.get_Field("inventDimId").ToString();
                                    axaptaRecord.set_Field("InventDimId", tempx);
                                }

                                axaptaRecord.set_Field("ItemId", servicerow.ServiceCode);
                                axaptaRecord.set_Field("purchId", purchId);
                                axaptaRecord.set_Field("QtyOrdered", Convert.ToDecimal(item.CalculatedTotalQty.ToString()));
                                decimal price = 1;

                                //context.TblTradeAgreementDetails.Where(x => x.ItemCode == servicerow.ServiceCode && x.TblTradeAgreementHeader1.Vendor == objToPost.Vendor);
                                axaptaRecord.set_Field("PurchPrice", Convert.ToDecimal(price));
                                axaptaRecord.set_Field("PurchQty", Convert.ToDecimal(item.CalculatedTotalQty.ToString()));
                                axaptaRecord.set_Field("LineAmount", Convert.ToDecimal(item.CalculatedTotalQty.ToString()) * price);
                                axaptaRecord.Call("createLine", true, true, true, true, true, false);
                            }
                            //No errors occured, Commit!
                            //Axapta.TTSCommit();

                            if (postPostOrNo == 1)
                            {
                                var importNew = axapta.CreateAxaptaObject("CreateProductionJournals");
                                importNew.Call("PostPurchaseOrder", purchId, objToPost.TransactionDate ?? DateTime.Now);
                                PickingListForAxServicesAcc(objToPost, headerObjToPost, postPostOrNo, userIserial,
                                                            transactionGuid);
                            }
                        }
                    }

                    catch (Exception ex)
                    {
                        //There was some errors, Abort transaction and Raise error!
                        //Axapta.TTSAbort();
                        throw new Exception(ex.Message);
                    }
                    finally
                    {
                        //Finally logoff the Axapta Session
                        axapta.Logoff();
                    }
                }
            }
        }
Esempio n. 25
0
        public bool DeleteAxFabItem(tbl_FabricAttriputes objToPost, bool deleteColors, int userIserial)
        {
            var axapta = new Axapta();

            try
            {
                var credential = new NetworkCredential("bcproxy", "around1");
                var user       = new TblAuthUser();
                using (var context = new WorkFlowManagerDBEntities())
                {
                    user = context.TblAuthUsers.FirstOrDefault(x => x.Iserial == userIserial);
                }

                axapta.LogonAs(user.User_Win_Login, user.User_Domain, credential, "Ccm", null, null, null);

                axapta.TTSBegin();
                var          itemId = objToPost.FabricID;
                AxaptaRecord axaptaRecord;

                var tableName = "InventTable";
                using (axaptaRecord = axapta.CreateAxaptaRecord(tableName))
                {
                    axaptaRecord.Clear();
                    axaptaRecord.InitValue();

                    // Execute a query to retrieve an editable record where the StatGroupName is “High Priority Customer”.
                    axaptaRecord.ExecuteStmt("select forupdate * from %1 where %1.ItemId =='" + itemId + "'");
                    // If the record is found then delete the record.
                    if (axaptaRecord.Found)
                    {
                        // Start a transaction that can be committed.
                        axapta.TTSBegin();
                        if (objToPost.Notes != null)
                        {
                            axaptaRecord.set_Field("Notes", objToPost.Notes);
                        }
                        // Commit the transaction.
                        axapta.TTSCommit();
                    }
                }

                //tableName = "TblFabricDetail";
                //using (axaptaRecord = axapta.CreateAxaptaRecord(tableName))
                //{
                //    axaptaRecord.Clear();
                //    axaptaRecord.InitValue();

                //    // Execute a query to retrieve an editable record where the StatGroupName is “High Priority Customer”.
                //    axaptaRecord.ExecuteStmt("select forupdate * from %1 where %1.ItemId =='" + itemId + "'");
                //    // If the record is found then delete the record.
                //    if (axaptaRecord.Found)
                //    {
                //        // Start a transaction that can be committed.
                //        axapta.TTSBegin();
                //        if (objToPost.Notes != null) axaptaRecord.set_Field("Notes", objToPost.Notes);
                //        // Commit the transaction.
                //        axapta.TTSCommit();
                //    }
                //}
                tableName = "INVENTTRANS";
                bool inventTransExists = false;
                using (axaptaRecord = axapta.CreateAxaptaRecord(tableName))
                {
                    axaptaRecord.Clear();
                    axaptaRecord.InitValue();

                    // Execute a query to retrieve an editable record where the StatGroupName is “High Priority Customer”.
                    axaptaRecord.ExecuteStmt("select  * from %1 where %1.ItemId =='" + itemId + "'");
                    // If the record is found then delete the record.
                    if (axaptaRecord.Found)
                    {
                        return(inventTransExists = true);
                    }
                }
                if (!inventTransExists)
                {
                    tableName = "InventTableModule";
                    using (axaptaRecord = axapta.CreateAxaptaRecord(tableName))
                    {
                        axaptaRecord.Clear();
                        axaptaRecord.InitValue();

                        // Execute a query to retrieve an editable record where the StatGroupName is “High Priority Customer”.
                        axaptaRecord.ExecuteStmt("select forupdate * from %1 where %1.ItemId =='" + itemId + "'");
                        // If the record is found then delete the record.
                        if (axaptaRecord.Found)
                        {
                            // Start a transaction that can be committed.
                            axapta.TTSBegin();
                            axaptaRecord.Delete();
                            // Commit the transaction.
                            axapta.TTSCommit();
                        }
                    }

                    tableName = "InventItemLocation";

                    using (axaptaRecord = axapta.CreateAxaptaRecord(tableName))
                    {
                        axaptaRecord.Clear();
                        axaptaRecord.InitValue();

                        // Execute a query to retrieve an editable record where the StatGroupName is “High Priority Customer”.
                        axaptaRecord.ExecuteStmt("select forupdate * from %1 where %1.ItemId =='" + itemId + "'");
                        // If the record is found then delete the record.
                        if (axaptaRecord.Found)
                        {
                            // Start a transaction that can be committed.
                            axapta.TTSBegin();
                            axaptaRecord.Delete();
                            // Commit the transaction.
                            axapta.TTSCommit();
                        }
                    }

                    if (deleteColors)
                    {
                        tableName = "ConfigTable";
                        using (axaptaRecord = axapta.CreateAxaptaRecord(tableName))
                        {
                            axaptaRecord.Clear();
                            axaptaRecord.InitValue();

                            // Execute a query to retrieve an editable record where the StatGroupName is “High Priority Customer”.
                            axaptaRecord.ExecuteStmt("select forupdate * from %1 where %1.ItemId =='" + itemId + "'");
                            // If the record is found then delete the record.
                            if (axaptaRecord.Found)
                            {
                                // Start a transaction that can be committed.
                                axapta.TTSBegin();
                                axaptaRecord.Delete();
                                // Commit the transaction.
                                axapta.TTSCommit();
                            }
                        }
                    }

                    tableName = "InventTable";
                    using (axaptaRecord = axapta.CreateAxaptaRecord(tableName))
                    {
                        axaptaRecord.Clear();
                        axaptaRecord.InitValue();

                        // Execute a query to retrieve an editable record where the StatGroupName is “High Priority Customer”.
                        axaptaRecord.ExecuteStmt("select forupdate * from %1 where %1.ItemId =='" + itemId + "'");
                        // If the record is found then delete the record.
                        if (axaptaRecord.Found)
                        {
                            // Start a transaction that can be committed.
                            axapta.TTSBegin();
                            axaptaRecord.Delete();
                            // Commit the transaction.
                            axapta.TTSCommit();
                        }
                    }
                    // Commit the record to the database.
                    axapta.TTSCommit();
                }
            }
            catch (Exception ex)
            {
                axapta.TTSAbort();
                throw ex;
            }
            return(false);
        }
Esempio n. 26
0
        public void PostRoutCardToAx(int routeCardHeaderIserial, int postPostOrNo) // posted=1
        {
            using (var context = new WorkFlowManagerDBEntities())
            {
                //int _TransID, string _WorkStationID, string _OperationID, int JournalType
                var routeHeaderRow = context
                                     .RouteCardHeaders.SingleOrDefault(x => x.Iserial == routeCardHeaderIserial);

                var operation = context.WF_RouteGroup.Where(x => x.iSerial == routeHeaderRow.RoutGroupID).Select(x => x.Code).SingleOrDefault();

                var workStation = context.WF_Route.Where(x => x.iSerial == routeHeaderRow.RoutID).Select(x => x.Code).SingleOrDefault();

                var detailsObjToPost = context
                                       .RealRoutCards
                                       .Where(x => x.TransID == routeHeaderRow.TransID &&
                                              x.Operation == operation &&
                                              x.WorkStation == workStation).ToList();

                var axapta     = new Axapta();
                var credential = new NetworkCredential("bcproxy", "around1");
                axapta.LogonAs("osama.gamal", "ccasual.loc", credential, "ccm", null, null, null);

                AxaptaRecord salesRecord = axapta.CreateAxaptaRecord("SalesLine"), invent = axapta.CreateAxaptaRecord("InventDim");

                const string tableName = "AutoRoute";
                //List<string> _TempinventDimIDList = new List<string>();
                //_TempinventDimIDList.Add("00008851_086");
                //_TempinventDimIDList.Add("00012748_086");
                //_TempinventDimIDList.Add("00008851_086");
                bool posted = false;

                try
                {
                    if (detailsObjToPost.Count > 0)
                    {
                        foreach (var item in detailsObjToPost)
                        {
                            axapta.ExecuteStmt("select * from %1 "
                                               + "JOIN %2"
                                               + " where %1.InventDimId == %2.InventDimId"
                                               + " && %2.ConfigID =='" + item.Color + "'"
                                               + " && %1.SalesId == '" + item.SalesOrder + "'", salesRecord, invent);
                            var inventDim = salesRecord.get_Field("InventDimID").ToString();

                            var axaptaRecord = axapta.CreateAxaptaRecord(tableName);
                            axaptaRecord.Clear();
                            axaptaRecord.InitValue();

                            axaptaRecord.set_Field("TransId", routeCardHeaderIserial);
                            if (item.StyleHeader != null)
                            {
                                axaptaRecord.set_Field("ItemID", item.StyleHeader);
                            }
                            if (item.SalesOrder != null)
                            {
                                axaptaRecord.set_Field("SalesId", item.SalesOrder);
                            }
                            if (item.Color != null)
                            {
                                axaptaRecord.set_Field("Colour", item.Color);
                            }
                            if (item.WorkStation != null)
                            {
                                axaptaRecord.set_Field("Machine", item.WorkStation);
                            }
                            if (item.Qty != null)
                            {
                                axaptaRecord.set_Field("Qty", Convert.ToDecimal(item.Qty.ToString()));
                            }
                            if (item.Operation != null)
                            {
                                axaptaRecord.set_Field("Operation", item.Operation);
                            }
                            if (item.DocDate != null)
                            {
                                axaptaRecord.set_Field("DocDate", item.DocDate);
                            }
                            axaptaRecord.set_Field("WhareHouse", "");
                            axaptaRecord.set_Field("Site", "");
                            if (inventDim != null)
                            {
                                axaptaRecord.set_Field("InventDimID", inventDim);
                            }
                            axaptaRecord.set_Field("JournalType", 5);
                            if ((routeHeaderRow.RouteType == 5))
                            {
                                axaptaRecord.set_Field("BatchId", "1");
                                axaptaRecord.set_Field("JournalType", 5);
                            }

                            axaptaRecord.Insert();
                        }
                        var import = axapta.CreateAxaptaObject("CreateProductionJournals");

                        var retval = import.Call("CreateRouteJournal", routeCardHeaderIserial, workStation, operation, 5, postPostOrNo);

                        if (retval.ToString() == "0")
                        {
                            throw new Exception("Error While Posting To AX");
                        }
                        else
                        {
                            routeHeaderRow.AxRouteCardJournalId = retval.ToString();

                            if (postPostOrNo == 1)
                            {
                                posted = true;
                            }
                            routeHeaderRow.IsPosted = posted;
                        }

                        ClearAxTable(tableName, axapta);

                        context.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    //There was some errors, Abort transaction and Raise error!
                    //Axapta.TTSAbort();
                    throw new Exception(ex.Message);
                }
                finally
                {
                    //Finally logoff the Axapta Session
                    axapta.Logoff();
                }

                if (routeHeaderRow.RouteType == 3) // Report AS a Finish
                {
                    PostReportAsAFinish(routeHeaderRow.TransID, 3, routeCardHeaderIserial, postPostOrNo);
                }

                if (routeHeaderRow.Direction == 0)
                {
                    PurchaseRouteServicesToAx(routeHeaderRow, postPostOrNo);
                }

                PickingList(routeCardHeaderIserial, postPostOrNo);
            }
        }
Esempio n. 27
0
        public void InsertFabItem(tbl_FabricAttriputes objToPost, string categoryName, string fabricType, int userIserial)
        {
            var axapta = new Axapta();

            try
            {
                using (var context = new WorkFlowManagerDBEntities())
                {
                    var credential = new NetworkCredential("bcproxy", "around1");
                    var user       = context.TblAuthUsers.FirstOrDefault(x => x.Iserial == userIserial);

                    axapta.LogonAs(user.User_Win_Login, user.User_Domain, credential, "Ccm", null, null, null);

                    axapta.TTSBegin();
                    var itemId    = objToPost.FabricID;
                    var tableName = "InventTable";

                    var axaptaRecord = axapta.CreateAxaptaRecord(tableName);
                    axaptaRecord.Clear();
                    axaptaRecord.InitValue();

                    if (fabricType != null)
                    {
                        axaptaRecord.set_Field("ItemGroupId",
                                               fabricType.ToUpper() == "KNITTED"
                                ? "KNITTED-FABRIC"
                                : "FINISHED-FABRIC");
                    }
                    else
                    {
                        axaptaRecord.set_Field("ItemGroupId",
                                               categoryName.ToUpper() == "FINISHED"
                                ? "FINISHED-FABRIC"
                                : categoryName.ToUpper() == "RAW"
                                    ? "KNITTED-FABRIC"
                                    : categoryName == "DYINGWOVEN"
                                        ? "FINISHED-FABRIC"
                                        : categoryName == "DYINGKNITED"
                                            ? "FINISHED-FABRIC"
                                            : categoryName == "Accessories"
                                                ? "ACCESSORIES"
                                                : "YARN"
                                               );
                    }
                    if (objToPost.Notes != null)
                    {
                        axaptaRecord.set_Field("Notes", objToPost.Notes);
                    }
                    axaptaRecord.set_Field("ItemId", itemId);
                    axaptaRecord.set_Field("ItemName", objToPost.FabricDescription);
                    axaptaRecord.set_Field("ModelGroupID", "STD");
                    axaptaRecord.set_Field("ItemType",
                                           categoryName.ToUpper() == "FINISHED"
                            ? 0
                            : categoryName.ToUpper() == "RAW"
                                ? 1
                                : categoryName.ToUpper() == "DYINGWOVEN"
                                    ? 1
                                    : categoryName.ToUpper() == "DYINGKNITED"
                                        ? 1
                                        : 0);

                    if (objToPost.DyingClassificationID != null)
                    {
                        //DyedGroup
                        axaptaRecord.set_Field("DyedGroup", objToPost.DyingClassificationID.ToString());
                    }
                    axaptaRecord.set_Field("DimGroupId", "FABRIC");
                    //Commit the record to the database.
                    axaptaRecord.Insert();

                    tableName    = "InventTableModule";
                    axaptaRecord = axapta.CreateAxaptaRecord(tableName);
                    axaptaRecord.Clear();
                    axaptaRecord.InitValue();

                    axaptaRecord.set_Field("ItemId", itemId);
                    axaptaRecord.set_Field("ModuleType", 0);
                    axaptaRecord.set_Field("Price", 0.00);
                    if (objToPost.UoMID != null)
                    {
                        var tempu = context.tbl_lkp_UoM
                                    .Where(x => x.Iserial == objToPost.UoMID)
                                    .Select(x => x.Ename)
                                    .SingleOrDefault();
                        axaptaRecord.set_Field("UnitId", tempu);
                        //axaptaRecord.set_Field("PriceUnit", tempu);
                    }
                    //
                    axaptaRecord.Insert();

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

                    axaptaRecord.set_Field("ItemId", itemId);
                    axaptaRecord.set_Field("ModuleType", 1);
                    axaptaRecord.set_Field("Price", 0.00);
                    if (objToPost.UoMID != null)
                    {
                        var tempu = context.tbl_lkp_UoM
                                    .Where(x => x.Iserial == objToPost.UoMID)
                                    .Select(x => x.Ename)
                                    .SingleOrDefault();
                        axaptaRecord.set_Field("UnitId", tempu);
                        //axaptaRecord.set_Field("PriceUnit", tempu);
                    }
                    //
                    axaptaRecord.Insert();

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

                    axaptaRecord.set_Field("ItemId", itemId);
                    axaptaRecord.set_Field("ModuleType", 2);
                    axaptaRecord.set_Field("Price", 0.00);
                    if (objToPost.UoMID != null)
                    {
                        var tempu = context.tbl_lkp_UoM
                                    .Where(x => x.Iserial == objToPost.UoMID)
                                    .Select(x => x.Ename)
                                    .SingleOrDefault();
                        axaptaRecord.set_Field("UnitId", tempu);
                        //axaptaRecord.set_Field("PriceUnit", tempu);
                    }
                    //
                    axaptaRecord.Insert();

                    tableName = "InventItemLocation";

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

                    axaptaRecord.set_Field("ItemId", itemId);
                    axaptaRecord.set_Field("InventDIMID", "AllBlank");
                    axaptaRecord.Insert();
                    try
                    {
                        tableName    = "ConfigTable";
                        axaptaRecord = axapta.CreateAxaptaRecord(tableName);
                        axaptaRecord.Clear();
                        axaptaRecord.InitValue();

                        axaptaRecord.set_Field("ItemId", itemId);
                        axaptaRecord.set_Field("ConfigId", "Free");
                        axaptaRecord.set_Field("Name", "Free");
                        //Commit the record to the database.
                        axaptaRecord.Insert();
                    }
                    catch
                    {
                        //if record exists do nothing and continue
                    }

                    // Commit the record to the database.
                    var categ = (from x in context.tbl_FabricCategories
                                 where x.Iserial == objToPost.FabricCategoryID
                                 select x).FirstOrDefault();
                    if (categ != null)
                    {
                        try
                        {
                            axapta.CallStaticRecordMethod("TblFabricCategory", "findOrCreate", categ.Iserial, categ.Code,
                                                          categ.Ename, categ.Aname);
                        }
                        catch
                        {
                            //if record exists do nothing and continue
                        }
                    }

                    var temp = (from x in context.tbl_FabricAttriputes
                                .Include("tbl_lkp_FabricDesignes").Include("tbl_lkp_FabricFinish").Include("tbl_lkp_FabricMaterials")
                                .Include("tbl_lkp_FabricStructure").Include("tbl_lkp_FabricTypes").Include("tbl_lkp_Inch").Include("tbl_lkp_Gauges")
                                .Include("tbl_lkp_ThreadNumbers").Include("tbl_lkp_YarnSource").Include("tbl_lkp_YarnCount").Include("tbl_lkp_YarnFinish")
                                .Include("tbl_lkp_YarnStatus")
                                where x.FabricCategoryID == objToPost.FabricCategoryID &&
                                x.FabricID == objToPost.FabricID
                                select x).FirstOrDefault();

                    if (temp != null)
                    {
                        if (temp.tbl_lkp_FabricDesignes != null)
                        {
                            try
                            {
                                axapta.CallStaticRecordMethod("TblFabricDesign", "findOrCreate", temp.tbl_lkp_FabricDesignes.Iserial, temp.tbl_lkp_FabricDesignes.Code,
                                                              temp.tbl_lkp_FabricDesignes.Ename, temp.tbl_lkp_FabricDesignes.Aname);
                            }
                            catch
                            {
                            }
                        }

                        if (temp.tbl_lkp_FabricFinish != null)
                        {
                            try
                            {
                                axapta.CallStaticRecordMethod("TblFabricFinish", "findOrCreate", temp.tbl_lkp_FabricFinish.Iserial, temp.tbl_lkp_FabricFinish.Code,
                                                              temp.tbl_lkp_FabricFinish.Ename, temp.tbl_lkp_FabricFinish.Aname);
                            }
                            catch
                            {
                            }
                        }
                        if (temp.tbl_lkp_FabricMaterials != null)
                        {
                            try
                            {
                                axapta.CallStaticRecordMethod("TblFabricMaterial", "findOrCreate", temp.tbl_lkp_FabricMaterials.Iserial, temp.tbl_lkp_FabricMaterials.Code,
                                                              temp.tbl_lkp_FabricMaterials.Ename, temp.tbl_lkp_FabricMaterials.Aname);
                            }
                            catch
                            {
                            }
                        }

                        if (temp.tbl_lkp_FabricStructure != null)
                        {
                            try
                            {
                                axapta.CallStaticRecordMethod("TblFabricStructure", "findOrCreate", temp.tbl_lkp_FabricStructure.Iserial, temp.tbl_lkp_FabricStructure.Code,
                                                              temp.tbl_lkp_FabricStructure.Ename, temp.tbl_lkp_FabricStructure.Aname);
                            }
                            catch
                            {
                            }
                        }

                        if (temp.tbl_lkp_FabricTypes != null)
                        {
                            try
                            {
                                axapta.CallStaticRecordMethod("TblFabricType", "findOrCreate", temp.tbl_lkp_FabricTypes.Iserial, temp.tbl_lkp_FabricTypes.Code,
                                                              temp.tbl_lkp_FabricTypes.Ename, temp.tbl_lkp_FabricTypes.Aname);
                            }
                            catch
                            {
                            }
                        }

                        if (temp.tbl_lkp_Inch != null)
                        {
                            try
                            {
                                axapta.CallStaticRecordMethod("TblInch", "findOrCreate", temp.tbl_lkp_Inch.Iserial, temp.tbl_lkp_Inch.Code,
                                                              temp.tbl_lkp_Inch.Ename, temp.tbl_lkp_Inch.Aname);
                            }
                            catch
                            {
                            }
                        }

                        if (temp.tbl_lkp_Gauges != null)
                        {
                            try
                            {
                                axapta.CallStaticRecordMethod("TblGuage", "findOrCreate", temp.tbl_lkp_Gauges.Iserial, temp.tbl_lkp_Gauges.Code,
                                                              temp.tbl_lkp_Gauges.Ename, temp.tbl_lkp_Gauges.Aname);
                            }
                            catch
                            {
                            }
                        }
                        if (temp.tbl_lkp_ThreadNumbers != null)
                        {
                            try
                            {
                                axapta.CallStaticRecordMethod("TblThread", "findOrCreate", temp.tbl_lkp_ThreadNumbers.Iserial, temp.tbl_lkp_ThreadNumbers.Code,
                                                              temp.tbl_lkp_ThreadNumbers.Ename, temp.tbl_lkp_ThreadNumbers.Aname);
                            }
                            catch
                            {
                            }
                        }

                        if (temp.tbl_lkp_YarnSource != null)
                        {
                            try
                            {
                                axapta.CallStaticRecordMethod("TblYarnSource", "findOrCreate", temp.tbl_lkp_YarnSource.Iserial, temp.tbl_lkp_YarnSource.Code,
                                                              temp.tbl_lkp_YarnSource.Ename, temp.tbl_lkp_YarnSource.Aname);
                            }
                            catch
                            {
                            }
                        }

                        if (temp.tbl_lkp_YarnCount != null)
                        {
                            try
                            {
                                axapta.CallStaticRecordMethod("TblYarnCount", "findOrCreate", temp.tbl_lkp_YarnCount.Iserial, temp.tbl_lkp_YarnCount.Code,
                                                              temp.tbl_lkp_YarnCount.Ename, temp.tbl_lkp_YarnCount.Aname);
                            }
                            catch
                            {
                            }
                        }

                        if (temp.tbl_lkp_YarnFinish != null)
                        {
                            try
                            {
                                axapta.CallStaticRecordMethod("TblYarnFinish", "findOrCreate", temp.tbl_lkp_YarnFinish.Iserial, temp.tbl_lkp_YarnFinish.Code,
                                                              temp.tbl_lkp_YarnFinish.Ename, temp.tbl_lkp_YarnFinish.Aname);
                            }
                            catch
                            {
                            }
                        }

                        if (temp.tbl_lkp_YarnStatus != null)
                        {
                            try
                            {
                                axapta.CallStaticRecordMethod("TblYarnStatus", "findOrCreate", temp.tbl_lkp_YarnStatus.Iserial, temp.tbl_lkp_YarnStatus.Code,
                                                              temp.tbl_lkp_YarnStatus.Ename, temp.tbl_lkp_YarnStatus.Aname);
                            }
                            catch
                            {
                            }
                        }

                        axapta.CallStaticRecordMethod("TblFabricDetail", "findOrCreate", temp.FabricID, temp.YarnStatusID ?? 0, temp.YarnFinishesID ?? 0, temp.YarnCountID ?? 0, temp.YarnSource ?? 0, temp.ThreadNumbersID ?? 0, temp.GaugesID ?? 0,
                                                      temp.InchesID ?? 0, temp.FabricTypesID ?? 0, temp.FabricStructuresID ?? 0, temp.FabricMaterialsID ?? 0, temp.FabricFinishesID ?? 0, temp.FabricDesignsID ?? 0, temp.FabricCategoryID
                                                      );

                        temp.Status = 2;
                    }

                    context.SaveChanges();
                    axapta.TTSCommit();
                }
            }
            catch (Exception ex)
            {
                axapta.TTSAbort();
                throw ex;
            }
        }
Esempio n. 28
0
        private void PostReportAsAFinish(int transId, int journalType, int routeCardHeaderIserial, int postPostOrNo)
        {
            using (var context = new WorkFlowManagerDBEntities())
            {
                var routeCardHeaderRow = context
                                         .RouteCardHeaders.SingleOrDefault(x => x.Iserial == routeCardHeaderIserial);

                var chainSetupList = context.tblChainSetups.Where(x => x.sGridHeaderEName == "Route Card").ToList();

                var routeCardDetailList = context.RouteCardDetails.Where(x => x.RoutGroupID == routeCardHeaderRow.RoutGroupID &&
                                                                         x.Trans_TransactionHeader == transId && x.Direction == routeCardHeaderRow.Direction).ToList();
                var axapta     = new Axapta();
                var credential = new NetworkCredential("bcproxy", "around1");
                axapta.LogonAs("osama.gamal", "ccasual.loc", credential, "ccm", null, null, null);
                const string tableName = "AutoRoute";
                AxaptaRecord salesRecord = axapta.CreateAxaptaRecord("SalesLine"), invent = axapta.CreateAxaptaRecord("InventDim");

                int i = 0;
                try
                {
                    if (routeCardDetailList.Count > 0)
                    {
                        foreach (var item in routeCardDetailList)
                        {
                            string warehouse = null;
                            if (item.Degree == "1st")
                            {
                                warehouse = chainSetupList.SingleOrDefault(x => x.sGlobalSettingCode == "DefaultFPWarehouse1st").sSetupValue;
                            }
                            else if (item.Degree == "2nd")
                            {
                                warehouse = chainSetupList.SingleOrDefault(x => x.sGlobalSettingCode == "DefaultFPWarehouse2st").sSetupValue;
                            }
                            else if (item.Degree == "3rd")
                            {
                                warehouse = chainSetupList.SingleOrDefault(x => x.sGlobalSettingCode == "DefaultFPWarehouse3rd").sSetupValue;
                            }

                            var site = context.GetLocations.Where(x => x.INVENTLOCATIONID == warehouse).Select(x => x.INVENTSITEID).FirstOrDefault();

                            #region MyRegion

                            axapta.ExecuteStmt("select * from %1 "
                                               + "JOIN %2"
                                               + " where %1.InventDimId == %2.InventDimId"
                                               + " && %2.ConfigID =='" + item.Color + "'"
                                               + " && %1.SalesId == '" + item.SalesOrder + "'", salesRecord, invent);
                            var inventDim = salesRecord.get_Field("InventDimID").ToString();

                            #endregion MyRegion

                            var axaptaRecord = axapta.CreateAxaptaRecord(tableName);
                            axaptaRecord.Clear();
                            axaptaRecord.InitValue();

                            axaptaRecord.set_Field("TransId", routeCardHeaderRow.Iserial);
                            if (item.Style != null)
                            {
                                axaptaRecord.set_Field("ItemID", item.Style);
                            }
                            if (item.SalesOrder != null)
                            {
                                axaptaRecord.set_Field("SalesId", item.SalesOrder);
                            }
                            if (item.Color != null)
                            {
                                axaptaRecord.set_Field("Colour", item.Color);
                            }
                            //  AxaptaRecord.set_Field("Machine", _WorkStationID);
                            if (item.SizeQuantity != null)
                            {
                                axaptaRecord.set_Field("Qty", Convert.ToDecimal(item.SizeQuantity));
                            }
                            //   AxaptaRecord.set_Field("Operation", _OperationID);
                            if (routeCardHeaderRow.DocDate != null)
                            {
                                axaptaRecord.set_Field("DocDate", routeCardHeaderRow.DocDate);
                            }
                            if (warehouse != null)
                            {
                                axaptaRecord.set_Field("WhareHouse", warehouse);
                            }
                            if (warehouse != null)
                            {
                                axaptaRecord.set_Field("Location", warehouse);
                            }
                            if (site != null)
                            {
                                axaptaRecord.set_Field("Site", site);
                            }
                            axaptaRecord.set_Field("InventDimID", inventDim);
                            axaptaRecord.set_Field("JournalType", journalType);
                            axaptaRecord.set_Field("BatchId", "N/a");
                            if (item.Size != null)
                            {
                                axaptaRecord.set_Field("SreialId", item.Size);
                            }

                            if (i < 3)
                            {
                                i++;
                            }
                            axaptaRecord.Insert();
                        }
                        var import = axapta.CreateAxaptaObject("CreateProductionJournals");

                        var retval = import.Call("CreateReportJournal", routeCardHeaderRow.Iserial, journalType, true, postPostOrNo);

                        if (retval.ToString() == "0")
                        {
                            throw new Exception("Error While Posting To AX");
                        }
                        else
                        {
                            routeCardHeaderRow.AxReportAsAFinishedJournalId = retval.ToString();
                        }

                        ClearAxTable(tableName, axapta);

                        context.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    //There was some errors, Abort transaction and Raise error!
                    //Axapta.TTSAbort();
                    throw new Exception(ex.Message);
                }
                finally
                {
                    //Finally logoff the Axapta Session
                    axapta.Logoff();
                }
            }
        }
Esempio n. 29
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();
                }
            }
        }
Esempio n. 30
0
        public void ProducationConnectionAcc(int dyeingProductionOrder, int transId, int transactionType, int userIserial)
        {
            using (var entities = new WorkFlowManagerDBEntities())
            {
                var header     = entities.TblDyeingOrdersHeaderAccs.SingleOrDefault(x => x.DyeingProductionOrder == dyeingProductionOrder);
                var mainDetail = entities.TblDyeingOrdersMainDetailsACCs.Include("TblDyeingOrdersDetailsAccs.DyeingOrderDetailsServicesAccs").SingleOrDefault(x => x.DyeingProductionOrder == dyeingProductionOrder &&
                                                                                                                                                              x.TransId == transId && x.TransactionType == transactionType);
                var locationLoc = entities.GetLocations.SingleOrDefault(x => x.INVENTLOCATIONID == mainDetail.WareHouse);

                var vendorWmsLocation = entities.GetWmsLocations.SingleOrDefault(x => x.VENDID == header.Vendor);

                var vendorLoc  = entities.GetLocations.SingleOrDefault(x => x.INVENTLOCATIONID == vendorWmsLocation.INVENTLOCATIONID);
                var axapta     = new Axapta();
                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);
                var tableName       = "PRODCONNECTION";
                var transactionGuid = Guid.NewGuid().ToString();
                foreach (var item in mainDetail.TblDyeingOrdersDetailsAccs)
                {
                    try
                    {
                        AxaptaRecord AxaptaRecord;

                        #region TransactionType0  Transfer To Vendor's Location And ProductionOrder And PickingList

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

                        if (item.TransactionType == 0)
                        {
                            //Transfer To Vendor's Location

                            AxaptaRecord.set_Field("TRANSID", item.DyeingProductionOrder);
                            AxaptaRecord.set_Field("RAWID", item.FabricCode);
                            AxaptaRecord.set_Field("RAWQTY", item.CalculatedTotalQty);
                            AxaptaRecord.set_Field("UNITID", item.Unit);
                            AxaptaRecord.set_Field("FROMSITE", locationLoc.INVENTSITEID);
                            AxaptaRecord.set_Field("FROMLOCATION", mainDetail.WareHouse);
                            AxaptaRecord.set_Field("FROMWAREHOUSE", mainDetail.WareHouse);
                            AxaptaRecord.set_Field("FROMBATCH", "Free");
                            AxaptaRecord.set_Field("FROMCONFIG", item.Color);
                            AxaptaRecord.set_Field("TOSITE", vendorLoc.INVENTSITEID);
                            AxaptaRecord.set_Field("TOLOCATION", vendorWmsLocation.WMSLOCATIONID);
                            AxaptaRecord.set_Field("TOWAREHOUSE", vendorWmsLocation.INVENTLOCATIONID);
                            //AxaptaRecord.set_Field("TOBATCH", item.BatchNo.ToString());
                            AxaptaRecord.set_Field("TOCONFIG", item.Color);
                            AxaptaRecord.set_Field("TRANSTYPE", Convert.ToInt64(0));
                            AxaptaRecord.set_Field("JOURNALLINKID", transId);
                            AxaptaRecord.set_Field("TransactionGuid", transactionGuid);
                            AxaptaRecord.Insert();

                            //  //   ProductionOrder

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

                            AxaptaRecord.set_Field("TRANSID", item.DyeingProductionOrder);
                            AxaptaRecord.set_Field("DYEDITEM", item.DyedFabric);
                            AxaptaRecord.set_Field("DYEDQTY", item.CalculatedTotalQty);
                            AxaptaRecord.set_Field("UNITID", item.Unit);
                            AxaptaRecord.set_Field("JOURNALLINKID", transId);
                            AxaptaRecord.set_Field("FROMSITE", vendorLoc.INVENTSITEID);
                            AxaptaRecord.set_Field("TOSITE", vendorLoc.INVENTSITEID);
                            AxaptaRecord.set_Field("FROMLOCATION", vendorWmsLocation.WMSLOCATIONID);
                            AxaptaRecord.set_Field("TOLOCATION", vendorWmsLocation.WMSLOCATIONID);
                            AxaptaRecord.set_Field("TRANSTYPE", Convert.ToInt64(1));
                            AxaptaRecord.set_Field("FROMCONFIG", item.Color);
                            AxaptaRecord.set_Field("TOCONFIG", item.Color);
                            //  AxaptaRecord.set_Field("FROMBATCH", item.BatchNo.ToString());
                            //   AxaptaRecord.set_Field("TOBATCH", item.BatchNo.ToString());
                            AxaptaRecord.set_Field("FROMWAREHOUSE", vendorWmsLocation.INVENTLOCATIONID);
                            AxaptaRecord.set_Field("TOWAREHOUSE", vendorWmsLocation.INVENTLOCATIONID);
                            AxaptaRecord.set_Field("TransactionGuid", transactionGuid);
                            AxaptaRecord.Insert();

                            ////     PickingList
                            AxaptaRecord = axapta.CreateAxaptaRecord(tableName);
                            AxaptaRecord.Clear();
                            AxaptaRecord.InitValue();
                            AxaptaRecord.set_Field("TRANSID", item.DyeingProductionOrder);
                            AxaptaRecord.set_Field("RAWID", item.FabricCode);
                            AxaptaRecord.set_Field("DYEDITEM", item.DyedFabric);
                            AxaptaRecord.set_Field("RAWQTY", item.CalculatedTotalQty);
                            AxaptaRecord.set_Field("DYEDQTY", item.CalculatedTotalQty);
                            AxaptaRecord.set_Field("UNITID", item.Unit);
                            AxaptaRecord.set_Field("FROMSITE", vendorLoc.INVENTSITEID);
                            AxaptaRecord.set_Field("TOSITE", vendorLoc.INVENTSITEID);
                            AxaptaRecord.set_Field("FROMLOCATION", vendorWmsLocation.WMSLOCATIONID);
                            AxaptaRecord.set_Field("TOLOCATION", vendorWmsLocation.WMSLOCATIONID);
                            AxaptaRecord.set_Field("TRANSTYPE", Convert.ToInt64(2));
                            AxaptaRecord.set_Field("FROMCONFIG", item.Color);
                            AxaptaRecord.set_Field("TOCONFIG", item.Color);
                            //AxaptaRecord.set_Field("FROMBATCH", item.BatchNo.ToString());
                            //AxaptaRecord.set_Field("TOBATCH", item.BatchNo.ToString());
                            AxaptaRecord.set_Field("FROMWAREHOUSE", vendorWmsLocation.INVENTLOCATIONID);
                            AxaptaRecord.set_Field("TOWAREHOUSE", vendorWmsLocation.INVENTLOCATIONID);
                            AxaptaRecord.set_Field("JOURNALLINKID", transId);
                            AxaptaRecord.set_Field("TransactionGuid", transactionGuid);
                            AxaptaRecord.Insert();
                        }

                        #endregion TransactionType0  Transfer To Vendor's Location And ProductionOrder And PickingList

                        #region TransactionType3 ReportAsFinished

                        else if (item.TransactionType == 1)
                        {
                            AxaptaRecord = axapta.CreateAxaptaRecord(tableName);
                            AxaptaRecord.Clear();
                            AxaptaRecord.InitValue();

                            AxaptaRecord.set_Field("TRANSID", item.DyeingProductionOrder);
                            AxaptaRecord.set_Field("DYEDITEM", item.DyedFabric);
                            AxaptaRecord.set_Field("DYEDQTY", item.CalculatedTotalQty);
                            AxaptaRecord.set_Field("UNITID", item.Unit);
                            AxaptaRecord.set_Field("FROMSITE", vendorLoc.INVENTSITEID);
                            AxaptaRecord.set_Field("TOSITE", locationLoc.INVENTSITEID);
                            AxaptaRecord.set_Field("FROMLOCATION", vendorWmsLocation.WMSLOCATIONID);
                            AxaptaRecord.set_Field("TOLOCATION", mainDetail.WareHouse);
                            AxaptaRecord.set_Field("TRANSTYPE", Convert.ToInt64(3));
                            AxaptaRecord.set_Field("FROMCONFIG", item.Color);
                            AxaptaRecord.set_Field("TOCONFIG", item.Color);
                            // AxaptaRecord.set_Field("FROMBATCH", item.BatchNo.ToString());
                            // AxaptaRecord.set_Field("TOBATCH", item.BatchNo.ToString());
                            AxaptaRecord.set_Field("JOURNALLINKID", transId);
                            AxaptaRecord.set_Field("TOWAREHOUSE", mainDetail.WareHouse);
                            AxaptaRecord.set_Field("FROMWAREHOUSE", vendorWmsLocation.INVENTLOCATIONID);

                            AxaptaRecord.Insert();
                        }

                        #endregion TransactionType3 ReportAsFinished
                    }
                    catch (Exception)
                    {
                    }
                }
                var import = axapta.CreateAxaptaObject("CLEDyeProcesse");
                try
                {
                    if (transactionType == 0)
                    {
                        //public ProdJournalId run(int transId,int journalId,int WhatToDo,str JourName,int PostorNo)
                        var Production  = import.Call("run", dyeingProductionOrder, transId, 1, "", 1);
                        var Transfer    = import.Call("run", dyeingProductionOrder, transId, 0, "Name", 1);
                        var PickingList = import.Call("run", dyeingProductionOrder, transId, 2, "Name", 1);
                        PurchaseDyeingServicesToAxAcc(header, mainDetail, 0, userIserial, transactionGuid);
                    }
                    else if (transactionType == 1)
                    {
                        var ReportAsFinished = import.Call("run", dyeingProductionOrder, transId, 3, "Name", 1);
                    }

                    mainDetail.Posted = true;
                    entities.SaveChanges();
                }
                catch (Exception)
                {
                    throw;
                }

                Operations.SharedOperation.ClearAxTable("PRODCONNECTION", axapta, transactionGuid);
                axapta.Logoff();
            }
        }
Esempio n. 31
0
        private void PickingList(int routeCardHeaderIserial, int postPostOrNo)
        {
            using (var entities = new WorkFlowManagerDBEntities())
            {
                var routeHeaderRow = entities
                                     .RouteCardHeaders.SingleOrDefault(x => x.Iserial == routeCardHeaderIserial);

                var pickingList = entities.RouteCardFabrics.Where(x => x.RouteCardHeaderIserial == routeHeaderRow.Iserial).ToList();

                try
                {
                    if (pickingList.Count() != 0)
                    {
                        var axapta     = new Axapta();
                        var credential = new NetworkCredential("bcproxy", "around1");
                        axapta.LogonAs("osama.gamal", "ccasual.loc", credential, "ccm", null, null, null);
                        const string tableName = "AutoPICKING";

                        foreach (var item in pickingList)
                        {
                            var site = entities.GetLocations.Where(x => x.INVENTLOCATIONID == item.Warehouse).Select(x => x.INVENTSITEID).FirstOrDefault();

                            var axaptaRecord = axapta.CreateAxaptaRecord(tableName);
                            axaptaRecord.Clear();
                            axaptaRecord.InitValue();
                            axaptaRecord.set_Field("DATAAREAID", "CCM");
                            if (item != null)
                            {
                                if (item.SalesOrder != null)
                                {
                                    axaptaRecord.set_Field("SALESORDER", item.SalesOrder);
                                }
                                if (item.ItemId != null)
                                {
                                    axaptaRecord.set_Field("FABRICID", item.ItemId);
                                }
                                if (item.FabricColor != null)
                                {
                                    axaptaRecord.set_Field("FABRIC_COLOR", item.FabricColor);
                                }
                                if (item.Style != null)
                                {
                                    axaptaRecord.set_Field("STYLEID", item.Style);
                                }
                                if (item.StyleColor != null)
                                {
                                    axaptaRecord.set_Field("STYLECOLOR", item.StyleColor);
                                }
                                if (site != null)
                                {
                                    axaptaRecord.set_Field("FABRICSITEID", site);
                                }
                                if (item.Warehouse != null)
                                {
                                    axaptaRecord.set_Field("FABRICLOCATION", item.Warehouse);
                                    axaptaRecord.set_Field("FABRICWAREHOUSES", item.Warehouse);
                                }
                                if (item.Barcode != null)
                                {
                                    axaptaRecord.set_Field("FABRICBATCHNUMBER", item.Barcode.ToString());
                                }
                                axaptaRecord.set_Field("TRANSDATE", routeHeaderRow.DocDate);
                                axaptaRecord.set_Field("QTY", item.Qty);
                            }
                            axaptaRecord.set_Field("VENDOR", routeHeaderRow.Vendor);
                            axaptaRecord.set_Field("WORKFLOWJOURID", routeHeaderRow.Iserial);

                            axaptaRecord.Insert();
                        }

                        var importNew = axapta.CreateAxaptaObject("CreateProductionJournals");
                        var retval    = importNew.Call("CreatePicking", routeHeaderRow.Iserial, 0, postPostOrNo);
                        routeHeaderRow.AxRouteCardFabricsJournalId = retval.ToString();

                        ClearAxTable(tableName, axapta);

                        entities.SaveChanges();
                        axapta.Logoff();
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Esempio n. 32
0
        private void PickingListForAxServicesAcc(TblDyeingOrdersHeaderAcc objToPost, TblDyeingOrdersMainDetailsACC headerObjToPost,
                                                 int postPostOrNo, int userIserial, string transactionGuid)
        {
            using (var entities = new WorkFlowManagerDBEntities())
            {
                var          axapta = new Axapta();
                AxaptaRecord AxaptaRecord;
                var          credential = new NetworkCredential("bcproxy", "around1");
                var          tableName  = "PRODCONNECTION";
                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);

                var vendorWmsLocation = entities.GetWmsLocations.SingleOrDefault(x => x.VENDID == objToPost.Vendor);

                var vendorLoc =
                    entities.GetLocations.SingleOrDefault(x => x.INVENTLOCATIONID == vendorWmsLocation.INVENTLOCATIONID);

                try
                {
                    foreach (var item in headerObjToPost.TblDyeingOrdersDetailsAccs)
                    {
                        foreach (var service in item.DyeingOrderDetailsServicesAccs)
                        {
                            AxaptaRecord = axapta.CreateAxaptaRecord(tableName);
                            AxaptaRecord.Clear();
                            AxaptaRecord.InitValue();
                            AxaptaRecord.set_Field("TRANSID", item.DyeingProductionOrder);
                            AxaptaRecord.set_Field("RAWID", service.ServiceCode);
                            AxaptaRecord.set_Field("DYEDITEM", service.ServiceCode);
                            AxaptaRecord.set_Field("RAWQTY", item.CalculatedTotalQty);
                            AxaptaRecord.set_Field("DYEDQTY", item.CalculatedTotalQty);
                            //AxaptaRecord.set_Field("UNITID", item.Unit);
                            AxaptaRecord.set_Field("FROMSITE", vendorLoc.INVENTSITEID);
                            AxaptaRecord.set_Field("TOSITE", vendorLoc.INVENTSITEID);
                            AxaptaRecord.set_Field("FROMLOCATION", vendorWmsLocation.WMSLOCATIONID);
                            AxaptaRecord.set_Field("TOLOCATION", vendorWmsLocation.WMSLOCATIONID);
                            AxaptaRecord.set_Field("TRANSTYPE", Convert.ToInt64(2));
                            AxaptaRecord.set_Field("FROMCONFIG", item.Color);
                            AxaptaRecord.set_Field("TOCONFIG", item.Color);
                            // AxaptaRecord.set_Field("FROMBATCH", item.BatchNo.ToString());
                            //AxaptaRecord.set_Field("TOBATCH", item.BatchNo.ToString());
                            AxaptaRecord.set_Field("FROMWAREHOUSE", vendorWmsLocation.INVENTLOCATIONID);
                            AxaptaRecord.set_Field("TOWAREHOUSE", vendorWmsLocation.INVENTLOCATIONID);
                            AxaptaRecord.set_Field("JOURNALLINKID", headerObjToPost.TransId);
                            AxaptaRecord.set_Field("TransactionGuid", transactionGuid);
                            AxaptaRecord.Insert();
                        }
                    }
                    //public ProdJournalId run(int transId,int journalId,int WhatToDo,str JourName,int PostorNo)
                    var import      = axapta.CreateAxaptaObject("CLEDyeProcesse");
                    var PickingList = import.Call("run", headerObjToPost.DyeingProductionOrder, headerObjToPost.TransId, 2, "Name", postPostOrNo);

                    axapta.Logoff();
                }

                catch (Exception)
                {
                    axapta.Logoff();
                    throw;
                }
            }
        }
Esempio n. 33
0
        public void PurchaseRouteServicesToAx(RouteCardHeader headerObjToPost, int postPostOrNo)
        {
            using (var context = new WorkFlowManagerDBEntities())
            {
                var detailsObjToPost = context.RouteCardFabrics.Where(x => x.RouteCardHeaderIserial == headerObjToPost.Iserial);

                using (var axapta = new Axapta())
                {
                    var credential = new NetworkCredential("bcproxy", "around1");

                    axapta.LogonAs("osama.gamal", "ccasual.loc", credential, "ccm", null, null, null);

                    var inventTable = axapta.CreateAxaptaRecord("InventDim");
                    try
                    {
                        var purchId          = "Rc_ " + headerObjToPost.Iserial.ToString();
                        var tableName        = "PurchTable";
                        var purchTableRecord = axapta.CreateAxaptaRecord(tableName);
                        purchTableRecord.Clear();
                        purchTableRecord.InitValue();

                        purchTableRecord.set_Field("PurchId", purchId);
                        purchTableRecord.set_Field("DeliveryDate", headerObjToPost.DeliveryDate);
                        //   axaptaRecord.set_Field("PurchId", _PurchID);

                        var header = axapta.CallStaticRecordMethod("VendTable", "find", headerObjToPost.Vendor) as AxaptaRecord;
                        purchTableRecord.Call("initFromVendTable", header);

                        purchTableRecord.Insert();

                        tableName = "PurchLine";
                        foreach (var item in detailsObjToPost)
                        {
                            var axaptaRecord = axapta.CreateAxaptaRecord(tableName);
                            axaptaRecord.Clear();
                            axaptaRecord.InitValue();

                            inventTable.Clear();
                            inventTable.set_Field("InventLocationId", item.Warehouse);
                            if (item.FabricColor != null)
                            {
                                inventTable.set_Field("InventColorId", item.FabricColor);
                            }
                            if (item.Size != null)
                            {
                                inventTable.set_Field("InventSizeId", item.Size);
                            }

                            var importNew        = axapta.CreateAxaptaObject("CreateProductionJournals");
                            var producationOrder = importNew.Call("GetProdIdFromSalesorderAndColor", item.Style, item.StyleColor, item.SalesOrder);

                            if (producationOrder == null || (string)producationOrder == "")
                            {
                                producationOrder = "Free";
                            }

                            var config = importNew.Call("CreateConfig", item.ItemId, "Free");
                            var batch  = importNew.Call("CreateBatch", item.ItemId, producationOrder);
                            inventTable.set_Field("configId", "Free");
                            inventTable.set_Field("inventBatchId", producationOrder);
                            inventTable = axapta.CallStaticRecordMethod("InventDim", "findOrCreate", inventTable) as AxaptaRecord;

                            if (inventTable != null)
                            {
                                var tempx = inventTable.get_Field("inventDimId").ToString();
                                axaptaRecord.set_Field("InventDimId", tempx);
                            }

                            axaptaRecord.set_Field("ItemId", item.ItemId);
                            axaptaRecord.set_Field("ItemId", item.ItemId);
                            axaptaRecord.set_Field("purchId", purchId);
                            axaptaRecord.set_Field("QtyOrdered", Convert.ToDecimal(item.Qty.ToString()));
                            //  axaptaRecord.set_Field("PurchPrice", item.Qty);
                            axaptaRecord.set_Field("PurchQty", Convert.ToDecimal(item.Qty.ToString()));
                            axaptaRecord.set_Field("LineAmount", Convert.ToDecimal(item.Qty.ToString()));
                            axaptaRecord.Call("createLine", true, true, true, true, true, true);
                        }
                        //No errors occured, Commit!
                        //Axapta.TTSCommit();

                        if (postPostOrNo == 1)
                        {
                            var importNew = axapta.CreateAxaptaObject("CreateProductionJournals");
                            importNew.Call("PostPurchaseOrder", purchId, headerObjToPost.DocDate);
                        }
                    }

                    catch (Exception ex)
                    {
                        //There was some errors, Abort transaction and Raise error!
                        //Axapta.TTSAbort();
                        throw new Exception(ex.Message);
                    }
                    finally
                    {
                        //Finally logoff the Axapta Session
                        axapta.Logoff();
                    }
                }
            }
        }