示例#1
0
        protected void popCustomerEdit_WindowCallback(object source, DevExpress.Web.ASPxPopupControl.PopupWindowCallbackArgs e)
        {
            string[] args = e.Parameter.Split('|');
            switch (args[0])
            {
            case "new":
                CustomerOrg tempCustomerOrg = CustomerOrg.InitNewRow(session);
                PrivateSession.Instance.CustomerOrgId = tempCustomerOrg.OrganizationId;
                dsCustomer.CriteriaParameters["CustomerOrgId"].DefaultValue = PrivateSession.Instance.CustomerOrgId.ToString();
                ClearForm();
                initLbCustomerTypeForAdding();

                #region customer

                session.BeginTransaction();
                try
                {
                    ObjectType objectType_cus =
                        ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.CUSTOMER);

                    NAS.BO.CMS.ObjectDocument.ObjectBO objectBO_cus  = new NAS.BO.CMS.ObjectDocument.ObjectBO();
                    NAS.DAL.CMS.ObjectDocument.Object  cmsObject_cus =
                        objectBO_cus.CreateCMSObject(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.CUSTOMER);

                    // OrganizationObject
                    OrganizationObject organizatoinObject_cus = new OrganizationObject(session)
                    {
                        ObjectId       = cmsObject_cus,
                        OrganizationId = tempCustomerOrg
                    };
                    organizatoinObject_cus.Save();

                    // OrganizationCustomType
                    OrganizationCustomType organizationCustomType_cus = new OrganizationCustomType(session)
                    {
                        ObjectTypeId   = objectType_cus,
                        OrganizationId = tempCustomerOrg
                    };
                    organizationCustomType_cus.Save();
                    session.CommitTransaction();
                }
                catch (Exception)
                {
                    session.RollbackTransaction();
                    throw;
                }


                if (lbCustomerType.Items[0].Selected == true)
                {
                    xCallbackPanel_customer.Visible = true;

                    ObjectType objectType_cus1 =
                        ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.CUSTOMER);
                    OrganizationObject organizationObject_sup = tempCustomerOrg.OrganizationObjects
                                                                .Where(r => r.ObjectId.ObjectTypeId == objectType_cus1).FirstOrDefault();
                    grid_customer.CMSObjectId = organizationObject_sup.ObjectId.ObjectId;
                    grid_customer.DataBind();
                    //grid_customer.CMSObjectId = cmsObject_cus.ObjectId;
                    //grid_customer.DataBind();
                }
                else
                {
                    xCallbackPanel_customer.Visible = false;
                }

                #endregion

                #region supplier

                session.BeginTransaction();
                try
                {
                    ObjectType objectType_sup =
                        ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.SUPPLIER);

                    NAS.BO.CMS.ObjectDocument.ObjectBO objectBO_sup  = new NAS.BO.CMS.ObjectDocument.ObjectBO();
                    NAS.DAL.CMS.ObjectDocument.Object  cmsObject_sup =
                        objectBO_sup.CreateCMSObject(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.SUPPLIER);

                    // OrganizationObject
                    OrganizationObject organizatoinObject_sup = new OrganizationObject(session)
                    {
                        ObjectId       = cmsObject_sup,
                        OrganizationId = tempCustomerOrg
                    };
                    organizatoinObject_sup.Save();

                    // OrganizationCustomType
                    OrganizationCustomType organizationCustomType_sup = new OrganizationCustomType(session)
                    {
                        ObjectTypeId   = objectType_sup,
                        OrganizationId = tempCustomerOrg
                    };
                    organizationCustomType_sup.Save();
                    session.CommitTransaction();
                }
                catch (Exception)
                {
                    session.RollbackTransaction();
                    throw;
                }


                if (lbCustomerType.Items[1].Selected == true)
                {
                    xCallbackPanel_supplier.Visible = true;

                    ObjectType objectType_sup1 =
                        ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.SUPPLIER);
                    OrganizationObject organizationObject_sup = tempCustomerOrg.OrganizationObjects
                                                                .Where(r => r.ObjectId.ObjectTypeId == objectType_sup1).FirstOrDefault();
                    grid_supplier.CMSObjectId = organizationObject_sup.ObjectId.ObjectId;
                    grid_supplier.DataBind();
                    //grid_supplier.CMSObjectId = cmsObject_sup.ObjectId;
                    //grid_supplier.DataBind();
                }
                else
                {
                    xCallbackPanel_supplier.Visible = false;
                }
                #endregion

                break;

            case "edit":
                ClearForm();
                if (args.Length > 1)
                {
                    PrivateSession.Instance.CustomerOrgId = Guid.Parse(args[1]);
                    dsCustomer.CriteriaParameters["CustomerOrgId"].DefaultValue = PrivateSession.Instance.CustomerOrgId.ToString();
                    txtCode.Text = CurrentCustomerOrg.Code;
                    loadLbCustomerType();

                    if (CurrentCustomerOrg.OrganizationObjects.FirstOrDefault() == null)
                    {
                        #region customer
                        session.BeginTransaction();
                        try
                        {
                            ObjectType objectType_cus1 =
                                ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.CUSTOMER);

                            NAS.BO.CMS.ObjectDocument.ObjectBO objectBO_cus1  = new NAS.BO.CMS.ObjectDocument.ObjectBO();
                            NAS.DAL.CMS.ObjectDocument.Object  cmsObject_cus1 =
                                objectBO_cus1.CreateCMSObject(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.CUSTOMER);

                            // OrganizationObject
                            OrganizationObject organizatoinObject_cus1 = new OrganizationObject(session)
                            {
                                ObjectId       = cmsObject_cus1,
                                OrganizationId = CurrentCustomerOrg
                            };
                            organizatoinObject_cus1.Save();

                            // OrganizationCustomType
                            OrganizationCustomType organizationCustomType_cus1 = new OrganizationCustomType(session)
                            {
                                ObjectTypeId   = objectType_cus1,
                                OrganizationId = CurrentCustomerOrg
                            };
                            organizationCustomType_cus1.Save();
                            session.CommitTransaction();
                        }
                        catch (Exception)
                        {
                            session.RollbackTransaction();
                            throw;
                        }


                        if (lbCustomerType.Items[0].Selected == true)
                        {
                            xCallbackPanel_customer.Visible = true;

                            ObjectType objectType_cus1 =
                                ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.CUSTOMER);
                            OrganizationObject organizationObject_sup = CurrentCustomerOrg.OrganizationObjects
                                                                        .Where(r => r.ObjectId.ObjectTypeId == objectType_cus1).FirstOrDefault();
                            grid_customer.CMSObjectId = organizationObject_sup.ObjectId.ObjectId;
                            grid_customer.DataBind();
                            //grid_customer.CMSObjectId = cmsObject_cus1.ObjectId;
                            //grid_customer.DataBind();
                        }
                        else
                        {
                            xCallbackPanel_customer.Visible = false;
                        }
                        #endregion

                        #region supplier

                        session.BeginTransaction();
                        try
                        {
                            ObjectType objectType_sup1 =
                                ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.SUPPLIER);

                            NAS.BO.CMS.ObjectDocument.ObjectBO objectBO_sup1  = new NAS.BO.CMS.ObjectDocument.ObjectBO();
                            NAS.DAL.CMS.ObjectDocument.Object  cmsObject_sup1 =
                                objectBO_sup1.CreateCMSObject(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.SUPPLIER);

                            // OrganizationObject
                            OrganizationObject organizatoinObject_sup1 = new OrganizationObject(session)
                            {
                                ObjectId       = cmsObject_sup1,
                                OrganizationId = CurrentCustomerOrg
                            };
                            organizatoinObject_sup1.Save();

                            // OrganizationCustomType
                            OrganizationCustomType organizationCustomType_sup1 = new OrganizationCustomType(session)
                            {
                                ObjectTypeId   = objectType_sup1,
                                OrganizationId = CurrentCustomerOrg
                            };
                            organizationCustomType_sup1.Save();
                            session.CommitTransaction();
                        }
                        catch (Exception)
                        {
                            session.RollbackTransaction();
                            throw;
                        }


                        if (lbCustomerType.Items[1].Selected == true)
                        {
                            xCallbackPanel_supplier.Visible = true;

                            ObjectType objectType_sup1 =
                                ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.SUPPLIER);
                            OrganizationObject organizationObject_sup = CurrentCustomerOrg.OrganizationObjects
                                                                        .Where(r => r.ObjectId.ObjectTypeId == objectType_sup1).FirstOrDefault();
                            grid_supplier.CMSObjectId = organizationObject_sup.ObjectId.ObjectId;
                            grid_supplier.DataBind();
                            //grid_supplier.CMSObjectId = cmsObject_sup1.ObjectId;
                            //grid_supplier.DataBind();
                        }
                        else
                        {
                            xCallbackPanel_supplier.Visible = false;
                        }
                        #endregion
                    }

                    else
                    {
                        #region load customer data
                        if (lbCustomerType.Items[0].Selected == true)
                        {
                            xCallbackPanel_customer.Visible = true;
                            ObjectType objectType_cus1 =
                                ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.CUSTOMER);
                            OrganizationObject organizationObject_sup = CurrentCustomerOrg.OrganizationObjects
                                                                        .Where(r => r.ObjectId.ObjectTypeId == objectType_cus1).FirstOrDefault();
                            grid_customer.CMSObjectId = organizationObject_sup.ObjectId.ObjectId;
                            grid_customer.DataBind();
                        }
                        else
                        {
                            xCallbackPanel_customer.Visible = false;
                        }
                        #endregion

                        #region load supplier data
                        if (lbCustomerType.Items[1].Selected == true)
                        {
                            xCallbackPanel_supplier.Visible = true;
                            ObjectType objectType_sup1 =
                                ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.SUPPLIER);
                            OrganizationObject organizationObject_sup = CurrentCustomerOrg.OrganizationObjects
                                                                        .Where(r => r.ObjectId.ObjectTypeId == objectType_sup1).FirstOrDefault();
                            grid_supplier.CMSObjectId = organizationObject_sup.ObjectId.ObjectId;
                            grid_supplier.DataBind();
                        }
                        else
                        {
                            xCallbackPanel_supplier.Visible = false;
                        }
                        #endregion
                    }
                }
                break;

            case "save":
                bool   isSuccess   = true;
                string recordIdStr = null;
                try
                {
                    session.BeginTransaction();
                    //Check validation
                    if (!IsSelectedLbType())
                    {
                        throw new Exception(String.Format("Phải chọn ít nhất một phân loại cho khách hàng"));
                    }

                    if (!ASPxEdit.AreEditorsValid(pagCustomer, true))
                    {
                        popCustomerEdit.JSProperties.Add("cpInvalid", true);
                        pagCustomer.ActiveTabIndex = 0;
                        return;
                    }
                    //Logic to save data
                    if (args.Length > 1)
                    {
                        //Update mode
                        //Update general information
                        recordIdStr = args[1];
                        Guid         recordId        = Guid.Parse(recordIdStr);
                        Organization editCustomerOrg =
                            session.GetObjectByKey <Organization>(PrivateSession.Instance.CustomerOrgId);
                        editCustomerOrg.Code      = txtCode.Text;
                        editCustomerOrg.Name      = txtName.Text;
                        editCustomerOrg.TaxNumber = txtTaxNumber.Text;
                        // Duc.Vo 10/09/2013 INS-START
                        editCustomerOrg.Address = txtAddress.Text;
                        // Duc.Vo 10/09/2013 INS-START
                        editCustomerOrg.RowStatus = short.Parse(cbRowStatus.SelectedItem.Value.ToString());
                        //----Duc.Vo 03/11/2013 INS -START
                        selectedObjectTypeId = new List <Guid>();
                        foreach (ListEditItem l in lbCustomerType.Items)
                        {
                            if (l.Selected)
                            {
                                selectedObjectTypeId.Add(Guid.Parse(l.Value.ToString()));
                            }
                        }

                        if (editCustomerOrg is SupplierOrg)
                        {
                            supplierBO.updateTradingCategoriesForObject <SupplierOrg>(session, recordId, selectedObjectTypeId);
                        }
                        else
                        {
                            supplierBO.updateTradingCategoriesForObject <CustomerOrg>(session, recordId, selectedObjectTypeId);
                        }
                        //----Duc.Vo 03/11/2013 INS -END

                        editCustomerOrg.Save();
                        session.CommitTransaction();
                    }
                    else
                    {
                        //Insert mode
                        CustomerOrg newCustomerOrg =
                            session.GetObjectByKey <CustomerOrg>(PrivateSession.Instance.CustomerOrgId);
                        newCustomerOrg.Code      = txtCode.Text;
                        newCustomerOrg.Name      = txtName.Text;
                        newCustomerOrg.TaxNumber = txtTaxNumber.Text;
                        // Duc.Vo 10/09/2013 INS-START
                        newCustomerOrg.Address = txtAddress.Text;
                        // Duc.Vo 10/09/2013 INS-START
                        newCustomerOrg.RowStatus = short.Parse(cbRowStatus.SelectedItem.Value.ToString());
                        newCustomerOrg.Save();
                        //----Duc.Vo 03/11/2013 INS -START
                        selectedObjectTypeId = new List <Guid>();
                        foreach (ListEditItem l in lbCustomerType.Items)
                        {
                            if (l.Selected)
                            {
                                selectedObjectTypeId.Add(Guid.Parse(l.Value.ToString()));
                            }
                        }
                        supplierBO.updateTradingCategoriesForObject <CustomerOrg>(session, newCustomerOrg.OrganizationId, selectedObjectTypeId);
                        //----Duc.Vo 03/11/2013 INS -END
                        session.CommitTransaction();
                    }
                }
                catch (Exception ex)
                {
                    session.RollbackTransaction();
                    isSuccess = false;
                    throw;
                }
                finally
                {
                    popCustomerEdit.JSProperties.Add("cpCallbackArgs",
                                                     String.Format("{{ \"recordId\": \"{0}\", \"isSuccess\": {1} }}", recordIdStr, isSuccess.ToString().ToLower()));
                }
                break;

            default:
                break;
            }
        }
示例#2
0
文件: Util.cs 项目: ewin66/dev
        /// <summary>
        /// Populate default data to database
        /// </summary>
        public static void Populate()
        {
            try
            {
                ////NAS.DAL.Accounting.AccountChart
                NAS.DAL.BI.Accounting.Account.CorrespondFinancialAccountDim.Populate();
                NAS.DAL.BI.Accounting.Account.FinancialAccountDim.Populate();
                Account.Populate();
                AccountType.Populate();
                AccountCategory.Populate();
                Currency.Populate();

                ////NAS.DAL.Accounting.Configure
                AllocationType.Populate();

                ////NAS.DAL.CMS.ObjectDocument
                ObjectType.Populate();
                CustomFieldType.Populate();
                ObjectTypeCustomField.Populate();

                ////NAS.DAL.Inventory.Item
                RecordedType.Populate();

                ////NAS.DAL.Inventory.Operation
                CommanderStockCartStatus.Populate();
                CommanderStockCartType.Populate();

                ////NAS.DAL.Inventory.StockCart
                StockCartActorType.Populate();

                ////NAS.DAL.Invoice
                TaxType.Populate();
                PromotionType.Populate();

                ////NAS.DAL.Nomenclature.Inventory
                Nomenclature.Inventory.Inventory.Populate();
                InventoryUnit.Populate();

                ////NAS.DAL.Nomenclature.Item
                ItemUnitRelationType.Populate();
                UnitType.Populate();
                Unit.Populate();
                ItemUnit.Populate();
                ItemTradingType.Populate();
                ItemCustomType.Populate();

                ////NAS.DAL.Nomenclature.Organization
                TradingCategory.Populate();
                AuthenticationProvider.Populate();
                DepartmentType.Populate();
                OrganizationType.Populate();
                Person.Populate();
                Organization.Populate();
                OwnerOrg.Populate();
                CustomerOrg.Populate();
                SupplierOrg.Populate();
                ManufacturerOrg.Populate();
                Department.Populate();
                DepartmentPerson.Populate();

                //NAS.DAL.Staging.Accounting.Journal
                AccountActorType.Populate();

                ////NAS.DAL.Vouches
                VouchesType.Populate();
                VouchesActorType.Populate();
                ReceiptVouchesType.Populate();
                PaymentVouchesType.Populate();
                ForeignCurrency.Populate();

                ////NAS.DAL.Accounting.Journal
                AccountingPeriod.Populate();
                //SalesInvoicePickingStockCart.Populate();

                ////NAS.DAL.System.ArtifactCode
                ArtifactType.Populate();
                CodeRuleDataType.Populate();
                CodeRuleDataFormat.Populate();
                RuleRepeaterType.Populate();

                //NAS.DAL.Sales.Price
                PricePolicyType.Populate();

                //NAS.DAL.Inventory.Lot.Lot
                NAS.DAL.Inventory.Lot.Lot.Populate();

                //NAS.DAL.Inventory.Command.InventoryCommandActorType
                NAS.DAL.Inventory.Command.InventoryCommandActorType.Populate();
                NAS.DAL.BI.Inventory.InventoryCommandDim.Populate();

                #region Other populate
                using (Session session = XpoHelper.GetNewSession())
                {
                    //Insert undefined supplier
                    if (!Util.isExistXpoObject <SupplierOrg>("OrganizationId",
                                                             Guid.Parse("3DEF2B62-2162-46CD-8418-DEE6F8E59E21")))
                    {
                        SupplierOrg undefinedSupplierOrg = new SupplierOrg(session)
                        {
                            OrganizationId       = Guid.Parse("3DEF2B62-2162-46CD-8418-DEE6F8E59E21"),
                            Name                 = "Mặc định",
                            Description          = "Mặc định",
                            Code                 = "MACDINH",
                            RowCreationTimeStamp = DateTime.Now,
                            RowStatus            = Constant.ROWSTATUS_ACTIVE,
                            OrganizationTypeId   =
                                NAS.DAL.Util.getDefaultXpoObject <OrganizationType>(session)
                        };
                        undefinedSupplierOrg.Save();
                    }
                }
                #endregion
            }
            catch (Exception)
            {
                throw new Exception("Populate failed");
            }
            finally
            {
            }
        }