Exemple #1
0
 protected void Page_Init(object sender, EventArgs e)
 {
     session = XpoHelper.GetNewSession();
     ResourceXDS.Criteria = "AppId = ?  And RowStatus >= ?";
     ResourceXDS.Session  = session;
 }
Exemple #2
0
        protected void customFieldDataGridView_DataUpdated(object sender,
                                                           ERPSystem.CustomField.GUI.Control.CustomFieldControlEventArgs args)
        {
            using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
            {
                //Get all journal of transaction
                Transaction transaction = uow.GetObjectByKey <Transaction>(TransactionId);
                var         cmsObjects  =
                    transaction.GeneralJournals
                    .Where(r => r.RowStatus >= 0)
                    .Select(r => r.GeneralJournalObjects.FirstOrDefault())
                    .Select(r => r.ObjectId);

                ObjectTypeCustomField objectTypeCustomField =
                    uow.GetObjectByKey <ObjectTypeCustomField>(args.ObjectTypeCustomFieldId);

                if (cmsObjects != null)
                {
                    ObjectCustomFieldBO objectCustomFieldBO = new ObjectCustomFieldBO();
                    foreach (var cmsObject in cmsObjects)
                    {
                        ObjectCustomField objectCustomField =
                            cmsObject.ObjectCustomFields
                            .Where(r => r.ObjectTypeCustomFieldId == objectTypeCustomField)
                            .FirstOrDefault();
                        if (objectCustomField != null)
                        {
                            //Copy new data to all jounal of the transaction
                            switch (args.CustomFieldCategory)
                            {
                            case CustomFieldControlEventArgs.CustomFieldCategoryEnum.BASIC:
                                objectCustomFieldBO.UpdateBasicData(
                                    objectCustomField.ObjectCustomFieldId,
                                    args.NewBasicDataValue,
                                    args.BasicCustomFieldType);
                                break;

                            case CustomFieldControlEventArgs.CustomFieldCategoryEnum.LIST:
                                objectCustomFieldBO.UpdateUserDefinedListData(
                                    objectCustomField.ObjectCustomFieldId,
                                    args.NewCustomFieldDataIds);
                                break;

                            case CustomFieldControlEventArgs.CustomFieldCategoryEnum.BUILT_IN:
                                NASCustomFieldPredefinitionData temp = args.NewBuiltInData.FirstOrDefault();
                                if (temp != null)
                                {
                                    PredefinitionCustomFieldTypeEnum predefinitionType =
                                        (PredefinitionCustomFieldTypeEnum)Enum
                                        .Parse(typeof(PredefinitionCustomFieldTypeEnum), temp.PredefinitionType);
                                    objectCustomFieldBO.UpdatePredefinitionData(
                                        objectCustomField.ObjectCustomFieldId,
                                        args.NewBuiltInData.Select(r => r.RefId).ToList(),
                                        predefinitionType);
                                }
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     session = XpoHelper.GetNewSession();
     UnitEdittingXDS.Session = session;
 }
Exemple #4
0
 protected void Page_Init(object sender, EventArgs e)
 {
     session            = XpoHelper.GetNewSession();
     dsCustomer.Session = session;
     ObjectCustomerTypeLbXDS.Session = session;
 }
 protected void Page_Init(object sender, EventArgs e)
 {
     session = XpoHelper.GetNewSession();
     dsReceiptVoucher.Session = session;
 }
        protected void gridviewGeneralJournal_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
        {
            ASPxGridView grid = sender as ASPxGridView;
            UnitOfWork   uow  = null;

            try
            {
                uow = XpoHelper.GetNewUnitOfWork();
                GeneralJournalBO generalJournalBO = new GeneralJournalBO();
                ObjectBO         objectBO         = new ObjectBO();

                double amount = 0;
                string description;
                Side   side;

                Guid transactionId = (Guid)grid.GetMasterRowKeyValue();
                Guid accountId     = (Guid)e.NewValues["AccountId!Key"];
                description = (string)e.NewValues["Description"];

                if (e.NewValues["Debit"] != null && (double)e.NewValues["Debit"] > 0)
                {
                    amount = (double)e.NewValues["Debit"];
                    side   = Side.DEBIT;
                }
                else if (e.NewValues["Credit"] != null && (double)e.NewValues["Credit"] > 0)
                {
                    amount = (double)e.NewValues["Credit"];
                    side   = Side.CREDIT;
                }
                else
                {
                    throw new Exception("Invaild parameter");
                }

                GeneralJournal generalJournal = Strategy.CreateGeneralJournal(
                    uow,
                    transactionId,
                    accountId,
                    side,
                    amount,
                    description,
                    JounalTypeFlag.ACTUAL);

                uow.FlushChanges();

                //Copy readonly data from transaction to journal
                //Get transaction object
                NAS.DAL.CMS.ObjectDocument.Object transactionCMSObject
                    = uow.GetObjectByKey <Transaction>(transactionId).TransactionObjects.First().ObjectId;
                //Get general journal object
                NAS.DAL.CMS.ObjectDocument.Object generalJournalCMSObject =
                    generalJournal.GeneralJournalObjects.First().ObjectId;

                objectBO.CopyReadOnlyCustomFieldData(
                    transactionCMSObject.ObjectId,
                    generalJournalCMSObject.ObjectId);

                uow.CommitChanges();

                grid.JSProperties["cpEvent"] = "GeneralJournalChanged";
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                e.Cancel = true;
                grid.CancelEdit();
                if (uow != null)
                {
                    uow.Dispose();
                }
            }
        }
Exemple #7
0
        public static void Populate()
        {
            Session session = null;

            try
            {
                session = XpoHelper.GetNewSession();

                //Product
                Guid objectType_Product = Guid.Parse("5817B239-E150-4C8E-A313-EAA8BD6944C4");
                if (!Util.isExistXpoObject <ItemCustomType>("ObjectTypeId", objectType_Product))
                {
                    ItemCustomType itemCustomTypeBO = new ItemCustomType(session)
                    {
                        ObjectTypeId = session.GetObjectByKey <ObjectType>(objectType_Product)
                    };
                    itemCustomTypeBO.Save();
                }

                //Service
                Guid objectType_Service = Guid.Parse("BEBAB7E7-8294-4EB0-81DF-B5E33ACBFE76");
                if (!Util.isExistXpoObject <ItemCustomType>("ObjectTypeId", objectType_Service))
                {
                    ItemCustomType itemCustomTypeBO = new ItemCustomType(session)
                    {
                        ObjectTypeId = session.GetObjectByKey <ObjectType>(objectType_Service)
                    };
                    itemCustomTypeBO.Save();
                }

                //Service
                Guid objectType_Material = Guid.Parse("7C32F816-23D1-4B67-97F5-940461E06305");
                if (!Util.isExistXpoObject <ItemCustomType>("ObjectTypeId", objectType_Material))
                {
                    ItemCustomType itemCustomTypeBO = new ItemCustomType(session)
                    {
                        ObjectTypeId = session.GetObjectByKey <ObjectType>(objectType_Material)
                    };
                    itemCustomTypeBO.Save();
                }

                //Tool
                Guid objectType_Tool = Guid.Parse("F34C4E28-04C5-492E-AEE2-09416914F950");
                if (!Util.isExistXpoObject <ItemCustomType>("ObjectTypeId", objectType_Tool))
                {
                    ItemCustomType itemCustomTypeBO = new ItemCustomType(session)
                    {
                        ObjectTypeId = session.GetObjectByKey <ObjectType>(objectType_Tool)
                    };
                    itemCustomTypeBO.Save();
                }
            }
            catch (Exception)
            {
                session.RollbackTransaction();
                throw;
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
Exemple #8
0
        public static void Populate()
        {
            Session session = null;

            try
            {
                session = XpoHelper.GetNewSession();
                //insert default data into RecordedType table
                if (!Util.isExistXpoObject <RecordedType>("Name", Utility.Constant.NAAN_DEFAULT_NAME))
                {
                    RecordedType recordedType = new RecordedType(session)
                    {
                        Name                 = Utility.Constant.NAAN_DEFAULT_NAME,
                        Description          = "",
                        RowStatus            = -1,
                        RowCreationTimeStamp = DateTime.Now
                    };
                    recordedType.Save();
                }
                //insert INITIAL_INVENTORY record type
                if (!Util.isExistXpoObject <RecordedType>("Name", "INITIAL_INVENTORY"))
                {
                    RecordedType recordedType = new RecordedType(session)
                    {
                        Name                 = "INITIAL_INVENTORY",
                        Description          = "Nhập số dư tồn kho đầu kỳ",
                        RowStatus            = 1,
                        RowCreationTimeStamp = DateTime.Now
                    };
                    recordedType.Save();
                }

                //insert PUTTING_INVENTORY record type
                if (!Util.isExistXpoObject <RecordedType>("Name", "PUTTING_INVENTORY"))
                {
                    RecordedType recordedType = new RecordedType(session)
                    {
                        Name                 = "PUTTING_INVENTORY",
                        Description          = "Nhập kho",
                        RowStatus            = 1,
                        RowCreationTimeStamp = DateTime.Now
                    };
                    recordedType.Save();
                }

                //insert GETTING_INVENTORY record type
                if (!Util.isExistXpoObject <RecordedType>("Name", "GETTING_INVENTORY"))
                {
                    RecordedType recordedType = new RecordedType(session)
                    {
                        Name                 = "GETTING_INVENTORY",
                        Description          = "Xuất kho",
                        RowStatus            = 1,
                        RowCreationTimeStamp = DateTime.Now
                    };
                    recordedType.Save();
                }

                //insert ENTRY_INVENTORY record type
                if (!Util.isExistXpoObject <RecordedType>("Name", "ENTRY_INVENTORY"))
                {
                    RecordedType recordedType = new RecordedType(session)
                    {
                        Name                 = "ENTRY_INVENTORY",
                        Description          = "Bút toán",
                        RowStatus            = 1,
                        RowCreationTimeStamp = DateTime.Now
                    };
                    recordedType.Save();
                }
            }
            catch (Exception)
            {
                session.RollbackTransaction();
                throw;
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
Exemple #9
0
        public void Insert(Guid tempReceiptVouchesId,
                           string code,
                           DateTime issuedDate,
                           string description,
                           string address,
                           string payer,
                           Guid sourceOrganizationId,
                           Guid targetOrganizationId,
                           double debit,
                           Guid currencyId,
                           double exchangeRate)
        {
            UnitOfWork uow = null;

            try
            {
                uow = XpoHelper.GetNewUnitOfWork();
                //Update temp data
                ReceiptVouches newReceiptVouches =
                    uow.GetObjectByKey <ReceiptVouches>(tempReceiptVouchesId);
                newReceiptVouches.Code                 = code;
                newReceiptVouches.IssuedDate           = issuedDate;
                newReceiptVouches.Description          = description;
                newReceiptVouches.Address              = address;
                newReceiptVouches.RowStatus            = Utility.Constant.ROWSTATUS_ACTIVE;
                newReceiptVouches.SourceOrganizationId =
                    uow.GetObjectByKey <Organization>(sourceOrganizationId);
                newReceiptVouches.TargetOrganizationId =
                    uow.GetObjectByKey <Organization>(targetOrganizationId);
                newReceiptVouches.Payer          = payer;
                newReceiptVouches.CreateDate     = DateTime.Now;
                newReceiptVouches.LastUpdateDate = newReceiptVouches.CreateDate;
                newReceiptVouches.SumOfCredit    = 0;
                newReceiptVouches.SumOfDebit     = debit * exchangeRate;

                //Insert data into VoucherAmount table
                NAS.DAL.Vouches.VouchesAmount voucherAmount = new VouchesAmount(uow)
                {
                    Credit       = 0,
                    Debit        = debit,
                    ExchangeRate = exchangeRate,
                    CurrencyId   = uow.GetObjectByKey <Currency>(currencyId),
                    VouchesId    = newReceiptVouches
                };

                //2014-02-18 ERP-1540 Khoa.Truong INS START
                //Update issue date for all voucher transaction
                if (newReceiptVouches.ReceiptVouchesTransactions != null)
                {
                    foreach (var receiptVouchesTransaction in newReceiptVouches.ReceiptVouchesTransactions)
                    {
                        receiptVouchesTransaction.IssueDate = newReceiptVouches.IssuedDate;
                        receiptVouchesTransaction.Save();
                    }
                }
                //2014-02-18 ERP-1540 Khoa.Truong INS END

                uow.CommitTransaction();
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (uow != null)
                {
                    uow.Dispose();
                }
            }
        }
Exemple #10
0
 protected void Page_Init(object sender, EventArgs e)
 {
     session = XpoHelper.GetNewSession();
     try { load_data(); }
     catch { }
 }
Exemple #11
0
        public static void Populate()
        {
            Session session = null;

            try
            {
                string billActorTypeName;
                session = XpoHelper.GetNewSession();
                //Insert CREATOR bill actor type
                billActorTypeName = Enum.GetName(typeof(BillActorTypeEnum), BillActorTypeEnum.CREATOR);
                if (!Util.isExistXpoObject <BillActorType>("Name", billActorTypeName))
                {
                    BillActorType billActorType = new BillActorType(session)
                    {
                        Name        = billActorTypeName,
                        Description = "Người lập phiếu",
                        RowStatus   = Utility.Constant.ROWSTATUS_ACTIVE
                    };

                    billActorType.Save();
                }

                //Insert BUYER bill actor type
                billActorTypeName = Enum.GetName(typeof(BillActorTypeEnum), BillActorTypeEnum.BUYER);
                if (!Util.isExistXpoObject <BillActorType>("Name", billActorTypeName))
                {
                    BillActorType billActorType = new BillActorType(session)
                    {
                        Name        = billActorTypeName,
                        Description = "Người mua hàng",
                        RowStatus   = Utility.Constant.ROWSTATUS_ACTIVE
                    };

                    billActorType.Save();
                }

                //Insert SALES bill actor type
                billActorTypeName = Enum.GetName(typeof(BillActorTypeEnum), BillActorTypeEnum.SALES);
                if (!Util.isExistXpoObject <BillActorType>("Name", billActorTypeName))
                {
                    BillActorType billActorType = new BillActorType(session)
                    {
                        Name        = billActorTypeName,
                        Description = "Người bán hàng",
                        RowStatus   = Utility.Constant.ROWSTATUS_ACTIVE
                    };

                    billActorType.Save();
                }

                //Insert CHIEFACCOUNTANT bill actor type
                billActorTypeName = Enum.GetName(typeof(BillActorTypeEnum), BillActorTypeEnum.CHIEFACCOUNTANT);
                if (!Util.isExistXpoObject <BillActorType>("Name", billActorTypeName))
                {
                    BillActorType billActorType = new BillActorType(session)
                    {
                        Name        = billActorTypeName,
                        Description = "Kế toán trưởng",
                        RowStatus   = Utility.Constant.ROWSTATUS_ACTIVE
                    };

                    billActorType.Save();
                }

                //Insert DIRECTOR bill actor type
                billActorTypeName = Enum.GetName(typeof(BillActorTypeEnum), BillActorTypeEnum.DIRECTOR);
                if (!Util.isExistXpoObject <BillActorType>("Name", billActorTypeName))
                {
                    BillActorType billActorType = new BillActorType(session)
                    {
                        Name        = billActorTypeName,
                        Description = "Giám đốc",
                        RowStatus   = Utility.Constant.ROWSTATUS_ACTIVE
                    };

                    billActorType.Save();
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
Exemple #12
0
        public override void CreateTransaction(Guid voucherId, string code, DateTime issuedDate, double amount, string description)
        {
            UnitOfWork uow = null;

            try
            {
                GeneralJournalBO generalJournalBO = new GeneralJournalBO();
                uow = XpoHelper.GetNewUnitOfWork();
                //Get the origin artifact
                PaymentVouches paymnetVouches = uow.GetObjectByKey <PaymentVouches>(voucherId);

                //Create new transaction
                PaymentVouchesTransaction transaction = new PaymentVouchesTransaction(uow)
                {
                    TransactionId    = Guid.NewGuid(),
                    Amount           = amount,
                    Code             = code,
                    CreateDate       = DateTime.Now,
                    Description      = description,
                    IssueDate        = issuedDate,
                    PaymentVouchesId = paymnetVouches,
                    RowStatus        = Utility.Constant.ROWSTATUS_ACTIVE,
                    UpdateDate       = DateTime.Now
                };
                uow.FlushChanges();
                //Create double entry
                //Create debit jounal
                GeneralJournal debitGeneralJournal = generalJournalBO.CreateGeneralJournal
                                                     (
                    uow,
                    transaction.TransactionId,
                    Account.GetDefault(uow, DefaultAccountEnum.NAAN_DEFAULT).AccountId,
                    Side.DEBIT,
                    amount,
                    description,
                    JounalTypeFlag.ACTUAL
                                                     );
                //Create credit jounal
                GeneralJournal creditGeneralJournal = generalJournalBO.CreateGeneralJournal
                                                      (
                    uow,
                    transaction.TransactionId,
                    Account.GetDefault(uow, DefaultAccountEnum.NAAN_DEFAULT).AccountId,
                    Side.CREDIT,
                    amount,
                    description,
                    JounalTypeFlag.ACTUAL
                                                      );

                ObjectBO objectBO = new ObjectBO();
                //Create CMS object for transaction
                NAS.DAL.CMS.ObjectDocument.Object transactionCMSObject =
                    objectBO.CreateCMSObject(uow,
                                             DAL.CMS.ObjectDocument.ObjectTypeEnum.VOUCHER_PAYMENT);

                TransactionObject transactionObject = new TransactionObject(uow)
                {
                    ObjectId      = transactionCMSObject,
                    TransactionId = transaction
                };

                GeneralJournalObject debitGeneralJournalObject  = null;
                GeneralJournalObject creditGeneralJournalObject = null;
                //Create CMS object for debit jounal
                NAS.DAL.CMS.ObjectDocument.Object debitJounalCMSObject =
                    objectBO.CreateCMSObject(uow,
                                             DAL.CMS.ObjectDocument.ObjectTypeEnum.VOUCHER_PAYMENT);
                debitGeneralJournalObject = new GeneralJournalObject(uow)
                {
                    GeneralJournalId = debitGeneralJournal,
                    ObjectId         = debitJounalCMSObject
                };

                //Create CMS object for debit jounal
                NAS.DAL.CMS.ObjectDocument.Object creditJounalCMSObject =
                    objectBO.CreateCMSObject(uow,
                                             DAL.CMS.ObjectDocument.ObjectTypeEnum.VOUCHER_PAYMENT);
                creditGeneralJournalObject = new GeneralJournalObject(uow)
                {
                    GeneralJournalId = creditGeneralJournal,
                    ObjectId         = creditJounalCMSObject
                };

                uow.FlushChanges();

                //Copy readonly data from original artifact
                //Get origin CMS object
                VoucherObject voucherObject = paymnetVouches.VoucherObjects.FirstOrDefault();
                if (voucherObject != null)
                {
                    NAS.DAL.CMS.ObjectDocument.Object CMSVoucherObject = voucherObject.ObjectId;
                    //Copy artifact's data to cms object of transaction
                    objectBO.CopyReadOnlyCustomFieldData(
                        CMSVoucherObject.ObjectId,
                        transactionCMSObject.ObjectId);
                    //Copy artifact's data to cms object of default general journals
                    objectBO.CopyReadOnlyCustomFieldData(
                        CMSVoucherObject.ObjectId,
                        debitJounalCMSObject.ObjectId);

                    objectBO.CopyReadOnlyCustomFieldData(
                        CMSVoucherObject.ObjectId,
                        creditJounalCMSObject.ObjectId);
                }

                uow.CommitChanges();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (uow != null)
                {
                    uow.Dispose();
                }
            }
        }
 protected void Page_Init(object sender, EventArgs e)
 {
     session = XpoHelper.GetNewSession();
     DBLegalInvoiceArtifact.Session = session;
 }
Exemple #14
0
 protected virtual Session CreateSession()
 {
     return(XpoHelper.GetNewSession());
 }
 protected void Page_Init(object sender, EventArgs e)
 {
     session = XpoHelper.GetNewSession();
     dsManufacturer.Session = session;
 }
Exemple #16
0
        public void Update(Guid receiptVouchesId,
                           string code,
                           DateTime issuedDate,
                           string description,
                           string address,
                           string payer,
                           Guid sourceOrganizationId,
                           Guid targetOrganizationId,
                           double debit,
                           Guid currencyId,
                           double exchangeRate)
        {
            UnitOfWork uow = null;

            try
            {
                uow = XpoHelper.GetNewUnitOfWork();
                //Update voucher data
                ReceiptVouches receiptVouches =
                    uow.GetObjectByKey <ReceiptVouches>(receiptVouchesId);
                receiptVouches.Code                 = code;
                receiptVouches.IssuedDate           = issuedDate;
                receiptVouches.Description          = description;
                receiptVouches.Address              = address;
                receiptVouches.SourceOrganizationId =
                    uow.GetObjectByKey <Organization>(sourceOrganizationId);
                receiptVouches.TargetOrganizationId =
                    uow.GetObjectByKey <Organization>(targetOrganizationId);
                receiptVouches.Payer          = payer;
                receiptVouches.LastUpdateDate = receiptVouches.CreateDate;
                receiptVouches.SumOfCredit    = 0;
                receiptVouches.SumOfDebit     = debit * exchangeRate;

                VouchesAmount voucherAmount = receiptVouches.VouchesAmounts.FirstOrDefault();
                if (voucherAmount == null)
                {
                    throw new Exception("The receipt voucher is invalid in inserting");
                }
                //update VoucherAmount data
                voucherAmount.Credit       = 0;
                voucherAmount.Debit        = debit;
                voucherAmount.ExchangeRate = exchangeRate;
                voucherAmount.CurrencyId   = uow.GetObjectByKey <Currency>(currencyId);

                //2014-02-18 ERP-1540 Khoa.Truong INS START
                //Update issue date for all voucher transaction
                if (receiptVouches.ReceiptVouchesTransactions != null)
                {
                    foreach (var receiptVouchesTransaction in receiptVouches.ReceiptVouchesTransactions)
                    {
                        receiptVouchesTransaction.IssueDate = receiptVouches.IssuedDate;
                        receiptVouchesTransaction.Save();
                    }
                }
                //2014-02-18 ERP-1540 Khoa.Truong INS END

                uow.CommitTransaction();
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (uow != null)
                {
                    uow.Dispose();
                }
            }
        }
Exemple #17
0
        public void Populate(string dataFilePath)
        {
            string filePath = dataFilePath;
            string connStr  = Utils.GetOleConnectionString(filePath, true);

            OleDbConnection   connection     = null;
            List <UnitEntity> unitEntityList = null;
            OleDbDataReader   dr             = null;
            OleDbCommand      command        = null;

            try
            {
                connection = new OleDbConnection(connStr);
                connection.Open();

                //Populate NAAN_DEFAULT data
                Util.Populate();

                #region Unit
                //Get distinct Unit
                string productSheetName = "dmhanghoa-vattuyte";
                string materiaSheetName = "DMNguyenlieu";
                string toolSheetName    = "DMCongCuDungCu";

                unitEntityList = new List <UnitEntity>();

                //Get Unit from Unit column
                string query = String.Empty;
                query  = "select distinct [Unit] from [" + productSheetName + "$]";
                query += " union ";
                query += "select distinct [Unit] from [" + materiaSheetName + "$]";
                query += " union ";
                query += "select distinct [Unit] from [" + toolSheetName + "$]";

                command =
                    new OleDbCommand(query, connection);
                using (dr = command.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        //Collect data
                        UnitEntity unitEntity = new UnitEntity()
                        {
                            Code        = (string)Utils.ConvertToNullIfDbNull(dr["Unit"]),
                            Name        = (string)Utils.ConvertToNullIfDbNull(dr["Unit"]),
                            Description = (string)Utils.ConvertToNullIfDbNull(dr["Unit"])
                        };
                        unitEntityList.Add(unitEntity);
                    }
                }

                //Get Unit from Dvt2 column
                query  = "select distinct [Dvt2] from [" + productSheetName + "$]";
                query += " union ";
                query += "select distinct [Dvt2] from [" + materiaSheetName + "$]";
                query += " union ";
                query += "select distinct [Dvt2] from [" + toolSheetName + "$]";

                command =
                    new OleDbCommand(query, connection);
                using (dr = command.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        //Collect data
                        UnitEntity unitEntity = new UnitEntity()
                        {
                            Code        = (string)Utils.ConvertToNullIfDbNull(dr["Dvt2"]),
                            Name        = (string)Utils.ConvertToNullIfDbNull(dr["Dvt2"]),
                            Description = (string)Utils.ConvertToNullIfDbNull(dr["Dvt2"])
                        };
                        unitEntityList.Add(unitEntity);
                    }
                }

                //Get Unit from Dvt3 column
                query  = "select distinct [Dvt3] from [" + productSheetName + "$]";
                query += " union ";
                query += "select distinct [Dvt3] from [" + materiaSheetName + "$]";
                query += " union ";
                query += "select distinct [Dvt3] from [" + toolSheetName + "$]";

                command =
                    new OleDbCommand(query, connection);
                using (dr = command.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        //Collect data
                        UnitEntity unitEntity = new UnitEntity()
                        {
                            Code        = (string)Utils.ConvertToNullIfDbNull(dr["Dvt3"]),
                            Name        = (string)Utils.ConvertToNullIfDbNull(dr["Dvt3"]),
                            Description = (string)Utils.ConvertToNullIfDbNull(dr["Dvt3"])
                        };
                        unitEntityList.Add(unitEntity);
                    }
                }

                IEqualityComparer <UnitEntity> comparer = new UnitEntityComparer();

                //get distinct Unit by Code
                unitEntityList = unitEntityList.Distinct(comparer).ToList();

                using (Session session = XpoHelper.GetNewSession())
                {
                    foreach (var unitEntity in unitEntityList)
                    {
                        try
                        {
                            //Check required
                            if (unitEntity.Code == null || unitEntity.Code.Trim().Length == 0)
                            {
                                continue;
                            }

                            //Check dupplicate code
                            bool isExist =
                                NAS.DAL.Util.isExistXpoObject <NAS.DAL.Nomenclature.Item.Unit>
                                    ("Code", unitEntity.Code,
                                    Constant.ROWSTATUS_ACTIVE,
                                    Constant.ROWSTATUS_DEFAULT,
                                    Constant.ROWSTATUS_INACTIVE);
                            if (isExist)
                            {
                                continue;
                            }

                            Unit unit = new Unit(session)
                            {
                                Code                 = unitEntity.Code,
                                Description          = unitEntity.Description,
                                Name                 = unitEntity.Name,
                                RowStatus            = Constant.ROWSTATUS_ACTIVE,
                                RowCreationTimeStamp = DateTime.Now
                            };
                            unit.Save();
                        }
                        catch (Exception ex)
                        {
                            string msg = ex.Message;
                        }
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
            }
            finally
            {
                if (connection != null)
                {
                    connection.Dispose();
                }
            }
        }
        /* 2013-12-14 Khoa.Truong INS START
         * Copy from NAS.BO.CMS.ObjectDocument.ObjectCustomFieldDataMultiSelectionListBO
         */
        private bool UpdateSelecteCustomFieldAllDataItems(Guid objectCustomFieldId,
                                                          IEnumerable <Guid> list,
                                                          CustomFieldTypeFlag customFieldTypeFlag)
        {
            using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
            {
                try
                {
                    ObjectCustomField objectCustomField =
                        uow.GetObjectByKey <ObjectCustomField>(objectCustomFieldId);

                    if (objectCustomField == null)
                    {
                        throw new Exception("The key is not exist in ObjectCustomField");
                    }

                    objectCustomField.CustomFieldType = customFieldTypeFlag.Value;
                    uow.FlushChanges();

                    int cnt = objectCustomField.ObjectCustomFieldDatas.Count;
                    if (objectCustomField.ObjectCustomFieldDatas != null && cnt > 0)
                    {
                        uow.Delete(objectCustomField.ObjectCustomFieldDatas);
                        uow.FlushChanges();
                    }

                    foreach (Guid g in list)
                    {
                        AddItemToSelectedCustomFieldDataItems(uow, objectCustomFieldId, g);
                    }

                    uow.FlushChanges();

                    objectCustomField =
                        uow.GetObjectByKey <ObjectCustomField>(objectCustomFieldId);

                    string displayText = String.Empty;
                    foreach (var item in objectCustomField.ObjectCustomFieldDatas)
                    {
                        if (objectCustomField.ObjectCustomFieldDatas.IndexOf(item) == 0)
                        {
                            displayText = ((CustomFieldDataString)item.CustomFieldDataId).StringValue;
                        }
                        else
                        {
                            displayText += String.Format(";{0}",
                                                         ((CustomFieldDataString)item.CustomFieldDataId).StringValue);
                        }
                    }

                    ObjectBO objectBO = new ObjectBO();
                    DynamicObjectListSerializeDataItem dataitem = new DynamicObjectListSerializeDataItem()
                    {
                        ObjectCustomFieldId = objectCustomFieldId,
                        CustomFieldName     = objectCustomField.ObjectTypeCustomFieldId.CustomFieldId.Name,
                        CustomFieldData     = displayText
                    };
                    objectBO.SetDynamicObjectListItem(uow, objectCustomField.ObjectId.ObjectId, dataitem);

                    uow.CommitChanges();
                    return(true);
                }
                catch
                {
                    //uow.ExplicitRollbackTransaction();
                    throw;
                }
            }
        }
Exemple #19
0
 protected void Page_Init(object sender, EventArgs e)
 {
     session             = XpoHelper.GetNewSession();
     BillItemXDS.Session = session;
 }
Exemple #20
0
        public static void Populate()
        {
            Session session = null;

            try
            {
                session = XpoHelper.GetNewSession();
                //insert default data into Unit table
                if (!Util.isExistXpoObject <Unit>("Name", Utility.Constant.NAAN_DEFAULT_NAME))
                {
                    Unit unit = new Unit(session)
                    {
                        Name                 = Utility.Constant.NAAN_DEFAULT_NAME,
                        Description          = "",
                        RowStatus            = -1,
                        RowCreationTimeStamp = DateTime.Now
                    };
                    unit.Save();
                }
                //DND
                NAS.DAL.Nomenclature.Organization.Organization orgID               = session.FindObject <NAS.DAL.Nomenclature.Organization.Organization>(new BinaryOperator("Code", "QUASAPHARCO"));
                NAS.DAL.Nomenclature.UnitItem.UnitType         unitTypeID_LENGTH   = session.FindObject <NAS.DAL.Nomenclature.UnitItem.UnitType>(new BinaryOperator("Code", "LENGTH"));
                NAS.DAL.Nomenclature.UnitItem.UnitType         unitTypeID_WEIGHT   = session.FindObject <NAS.DAL.Nomenclature.UnitItem.UnitType>(new BinaryOperator("Code", "WEIGHT"));
                NAS.DAL.Nomenclature.UnitItem.UnitType         unitTypeID_CAPACITY = session.FindObject <NAS.DAL.Nomenclature.UnitItem.UnitType>(new BinaryOperator("Code", "CAPACITY"));
                NAS.DAL.Nomenclature.UnitItem.UnitType         unitTypeID_ACREAGE  = session.FindObject <NAS.DAL.Nomenclature.UnitItem.UnitType>(new BinaryOperator("Code", "AREA"));

                if (orgID == null)
                {
                    throw new Exception(@"Không có dữ liệu tổ chức QUASAPHARCO trong Database");
                }
                if (unitTypeID_ACREAGE == null)
                {
                    throw new Exception(@"không có dữ liệu ACREAGE trong Database");
                }
                if (unitTypeID_LENGTH == null)
                {
                    throw new Exception(@"Không có dữ liệu LENGTH trong Database");
                }
                if (unitTypeID_WEIGHT == null)
                {
                    throw new Exception(@"Không có dữ liệu WEIGHT trong Database");
                }
                if (unitTypeID_CAPACITY == null)
                {
                    throw new Exception(@"Không có dữ liệu CAPACITY trong Database");
                }

                string[] Lenghts       = { "mm", "cm", "dm", "m", "km" };
                string[] Weights       = { "mg", "g", "kg", "tan" };
                string[] Capacitys     = { "ml", "lit", "m³" };
                string[] AREA          = { "mm²", "cm²", "dm²", "m²" };
                string[] Name_Lenght   = { "Millimeter", "Centimeter", "Decimeter", "Meter", "Kilometer" };
                string[] Name_Weight   = { "Milligram", "Gram", "Kilogram", "Ton" };
                string[] Name_Capacity = { "Milliliter", "Liter", "Cubic Meters" };
                string[] Name_AREA     = { "Square Milliliter", "Square Centimeter", "Square Decimeter", "Square Meter" };
                int      i             = 0;

                #region ADD Lenghts
                if (unitTypeID_LENGTH != null)
                {
                    for (i = 0; i < Lenghts.Length; i++)
                    {
                        if (!Util.isExistXpoObject <Unit>("Code", Lenghts[i], Utility.Constant.ROWSTATUS_DEFAULT, Utility.Constant.ROWSTATUS_ACTIVE))
                        {
                            Unit unit = new Unit(session)
                            {
                                Code                 = Lenghts[i],
                                Name                 = Name_Lenght[i],
                                RowStatus            = Utility.Constant.ROWSTATUS_DEFAULT,
                                OrganizationId       = orgID,
                                UnitTypeId           = unitTypeID_LENGTH,
                                RowCreationTimeStamp = DateTime.Now
                            };
                            unit.Save();
                        }
                        else
                        {
                            Unit unit = session.FindObject <Unit>(new BinaryOperator("Code", Lenghts[i], BinaryOperatorType.Equal));
                            unit.Name           = Name_Lenght[i];
                            unit.RowStatus      = Utility.Constant.ROWSTATUS_DEFAULT;
                            unit.OrganizationId = orgID;
                            unit.UnitTypeId     = unitTypeID_LENGTH;
                            unit.Save();
                        }
                    }
                }
                else
                {
                    throw new Exception(@"Không có dữ liệu Length trong Database");
                }
                #endregion
                #region ADD Weights
                if (unitTypeID_WEIGHT != null)
                {
                    for (i = 0; i < Weights.Length; i++)
                    {
                        if (!Util.isExistXpoObject <Unit>("Code", Weights[i], Utility.Constant.ROWSTATUS_DEFAULT, Utility.Constant.ROWSTATUS_ACTIVE))
                        {
                            Unit unit = new Unit(session)
                            {
                                Code                 = Weights[i],
                                Name                 = Name_Weight[i],
                                RowStatus            = Utility.Constant.ROWSTATUS_DEFAULT,
                                OrganizationId       = orgID,
                                UnitTypeId           = unitTypeID_WEIGHT,
                                RowCreationTimeStamp = DateTime.Now
                            };
                            unit.Save();
                        }
                        else
                        {
                            Unit unit = session.FindObject <Unit>(new BinaryOperator("Code", Weights[i], BinaryOperatorType.Equal));
                            unit.Name           = Name_Weight[i];
                            unit.RowStatus      = Utility.Constant.ROWSTATUS_DEFAULT;
                            unit.OrganizationId = orgID;
                            unit.UnitTypeId     = unitTypeID_WEIGHT;
                            unit.Save();
                        }
                    }
                }
                else
                {
                    throw new Exception(@"Không có dữ liệu Weight trong Database");
                }
                #endregion
                #region ADD Capacitys
                if (unitTypeID_CAPACITY != null)
                {
                    for (i = 0; i < Capacitys.Length; i++)
                    {
                        if (!Util.isExistXpoObject <Unit>("Code", Capacitys[i], Utility.Constant.ROWSTATUS_DEFAULT, Utility.Constant.ROWSTATUS_ACTIVE))
                        {
                            Unit unit = new Unit(session)
                            {
                                Code                 = Capacitys[i],
                                Name                 = Name_Capacity[i],
                                RowStatus            = Utility.Constant.ROWSTATUS_DEFAULT,
                                OrganizationId       = orgID,
                                UnitTypeId           = unitTypeID_CAPACITY,
                                RowCreationTimeStamp = DateTime.Now
                            };
                            unit.Save();
                        }
                        else
                        {
                            Unit unit = session.FindObject <Unit>(new BinaryOperator("Code", Capacitys[i], BinaryOperatorType.Equal));
                            unit.Name           = Name_Capacity[i];
                            unit.RowStatus      = Utility.Constant.ROWSTATUS_DEFAULT;
                            unit.OrganizationId = orgID;
                            unit.UnitTypeId     = unitTypeID_CAPACITY;
                            unit.Save();
                        }
                    }
                }
                else
                {
                    throw new Exception(@"Không có dữ liệu Capacitys trong Database");
                }
                #endregion
                #region ADD Acreage
                if (unitTypeID_ACREAGE != null)
                {
                    for (i = 0; i < AREA.Length; i++)
                    {
                        if (!Util.isExistXpoObject <Unit>("Code", AREA[i], Utility.Constant.ROWSTATUS_DEFAULT, Utility.Constant.ROWSTATUS_ACTIVE))
                        {
                            Unit unit = new Unit(session)
                            {
                                Code                 = AREA[i],
                                Name                 = Name_AREA[i],
                                RowStatus            = Utility.Constant.ROWSTATUS_DEFAULT,
                                OrganizationId       = orgID,
                                UnitTypeId           = unitTypeID_ACREAGE,
                                RowCreationTimeStamp = DateTime.Now
                            };
                            unit.Save();
                        }
                        else
                        {
                            Unit unit = session.FindObject <Unit>(new BinaryOperator("Code", AREA[i], BinaryOperatorType.Equal));
                            unit.Name           = Name_AREA[i];
                            unit.RowStatus      = Utility.Constant.ROWSTATUS_DEFAULT;
                            unit.OrganizationId = orgID;
                            unit.UnitTypeId     = unitTypeID_ACREAGE;
                            unit.Save();
                        }
                    }
                }
                else
                {
                    throw new Exception(@"Không có dữ liệu Acreage trong Database");
                }
                #endregion
                //END DND
            }
            catch (Exception)
            {
                session.RollbackTransaction();
                throw;
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
Exemple #21
0
 public bool Install(Tenant tenant, string version)
 {
     XpoHelper.InitXpo(tenant.DBConnectionString);
     //return _sql.ExecuteScript(tenant, GetType().Assembly, "BIT.Customer." + version + ".sql");
     return(true);
 }
Exemple #22
0
        protected void cpBooking_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
        {
            session = XpoHelper.GetNewSession();


            switch (e.Parameter)
            {
            case "view":

                grdBooking.DetailRows.CollapseAllRows();

                if (Session["SaleBillId"] == null)
                {
                    return;
                }

                session = XpoHelper.GetNewSession();
                SalesInvoice salesInvoice = session.GetObjectByKey <SalesInvoice>(Guid.Parse(Session["SaleBillId"].ToString()));

                CriteriaOperator filter = new BinaryOperator("SalesInvoiceInventoryTransactionId", Guid.Parse(Session["SaleBillId"].ToString()), BinaryOperatorType.Equal);
                XPCollection <SalesInvoiceInventoryAccountingTransaction> saleInvoiceTransaction = new XPCollection <SalesInvoiceInventoryAccountingTransaction>(session, filter);

                if (saleInvoiceTransaction.Count > 0)
                {
                    foreach (SalesInvoiceInventoryAccountingTransaction item in saleInvoiceTransaction)
                    {
                        if (item.RowStatus == ROW_NOT_DELETE)
                        {
                            grdBooking.Columns["Thao tác"].Visible = false;
                            break;
                        }
                        else
                        {
                            grdBooking.Columns["Thao tác"].Visible = true;
                        }
                    }
                }
                else
                {
                    grdBooking.AddNewRow();
                    grdBooking.Columns["Thao tác"].Visible = true;
                }

                cpBooking.JSProperties.Add("cpEnable", "true");


                /////


                break;

            case "booking":

                salesInvoice = session.GetObjectByKey <SalesInvoice>(Guid.Parse(Session["SaleBillId"].ToString()));

                filter = new BinaryOperator("SalesInvoiceInventoryTransactionId", Guid.Parse(Session["SaleBillId"].ToString()), BinaryOperatorType.Equal);
                saleInvoiceTransaction = new XPCollection <SalesInvoiceInventoryAccountingTransaction>(session, filter);

                foreach (SalesInvoiceInventoryAccountingTransaction item in saleInvoiceTransaction)
                {
                    double credit = 0;
                    double debit  = 0;

                    filter = new GroupOperator(GroupOperatorType.And,
                                               new BinaryOperator("TransactionId", item.TransactionId, BinaryOperatorType.Equal),
                                               new BinaryOperator("RowStatus", ROW_NEW, BinaryOperatorType.Equal));
                    XPCollection <GeneralJournal> generalJournal = new XPCollection <GeneralJournal>(session, filter);

                    foreach (GeneralJournal x in generalJournal)
                    {
                        filter = new GroupOperator(GroupOperatorType.And,
                                                   new BinaryOperator("TransactionId", item.TransactionId, BinaryOperatorType.Equal),
                                                   new BinaryOperator("AccountId", x.AccountId, BinaryOperatorType.Equal),
                                                   new BinaryOperator("RowStatus", ROW_NEW, BinaryOperatorType.Equal));

                        XPCollection <GeneralJournal> generalJ = new XPCollection <GeneralJournal>(session, filter);
                        if (generalJ.Count >= 2)
                        {
                            cpBooking.JSProperties.Add("cpUnbooked", "1");
                            return;
                        }

                        credit += x.Credit;
                        debit  += x.Debit;
                    }

                    if (credit != debit)
                    {
                        cpBooking.JSProperties.Add("cpUnbooked", "2");
                        return;
                    }
                }

                foreach (SalesInvoiceInventoryAccountingTransaction item in saleInvoiceTransaction)
                {
                    item.RowStatus = ROW_NOT_DELETE;
                    item.Save();

                    filter = new BinaryOperator("TransactionId", item.TransactionId, BinaryOperatorType.Equal);
                    XPCollection <GeneralJournal> generalJournal = new XPCollection <GeneralJournal>(session, filter);
                    double milsec = 0;
                    foreach (GeneralJournal x in generalJournal)
                    {
                        NAS.DAL.Accounting.AccountChart.Account account = session.GetObjectByKey <NAS.DAL.Accounting.AccountChart.Account>(x.AccountId.AccountId);
                        //General general = new General();
                        //general.BalanceUpdate(session, account, x, false, x.Debit-x.Credit);
                        AccountingBO accountBO = new AccountingBO();
                        accountBO.CreateGeneralLedger(session, x.TransactionId.TransactionId, x.GeneralJournalId, milsec);

                        milsec += 10;
                    }
                }


                filter = new BinaryOperator("SalesInvoiceInventoryTransactionId", Guid.Parse(Session["SaleBillId"].ToString()), BinaryOperatorType.Equal);
                SalesInvoiceInventoryAccountingTransaction purchaseInvoiceInventoryTransaction = session.FindObject <SalesInvoiceInventoryAccountingTransaction>(filter);

                purchaseInvoiceInventoryTransaction.RowStatus = ROW_NOT_DELETE;
                purchaseInvoiceInventoryTransaction.Save();

                grdBooking.DetailRows.CollapseAllRows();
                grdBooking.Columns["Thao tác"].Visible = false;

                cpBooking.JSProperties.Add("cpEnable", "true");

                break;


            default:
                break;
            }
        }
Exemple #23
0
 protected void Page_Init(object sender, EventArgs e)
 {
     session = XpoHelper.GetNewSession();
     this.XpoInventoryUnit.Session = session;
 }
Exemple #24
0
        protected void popupCustomFieldAttachment_WindowCallback(object source, DevExpress.Web.ASPxPopupControl.PopupWindowCallbackArgs e)
        {
            try
            {
                string[] args = e.Parameter.Split('|');
                NAS.DAL.CMS.ObjectDocument.CustomField customField = null;
                string command = args[0];
                switch (command)
                {
                    #region AttachTo
                case "AttachTo":
                    //Get CustomField
                    if (args.Length > 1)
                    {
                        CustomFieldId = Guid.Parse(args[1]);
                    }
                    else
                    {
                        throw new Exception("Invalid parameter");
                    }
                    customField = GetCurrentCustomField(session);

                    //Bind data to form
                    formlayoutCustomFieldAttachment_DataBind();

                    /////Set Selection for gridview
                    gridviewObjectType.Selection.UnselectAll();
                    if (customField.ObjectTypeCustomFields != null)
                    {
                        foreach (var objectTypeCustomField in customField.ObjectTypeCustomFields)
                        {
                            gridviewObjectType.Selection
                            .SetSelectionByKey(objectTypeCustomField.ObjectTypeId.ObjectTypeId, true);
                        }
                    }
                    break;
                    #endregion

                    #region Save
                case "Save":
                    using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
                    {
                        //Delete all object type custom field which it's type is not master and system
                        customField = GetCurrentCustomField(uow);
                        var userDefinedObjectTypeCustomFields = customField.ObjectTypeCustomFields.Where(r =>
                                                                                                         !r.CustomFieldType.Equals(CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_MASTER) &&
                                                                                                         !r.CustomFieldType.Equals(CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_MASTER_READONLY) &&
                                                                                                         !r.CustomFieldType.Equals(CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_READONLY)).ToList();
                        uow.Delete(userDefinedObjectTypeCustomFields);
                        //Get selection to save
                        var selectedObjectTypeIds = gridviewObjectType.GetSelectedFieldValues("ObjectTypeId")
                                                    .Select(r => Guid.Parse(r.ToString()));

                        //Update object custom field table
                        foreach (var selectedObjectTypeId in selectedObjectTypeIds)
                        {
                            //Check exist
                            int count = customField.ObjectTypeCustomFields.Where(r =>
                                                                                 r.CustomFieldType.Equals(CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_MASTER) ||
                                                                                 r.CustomFieldType.Equals(CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_MASTER_READONLY) ||
                                                                                 r.CustomFieldType.Equals(CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_READONLY))
                                        .Count(r => r.ObjectTypeId.ObjectTypeId == selectedObjectTypeId);
                            if (count != 0)
                            {
                                continue;
                            }
                            //get ObjectType
                            ObjectType objectType = uow.GetObjectByKey <ObjectType>(selectedObjectTypeId);
                            //Create new ObjectTypeCustomField
                            ObjectTypeCustomField objectTypeCustomField = new ObjectTypeCustomField(uow)
                            {
                                CustomFieldId = customField,
                                ObjectTypeId  = objectType
                            };
                            objectTypeCustomField.Save();
                        }
                        uow.CommitChanges();
                    }
                    break;
                    #endregion

                default:
                    break;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #25
0
 protected void Page_Init(object sender, EventArgs e)
 {
     session = XpoHelper.GetNewSession();
     PricePolicyXDS.Session     = session;
     PricePolicyTypeXDS.Session = session;
 }
Exemple #26
0
 protected void Page_Init(object sender, EventArgs e)
 {
     session = XpoHelper.GetNewSession();
     dsArtifactCodeRule.Session = session;
     dsArtifactType.Session     = session;
 }
Exemple #27
0
 protected void Page_Init(object sender, EventArgs e)
 {
     session = XpoHelper.GetNewSession();
     dsVoucherTransaction.Session = session;
 }
Exemple #28
0
        public static void Populate()
        {
            Session session = null;

            try
            {
                session = XpoHelper.GetNewSession();
                //insert default data into Person table
                if (!Util.isExistXpoObject <AccountingPeriod>("Code", Utility.Constant.NAAN_DEFAULT_CODE))
                {
                    XPQuery <Organization> organizationQuery = session.Query <Organization>();
                    XPQuery <AccountType>  AccountTypeQuery  = session.Query <AccountType>();
                    Organization.Populate();
                    AccountType.Populate();
                    AccountType accountType =
                        AccountTypeQuery.Where(r => r.Code == Utility.Constant.NAAN_DEFAULT_CODE).FirstOrDefault();
                    Organization organization =
                        organizationQuery.Where(r => r.Code == Utility.Constant.NAAN_DEFAULT_CODE).FirstOrDefault();
                    AccountingPeriod accountingPeriod = new AccountingPeriod(session)
                    {
                        Code           = Utility.Constant.NAAN_DEFAULT_CODE,
                        OrganizationId = organization,
                        Description    = "",
                        fIsActive      = false,
                        fFromDateTime  = DateTime.Now,
                        fToDateTime    = DateTime.Now,
                        RowStatus      = Constant.ROWSTATUS_DEFAULT
                    };
                    accountingPeriod.Save();
                }


                if (!Util.isExistXpoObject <AccountingPeriod>("AccountingPeriodId", "5eaa2bf5-34ba-47c6-88df-48ad25bc6e18"))
                {
                    XPQuery <Organization> organizationQuery = session.Query <Organization>();
                    XPQuery <AccountType>  AccountTypeQuery  = session.Query <AccountType>();
                    Organization.Populate();
                    AccountType.Populate();
                    AccountType accountType =
                        AccountTypeQuery.Where(r => r.Code == Utility.Constant.NAAN_DEFAULT_CODE).FirstOrDefault();
                    Organization organization =
                        organizationQuery.Where(r => r.Code == Utility.Constant.NAAN_DEFAULT_CODE).FirstOrDefault();
                    AccountingPeriod accountingPeriod = new AccountingPeriod(session)
                    {
                        AccountingPeriodId = Guid.Parse("5eaa2bf5-34ba-47c6-88df-48ad25bc6e18"),
                        Code           = "MACDINH",
                        OrganizationId = organization,
                        Description    = "Chu kì Mặc định",
                        fIsActive      = true,
                        fFromDateTime  = DateTime.Today,
                        fToDateTime    = DateTime.Today.AddMonths(1),
                        RowStatus      = Constant.ROWSTATUS_ACTIVE
                    };
                    accountingPeriod.Save();
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
Exemple #29
0
 protected void Page_Init(object sender, EventArgs e)
 {
     session = XpoHelper.GetNewSession();
 }
Exemple #30
0
        public void CopyCustomFieldData(Guid sourceCMSObjectId, Guid targetCMSObjectId, bool isOnlyGetReadOnly)
        {
            ObjectCustomFieldBO objectCustomFieldBO = null;
            Session             session             = null;

            try
            {
                session = XpoHelper.GetNewSession();
                //Get source object
                NAS.DAL.CMS.ObjectDocument.Object sourceCMSObject =
                    session.GetObjectByKey <NAS.DAL.CMS.ObjectDocument.Object>(sourceCMSObjectId);

                if (sourceCMSObject == null)
                {
                    throw new Exception("Source object cannot be null");
                }

                NAS.DAL.CMS.ObjectDocument.Object targetCMSObject =
                    session.GetObjectByKey <NAS.DAL.CMS.ObjectDocument.Object>(targetCMSObjectId);

                if (targetCMSObject == null)
                {
                    throw new Exception("Target object cannot be null");
                }

                if (!sourceCMSObject.ObjectTypeId.Equals(targetCMSObject.ObjectTypeId))
                {
                    throw new Exception("Object type of the source and the target is different");
                }

                if (isOnlyGetReadOnly)
                {
                    int countReadOnlyData =
                        sourceCMSObject.ObjectCustomFields.Count(r =>
                                                                 !r.CustomFieldType.Equals(Utility.CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_DEFAULT));
                    if (countReadOnlyData == 0)
                    {
                        return;
                    }
                }

                IEnumerable <CustomFieldDataEntityBase> sourceCMSObjectData =
                    GetCustomFieldData(sourceCMSObjectId, isOnlyGetReadOnly);

                objectCustomFieldBO = new ObjectCustomFieldBO();

                //Update target's custom fields before copy data from source
                UpdateCustomFields(targetCMSObject.ObjectId);

                foreach (var sourceData in sourceCMSObjectData)
                {
                    ObjectCustomField targetObjectCustomField = targetCMSObject.ObjectCustomFields
                                                                .Where(r => r.ObjectTypeCustomFieldId.ObjectTypeCustomFieldId
                                                                       == sourceData.ObjectTypeCustomFieldId)
                                                                .First();

                    BasicCustomFieldDataEntity           tempBasicDataEntity         = null;
                    UserDefinedListCustomFieldDataEntity tempUserDefinedListEntity   = null;
                    PredefinitionCustomFieldEntity       tempPredefinitionDataEntity = null;

                    switch (sourceData.CustomFieldCategory)
                    {
                    case CustomFieldCategoryEnum.BASIC:
                        tempBasicDataEntity = (BasicCustomFieldDataEntity)sourceData;
                        //Update basic data
                        objectCustomFieldBO.UpdateBasicData(
                            targetObjectCustomField.ObjectCustomFieldId,
                            tempBasicDataEntity.BasicDataValue,
                            tempBasicDataEntity.BasicCustomFieldType,
                            tempBasicDataEntity.ObjectCustomFieldFlag);
                        break;

                    case CustomFieldCategoryEnum.LIST:
                        tempUserDefinedListEntity = (UserDefinedListCustomFieldDataEntity)sourceData;
                        //Update user defined list data
                        objectCustomFieldBO.UpdateUserDefinedListData(
                            targetObjectCustomField.ObjectCustomFieldId,
                            tempUserDefinedListEntity.UserDefinedItemIds,
                            tempUserDefinedListEntity.ObjectCustomFieldFlag);
                        break;

                    case CustomFieldCategoryEnum.BUILT_IN:
                        tempPredefinitionDataEntity = (PredefinitionCustomFieldEntity)sourceData;
                        //Update predefinition data
                        PredefinitionCustomFieldTypeEnum predefinitionCustomFieldTypeEnum;
                        bool isValidPredefinitionType =
                            Enum.TryParse <PredefinitionCustomFieldTypeEnum>(
                                tempPredefinitionDataEntity.PredefinitionType,
                                out predefinitionCustomFieldTypeEnum);
                        if (!isValidPredefinitionType)
                        {
                            throw new Exception("Invalid predeninition type");
                        }

                        objectCustomFieldBO.UpdatePredefinitionData(
                            targetObjectCustomField.ObjectCustomFieldId,
                            tempPredefinitionDataEntity.PredefinitionRefIds,
                            predefinitionCustomFieldTypeEnum,
                            tempPredefinitionDataEntity.ObjectCustomFieldFlag);
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }