コード例 #1
0
        public ActionResult UpdateTransfer(Transfer transfer)
        {
            try
            {
                TransferStates status = (TransferStates)Enum.ToObject(typeof(TransferStates), transfer.Status);

                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 A4URequest = (AxaptaRecord)axDB1.CallStaticRecordMethod("A4URequests", "Find", transfer.RequestId, true);
                if (transfer.ExactDateInput)
                {
                    A4URequest.set_Field("DateOffHire", transfer.DateOffHire);
                }
                else
                {
                    A4URequest.set_Field("DateExpectedOffHire", transfer.DateOffHire);
                }
                A4URequest.set_Field("Status", (int)status);
                A4URequest.Update();
                axDB1.TTSCommit();
                axDB1.Logoff();
                axDB1.Dispose();
                return(Content("true"));
            }
            catch
            {
                return(Content("false"));
            }
        }
コード例 #2
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;
            }
        }
コード例 #3
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();
                }
            }
        }
コード例 #4
0
ファイル: LeaveApp.cs プロジェクト: HosamKhalifa/ESS
        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;
            }
        }
コード例 #5
0
ファイル: LeaveApp.cs プロジェクト: HosamKhalifa/ESS
        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;
            }
        }
コード例 #6
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"));
            }
        }
コード例 #7
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);
        }
コード例 #8
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;
            }
        }
コード例 #9
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();
            }
        }
コード例 #10
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();
                }
            }
        }
コード例 #11
0
ファイル: PurchaseOrderRequest.cs プロジェクト: Osama91/CCWFM
        public void PoPlanPurchase(int PurchaseReceiveHeader, int userIserial)
        {
            using (var context = new WorkFlowManagerDBEntities())
            {
                var PurchaseOrderDetails = context.TblPurchaseReceiveDetails.Include("TblPurchaseOrderDetailRequest1").Where(w => w.TblPurchaseReceiveHeader == PurchaseReceiveHeader).ToList();

                var iserial = PurchaseOrderDetails.FirstOrDefault().TblPurchaseOrderDetailRequest1.TblPurchaseOrderHeaderRequest;

                var headerObjToPost = context.TblPurchaseOrderHeaderRequests.Include("TblWarehouse1.TblSite1").Include("TblPurchaseOrderDetailRequests.TblColor").SingleOrDefault(x => x.Iserial == iserial);
                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);
                }
                const string dataarea = "CCM";

                axapta.LogonAs(userToLogin.User_Win_Login, userToLogin.User_Domain, credential, dataarea, null, null, null);
                axapta.TTSBegin();

                try
                {
                    var tableName = "PurchTable";
                    var purchId   = "P" + "_" + headerObjToPost.Vendor + "_" + headerObjToPost.Iserial;

                    if (headerObjToPost.AxPurchase != purchId)
                    {
                        var inventDim    = axapta.CreateAxaptaRecord("InventDim");
                        var axaptaRecord = axapta.CreateAxaptaRecord(tableName);
                        axaptaRecord.Clear();
                        axaptaRecord.InitValue();
                        axaptaRecord.set_Field("PurchId", purchId);
                        if (headerObjToPost.DeliveryDate != null)
                        {
                            axaptaRecord.set_Field("DeliveryDate", headerObjToPost.DeliveryDate);
                        }

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

                        axaptaRecord.Insert();
                    }

                    tableName = "PurchLine";
                    foreach (var item in PurchaseOrderDetails)
                    {
                        PurchaseFabricLinesToAx(headerObjToPost, item, purchId, userIserial, axapta);
                    }
                    axapta.TTSCommit();
                    headerObjToPost.AxPurchase = purchId;
                    context.SaveChanges();

                    //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();
                }
            }
        }
コード例 #12
0
ファイル: Service.cs プロジェクト: Osama91/CCWFM
        public void InsertServiceItem(TblService objToPost, int userIserial)
        {
            var axapta = new Axapta();//Ready To be Dependent from Ax

            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.Code;
                    var tableName = "InventTable";

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

                    axaptaRecord.set_Field("ItemGroupId", objToPost.ServiceGroup);

                    axaptaRecord.set_Field("ItemId", itemId);
                    axaptaRecord.set_Field("ItemName", objToPost.Ename);
                    axaptaRecord.set_Field("ModelGroupID", "Service");
                    axaptaRecord.set_Field("ItemType", 0);
                    axaptaRecord.set_Field("DimGroupId", "Service");
                    //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);

                    axaptaRecord.set_Field("UnitId", "KG");
                    //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);
                    axaptaRecord.set_Field("UnitId", "KG");

                    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);
                    axaptaRecord.set_Field("UnitId", "KG");
                    axaptaRecord.set_Field("UnitId", "KG");

                    axaptaRecord.Insert();

                    tableName = "InventItemLocation";

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

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

                    // Commit the record to the database.
                    axapta.TTSCommit();
                }
            }
            catch (Exception ex)
            {
                axapta.TTSAbort();
                throw ex;
            }
        }