예제 #1
0
파일: Users.cs 프로젝트: Osama91/CCWFM
        public TblAuthUser SaveUser(TblAuthUser newRow, int index, out int outindex)
        {
            outindex = index;
            using (var context = new WorkFlowManagerDBEntities())
            {
                if (newRow.Iserial != 0)
                {
                    var oldRow = (from s in context.TblAuthUsers
                                  where s.Iserial == newRow.Iserial
                                  select s).SingleOrDefault();
                    if (oldRow != null)
                    {
                        GenericUpdate(oldRow, newRow, context);
                    }
                }

                if (newRow.Iserial == 0)
                {
                    context.TblAuthUsers.AddObject(newRow);
                }

                context.SaveChanges();
                return(newRow);
            }
        }
예제 #2
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);
        }
예제 #3
0
        public TblAuthUser SaveUser(TblAuthUser newRow, int index, out int outindex)
        {
            outindex = index;
            using (var context = new WorkFlowManagerDBEntities())
            {
                if (newRow.Iserial != 0)
                {
                    var oldRow = (from s in context.TblAuthUsers
                                  where s.Iserial == newRow.Iserial
                                  select s).SingleOrDefault();
                    if (oldRow != null)
                    {
                        SharedOperation.GenericUpdate(oldRow, newRow, context);
                    }
                }

                try
                {
                    if (newRow.Iserial == 0)
                    {
                        context.TblAuthUsers.AddObject(newRow);
                        context.SaveChanges();
                        context.TblUserExpiries.AddObject(new TblUserExpiry()
                        {
                            Tbluser        = newRow.Iserial,
                            LastChangeDate = DateTime.Now,
                            LastPass       = newRow.UserPassword
                        });
                    }

                    context.SaveChanges();
                }
                catch
                {
                    newRow.Ename = "ERROR_OCCURED";
                    newRow.Aname = "ERROR_OCCURED";
                }
                return(newRow);
            }
        }
예제 #4
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);
        }
예제 #5
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();
                    }
                }
            }
        }
예제 #6
0
        public int UpdateNewUsersRequest(NewUserRequests UserRequest)
        {
            int    Result = 0;
            string dbName = "";

            TblAuthUser LikeUser = new TblAuthUser();

            using (var context = new WorkFlowManagerDBEntities())
            {
                var currentUserRequest = context.TblAddUserRequests.FirstOrDefault
                                             (x => x.UserCreateRequestID == UserRequest.UserCreateRequestID &&
                                             x.NewUserID == UserRequest.NewUserID & x.NewUserCompanyID == UserRequest.NewUserCompanyID);

                currentUserRequest.Approved    = UserRequest.Approved;
                currentUserRequest.Rejected    = UserRequest.Rejected;
                currentUserRequest.ApproveDate = DateTime.Now;

                /*************************************Approved User*********************************/
                if (currentUserRequest.Approved == "1")
                {
                    LikeUser = context.TblAuthUsers.FirstOrDefault(x => x.PayrollCode == UserRequest.LikeUserID);

                    int _NewUserCompanyID = int.Parse(UserRequest.NewUserCompanyID);
                    dbName = context.TblCompanies.FirstOrDefault(x => x.Iserial == _NewUserCompanyID).DbName;

                    //Create New User Login

                    TblAuthUser CreateNewUser = new TblAuthUser();
                    CreateNewUser.UserName     = currentUserRequest.UserName;
                    CreateNewUser.UserPassword = currentUserRequest.UserPassword;
                    CreateNewUser.Code         = string.Format(@"{0}{1}", currentUserRequest.NewUserID, currentUserRequest.NewUserCompanyID);
                    CreateNewUser.TblCompany   = int.Parse(currentUserRequest.NewUserCompanyID);
                    CreateNewUser.PayrollCode  = currentUserRequest.NewUserID;
                    CreateNewUser.Ename        = currentUserRequest.UserName;
                    CreateNewUser.Aname        = currentUserRequest.UserName;
                    CreateNewUser.TblJob       = LikeUser.TblJob;
                    CreateNewUser.CurrLang     = LikeUser.CurrLang;
                    context.TblAuthUsers.AddObject(CreateNewUser);
                }

                context.SaveChanges();
            }

            if (UserRequest.Approved == "1" && UserRequest.IsSalesPerson == "1")
            {
                Operations.GlOperations.GlService service = new Operations.GlOperations.GlService();
                using (var newContext = new ccnewEntities(service.GetSqlConnectionString(dbName)))
                {
                    TBLSalesPerson newRow = new TBLSalesPerson();

                    int NextSerial = newContext.TBLSalesPersons.Select(x => x.ISerial).Max();
                    newRow.ISerial = NextSerial + 1;
                    newRow.Ename   = UserRequest.UserName;
                    newRow.Aname   = UserRequest.UserName;
                    newRow.Code    = UserRequest.NewUserID;
                    newContext.TBLSalesPersons.AddObject(newRow);
                    if (UserRequest.IsRetailPerson == "1")
                    {
                        TblUser newUser = new TblUser();
                        TblUser oldUser = newContext.TblUsers.FirstOrDefault(x => x.Code == UserRequest.LikeUserID);

                        try
                        {
                            int NextUserSerial = newContext.TblUsers.Select(x => x.iserial).Max();
                            newUser.iserial         = NextUserSerial + 1;
                            newUser.Ename           = UserRequest.UserName;
                            newUser.Aname           = UserRequest.UserName;
                            newUser.Code            = UserRequest.NewUserID;
                            newUser.UserPassword    = UserRequest.UserPassword;
                            newUser.TblJob          = oldUser.TblJob;
                            newUser.Active          = oldUser.Active;
                            newUser.CurrLang        = oldUser.CurrLang;
                            newUser.ReportFont      = oldUser.ReportFont;
                            newUser.ActiveCashMach  = oldUser.ActiveCashMach;
                            newUser.ActiveStore     = oldUser.ActiveStore;
                            newUser.RegNo           = oldUser.RegNo;
                            newUser.AllowedStores   = oldUser.AllowedStores;
                            newUser.AllowedStoresTo = oldUser.AllowedStoresTo;
                            newContext.TblUsers.AddObject(newUser);
                        }
                        catch { }
                    }
                    newContext.SaveChanges();
                }

                AddUserToActiveDirectory(UserRequest);
            }

            return(Result);
        }