Beispiel #1
0
        public void AddNewMainRow(GenericTable row)
        {
            var newRow = new TblApprovalViewModel
            {
                UserPerRow =
                {
                    Iserial  = LoggedUserInfo.Iserial,
                    AxId     = LoggedUserInfo.AxId,
                    UserName = LoggedUserInfo.WFM_UserName
                },
                TblAuthUser    = LoggedUserInfo.Iserial,
                TblSalesOrder  = Salesorder,
                ApprovalDate   = DateTime.Now,
                ApprovalType   = row.Iserial,
                ApprovalPerRow = row
            };

            MainRowList.Add(newRow);
        }
Beispiel #2
0
        public ApprovalViewModel(StyleHeaderViewModel styleViewModel)
        {
            TempStyleViewModel = styleViewModel;
            Perm = 301;
            if (!DesignerProperties.IsInDesignTool)
            {
                User = LoggedUserInfo.Iserial;

                Salesorder = styleViewModel.SelectedDetailRow.Iserial;

                var approvalTypeService = new CRUD_ManagerServiceClient();

                approvalTypeService.GetGenericAsync("TblApprovalTypes", "%%", "%%", "%%", "Iserial", "ASC");

                approvalTypeService.GetGenericCompleted += (s, sv) =>
                {
                    var tblUserBrandSection =
                        LoggedUserInfo.UserBrandSection.FirstOrDefault(
                            x =>
                            x.BrandCode == styleViewModel.SelectedMainRow.Brand &&
                            x.TblLkpBrandSection == styleViewModel.SelectedMainRow.TblLkpBrandSection);

                    switch (styleViewModel.SelectedDetailRow.SalesOrderType)
                    {
                    case (int)SalesOrderType.SalesOrderPo:

                        Perm = 303;
                        break;
                    }

                    if (tblUserBrandSection != null)
                    {
                        ApprovalTypesList = sv.Result;
                        var userPerm =
                            tblUserBrandSection.TblUserBrandSectionPermissions.SingleOrDefault(
                                x => x.TblAuthPermission == Perm);

                        if (userPerm != null)
                        {
                            if (!userPerm.Retail)
                            {
                                var tempRow = sv.Result.SingleOrDefault(x => x.Code == "Retail");
                                ApprovalTypesList.Remove(tempRow);
                            }
                            if (!userPerm.Financial)
                            {
                                var tempRow = sv.Result.SingleOrDefault(x => x.Code == "Financial");
                                ApprovalTypesList.Remove(tempRow);
                            }
                            if (!userPerm.Technical)
                            {
                                var tempRow = sv.Result.SingleOrDefault(x => x.Code == "Technical");
                                ApprovalTypesList.Remove(tempRow);
                            }
                        }
                        else
                        {
                            ApprovalTypesList.Clear();
                        }
                    }

                    if (ApprovalTypesList != null && ApprovalTypesList.Count > 0)
                    {
                        GetMaindata();
                    }
                };

                MainRowList     = new ObservableCollection <TblApprovalViewModel>();
                SelectedMainRow = new TblApprovalViewModel();

                Client.GetTblApprovalCompleted += (s, sv) =>
                {
                    if (sv.Error != null)
                    {
                        MessageBox.Show(sv.Error.Message);
                    }

                    foreach (var row in sv.Result)
                    {
                        var newrow = new TblApprovalViewModel();
                        newrow.InjectFrom(row);
                        newrow.ApprovalPerRow.InjectFrom(row.TblApprovalType);
                        newrow.UserPerRow = row.TblAuthUser1;
                        MainRowList.Add(newrow);
                    }

                    foreach (var row in ApprovalTypesList)
                    {
                        if (row.Iserial == 1 && !styleViewModel.SelectedDetailRow.IsRetailApproved ||
                            row.Iserial == 2 && !styleViewModel.SelectedDetailRow.IsFinancialApproved ||
                            row.Iserial == 3 && !styleViewModel.SelectedDetailRow.IsTechnicalApproved
                            )
                        {
                            AddNewMainRow(row);
                        }
                    }

                    Loading = false;
                };

                ProductionClient.GetTblUsersApprovalStatusAsync(LoggedUserInfo.Iserial);

                ProductionClient.GetTblUsersApprovalStatusCompleted += (s, sv) =>
                {
                    ApprovalStatusList.Clear();
                    foreach (var item in sv.Result.ToList())
                    {
                        ApprovalStatusList.Add(new GenericTable().InjectFrom(item) as GenericTable);
                    }
                };

                Client.UpdateOrInsertTblApprovalCompleted += (s, x) =>
                {
                    Salesorder.InjectFrom(x.Result.TblSalesOrder);
                    var savedRow = (TblApprovalViewModel)MainRowList.GetItemAt(x.outindex);
                    if (savedRow != null)
                    {
                        savedRow.InjectFrom(x.Result);
                    }
                    OnApproveCompleted();
                    TempStyleViewModel.Loading = false;
                    Loading = false;
                };
                Client.DeleteTblApprovalCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        throw ev.Error;
                    }

                    var oldrow = MainRowList.FirstOrDefault(x => x.Iserial == ev.Result);
                    if (oldrow != null)
                    {
                        MainRowList.Remove(oldrow);
                    }
                };
            }
        }