コード例 #1
0
 private Guid GetCMSObjectIdOfTransaction(Guid transactionId)
 {
     if (transactionId != null && !transactionId.Equals(Guid.Empty))
     {
         NAS.DAL.CMS.ObjectDocument.Object cmsObject = null;
         using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
         {
             NAS.DAL.Accounting.Journal.Transaction transaction =
                 uow.GetObjectByKey <NAS.DAL.Accounting.Journal.Transaction>(transactionId);
             TransactionObject transactionObject =
                 transaction.TransactionObjects.FirstOrDefault();
             if (transactionObject == null)
             {
                 return(Guid.Empty);
             }
             else
             {
                 cmsObject = transactionObject.ObjectId;
             }
             return(cmsObject.ObjectId);
         }
     }
     else
     {
         return(Guid.Empty);
     }
 }
コード例 #2
0
ファイル: ucBalanceInit.ascx.cs プロジェクト: ewin66/dev
        protected void grdBalanceLine_RowInserted(object sender, DevExpress.Web.Data.ASPxDataInsertedEventArgs e)
        {
            if (cboBalanceInitAccount.Value == null || cboBalanceInitCurrency.Value == null)
            {
                return;
            }

            ObjectBO objectBO = new ObjectBO();

            NAS.DAL.CMS.ObjectDocument.Object debitJounalCMSObject = objectBO.CreateCMSObject(session, ObjectTypeEnum.OPENBALANCE_ACCOUTING);

            GeneralJournal debitGeneralJournal = session.GetObjectByKey <GeneralJournal>(Guid.Parse(e.NewValues["GeneralJournalId"].ToString()));

            GeneralJournalObject debitGeneralJournalObject = null;

            debitGeneralJournalObject = new GeneralJournalObject(session);
            debitGeneralJournalObject.GeneralJournalId = debitGeneralJournal;
            debitGeneralJournalObject.ObjectId         = debitJounalCMSObject;
            debitGeneralJournalObject.Save();

            ObjectType objectType = NAS.DAL.CMS.ObjectDocument.ObjectType.GetDefault(session, ObjectTypeEnum.OPENBALANCE_ACCOUTING);

            GeneralJournalCustomType generalJournalCustomType = new GeneralJournalCustomType(session);

            generalJournalCustomType.GeneralJournalId = debitGeneralJournal;
            generalJournalCustomType.ObjectTypeId     = objectType;
            generalJournalCustomType.Save();

            grdBalanceLine.JSProperties.Add("cpRefreshTree", "refresh");
        }
コード例 #3
0
 private Guid GetCMSObjectIdOfGeneralJounal(Guid generalJounalId)
 {
     if (generalJounalId != null && !generalJounalId.Equals(Guid.Empty))
     {
         NAS.DAL.CMS.ObjectDocument.Object cmsObject = null;
         using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
         {
             GeneralJournal       generalJournal       = uow.GetObjectByKey <GeneralJournal>(generalJounalId);
             GeneralJournalObject generalJournalObject =
                 generalJournal.GeneralJournalObjects.FirstOrDefault();
             if (generalJournalObject == null)
             {
                 return(Guid.Empty);
             }
             else
             {
                 cmsObject = generalJournalObject.ObjectId;
             }
             return(cmsObject.ObjectId);
         }
     }
     else
     {
         return(Guid.Empty);
     }
 }
コード例 #4
0
ファイル: CMSObjectRelationBO.cs プロジェクト: ewin66/dev
        /// <summary>
        /// Tìm đối tượng CMS object của InventoryJournal
        /// </summary>
        /// <param name="InventoryJournalId"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public NAS.DAL.CMS.ObjectDocument.Object GetCMSInventoryJournal(
            Guid InventoryJournalId,
            ObjectTypeEnum type)
        {
            if (type != ObjectTypeEnum.INVENTORY_IN && type != ObjectTypeEnum.INVENTORY_MOVE && type != ObjectTypeEnum.INVENTORY_OUT)
            {
                throw new Exception("The Type is invalid");
            }

            if (InventoryJournalId != null && !InventoryJournalId.Equals(Guid.Empty))
            {
                NAS.DAL.CMS.ObjectDocument.Object cmsObject = null;
                using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
                {
                    InventoryJournal       journal       = uow.GetObjectByKey <InventoryJournal>(InventoryJournalId);
                    InventoryJournalObject journalObject =
                        journal.InventoryJournalObjects.FirstOrDefault();
                    if (journalObject == null)
                    {
                        ObjectBO objectBO = new ObjectBO();
                        cmsObject = objectBO.CreateCMSObject(uow, type);
                        InventoryJournalObject newJournalObject = new InventoryJournalObject(uow)
                        {
                            ObjectId           = cmsObject,
                            InventoryJournalId = journal
                        };

                        NAS.DAL.CMS.ObjectDocument.ObjectType objectType
                            = uow.FindObject <ObjectType>(new BinaryOperator("Name", Enum.GetName(typeof(ObjectTypeEnum), type)));

                        if (objectType == null)
                        {
                            throw new Exception("The OjectType is not exist in system");
                        }

                        InventoryJournalCustomType newJournalCustomType = new InventoryJournalCustomType(uow)
                        {
                            ObjectTypeId       = objectType,
                            InventoryJournalId = journal
                        };

                        newJournalCustomType.Save();

                        uow.CommitChanges();
                    }
                    else
                    {
                        cmsObject = journalObject.ObjectId;
                    }
                    return(cmsObject);
                }
            }
            else
            {
                return(null);
            }
        }
コード例 #5
0
ファイル: ObjectBO.cs プロジェクト: ewin66/dev
        public bool UpdateCustomFields(Guid CMSObjectId)
        {
            if (CMSObjectId.Equals(Guid.Empty))
            {
                return(true);
            }
            UnitOfWork uow = null;

            try
            {
                uow = XpoHelper.GetNewUnitOfWork();
                //Get object
                NAS.DAL.CMS.ObjectDocument.Object CMSObject =
                    uow.GetObjectByKey <NAS.DAL.CMS.ObjectDocument.Object>(CMSObjectId);
                if (CMSObject == null)
                {
                    throw new Exception("Cannot update custom fields of null");
                }
                ObjectType objectType = CMSObject.ObjectTypeId;
                if (objectType == null)
                {
                    throw new Exception("The object is not of any object type");
                }
                if (objectType.ObjectTypeCustomFields != null)
                {
                    foreach (var objectTypeCustomField in objectType.ObjectTypeCustomFields)
                    {
                        //Check the custom field has already attached in the object
                        int countAttachment =
                            objectTypeCustomField.ObjectCustomFields.Where(r => r.ObjectId == CMSObject).Count();
                        if (countAttachment == 0)
                        {
                            //Attach the custom field for the object and insert default value for the field
                            AttachObjectCustomFieldWithDefaultValue(uow, CMSObject, objectTypeCustomField, CustomFieldTypeFlag.CUSTOM_FIELD_TYPE_DEFAULT);
                        }
                    }
                }
                uow.CommitChanges();
                return(true);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (uow != null)
                {
                    uow.Dispose();
                }
            }
        }
コード例 #6
0
ファイル: ObjectBO.cs プロジェクト: ewin66/dev
 public bool DeleteCMSObject(Session session, Guid CMSObjectId)
 {
     try
     {
         NAS.DAL.CMS.ObjectDocument.Object CMSObject =
             session.GetObjectByKey <NAS.DAL.CMS.ObjectDocument.Object>(CMSObjectId);
         CMSObject.Delete();
         return(true);
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #7
0
ファイル: ucBalanceInit.ascx.cs プロジェクト: ewin66/dev
        protected void cpAllocation_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
        {
            CriteriaOperator _filter;

            string[] p = e.Parameter.Split('|');
            switch (p[0])
            {
            case "allocation":

                // Check not has Object to Create

                GeneralJournal debitGeneralJournal = session.GetObjectByKey <GeneralJournal>(Guid.Parse(p[1]));
                if (debitGeneralJournal != null)
                {
                    _filter = new BinaryOperator("GeneralJournalId.GeneralJournalId", debitGeneralJournal.GeneralJournalId, BinaryOperatorType.Equal);
                    GeneralJournalObject debitGeneralJournalObject = session.FindObject <GeneralJournalObject>(_filter);
                    if (debitGeneralJournalObject == null)
                    {
                        ObjectBO objectBO = new ObjectBO();
                        NAS.DAL.CMS.ObjectDocument.Object debitJounalCMSObject = objectBO.CreateCMSObject(session, ObjectTypeEnum.OPENBALANCE_ACCOUTING);

                        debitGeneralJournalObject = new GeneralJournalObject(session);
                        debitGeneralJournalObject.GeneralJournalId = debitGeneralJournal;
                        debitGeneralJournalObject.ObjectId         = debitJounalCMSObject;
                        debitGeneralJournalObject.Save();

                        ObjectType objectType = NAS.DAL.CMS.ObjectDocument.ObjectType.GetDefault(session, ObjectTypeEnum.OPENBALANCE_ACCOUTING);

                        GeneralJournalCustomType generalJournalCustomType = new GeneralJournalCustomType(session);
                        generalJournalCustomType.GeneralJournalId = debitGeneralJournal;
                        generalJournalCustomType.ObjectTypeId     = objectType;
                        generalJournalCustomType.Save();
                    }
                }

                CriteriaOperator     filter = new BinaryOperator("GeneralJournalId.GeneralJournalId", Guid.Parse(p[1]), BinaryOperatorType.Equal);
                GeneralJournalObject generalJournalObject = session.FindObject <GeneralJournalObject>(filter);

                if (generalJournalObject != null)
                {
                    NASCustomFieldDataGridView1.CMSObjectId = Guid.Parse(generalJournalObject.ObjectId.ObjectId.ToString());
                    NASCustomFieldDataGridView1.DataBind();
                }
                break;

            default:
                break;
            }
        }
コード例 #8
0
ファイル: ObjectBO.cs プロジェクト: ewin66/dev
        public IEnumerable <CustomFieldDataEntityBase> GetCustomFieldData(Guid CMSObjectId, bool isOnlyGetReadOnly)
        {
            List <CustomFieldDataEntityBase> ret = null;
            Session session = null;

            try
            {
                session = XpoHelper.GetNewSession();
                //Get object
                NAS.DAL.CMS.ObjectDocument.Object cmsObject =
                    session.GetObjectByKey <NAS.DAL.CMS.ObjectDocument.Object>(CMSObjectId);
                //Get readonly object custom field
                IEnumerable <ObjectCustomField> objectCustomFields = null;
                if (isOnlyGetReadOnly)
                {
                    objectCustomFields = cmsObject.ObjectCustomFields.Where(r =>
                                                                            !r.CustomFieldType.Equals(Utility.CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_DEFAULT));
                }
                else
                {
                    objectCustomFields = cmsObject.ObjectCustomFields;
                }
                if (objectCustomFields == null)
                {
                    return(null);
                }

                ret = new List <CustomFieldDataEntityBase>();

                foreach (var objectCustomField in objectCustomFields)
                {
                    ret.Add(GetObjectCustomFieldData(objectCustomField));
                }

                return(ret);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
コード例 #9
0
 private Guid GetCMSObjectIdOfTransaction(Guid transactionId)
 {
     if (transactionId != null && !transactionId.Equals(Guid.Empty))
     {
         NAS.DAL.CMS.ObjectDocument.Object cmsObject = null;
         using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
         {
             Transaction       transaction       = uow.GetObjectByKey <Transaction>(transactionId);
             TransactionObject transactionObject =
                 transaction.TransactionObjects.FirstOrDefault();
             if (transactionObject == null)
             {
                 ObjectBO objectBO = new ObjectBO();
                 NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum objectType = ObjectTypeEnum.VOUCHER_PAYMENT;;
                 if (Strategy.GetConcreteVoucherType().Equals(typeof(NAS.DAL.Vouches.ReceiptVouches)))
                 {
                     objectType = NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.VOUCHER_RECEIPT;
                 }
                 else if (Strategy.GetConcreteVoucherType().Equals(typeof(NAS.DAL.Vouches.PaymentVouches)))
                 {
                     objectType = NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.VOUCHER_PAYMENT;
                 }
                 else
                 {
                     throw new Exception("Create object the specific type is out of scope");
                 }
                 cmsObject = objectBO.CreateCMSObject(uow, objectType);
                 TransactionObject newTransactionObject = new TransactionObject(uow)
                 {
                     ObjectId      = cmsObject,
                     TransactionId = transaction
                 };
                 uow.CommitChanges();
             }
             else
             {
                 cmsObject = transactionObject.ObjectId;
             }
             return(cmsObject.ObjectId);
         }
     }
     else
     {
         return(Guid.Empty);
     }
 }
コード例 #10
0
 private Guid GetCMSObjectIdOfGeneralJounal(Guid generalJounalId)
 {
     if (generalJounalId != null && !generalJounalId.Equals(Guid.Empty))
     {
         NAS.DAL.CMS.ObjectDocument.Object cmsObject = null;
         using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
         {
             GeneralJournal       generalJournal       = uow.GetObjectByKey <GeneralJournal>(generalJounalId);
             GeneralJournalObject generalJournalObject =
                 generalJournal.GeneralJournalObjects.FirstOrDefault();
             if (generalJournalObject == null)
             {
                 ObjectBO objectBO = new ObjectBO();
                 NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum objectType = ObjectTypeEnum.VOUCHER_PAYMENT;;
                 if (Strategy.GetConcreteVoucherTransactionType().Equals(typeof(NAS.DAL.Accounting.Journal.ReceiptVouchesTransaction)))
                 {
                     objectType = NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.VOUCHER_RECEIPT;
                 }
                 else if (Strategy.GetConcreteVoucherTransactionType().Equals(typeof(NAS.DAL.Accounting.Journal.PaymentVouchesTransaction)))
                 {
                     objectType = NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.VOUCHER_PAYMENT;
                 }
                 else
                 {
                     throw new Exception("Create object the specific type is out of scope");
                 }
                 cmsObject = objectBO.CreateCMSObject(uow, objectType);
                 GeneralJournalObject newTransactionObject = new GeneralJournalObject(uow)
                 {
                     ObjectId         = cmsObject,
                     GeneralJournalId = generalJournal
                 };
                 uow.CommitChanges();
             }
             else
             {
                 cmsObject = generalJournalObject.ObjectId;
             }
             return(cmsObject.ObjectId);
         }
     }
     else
     {
         return(Guid.Empty);
     }
 }
コード例 #11
0
        public PaymentVouches CreateNewObject(Session session)
        {
            try
            {
                PaymentVouches paymentVouches = new PaymentVouches(session)
                {
                    VouchesId = Guid.NewGuid(),
                    RowStatus = Utility.Constant.ROWSTATUS_TEMP
                };
                paymentVouches.Save();

                ObjectBO objectBO = new ObjectBO();

                NAS.DAL.CMS.ObjectDocument.Object CMSObject = objectBO.CreateCMSObject(session,
                                                                                       DAL.CMS.ObjectDocument.ObjectTypeEnum.VOUCHER_PAYMENT);

                VoucherObject voucherObject = new VoucherObject(session)
                {
                    ObjectId  = CMSObject,
                    VoucherId = paymentVouches
                };
                voucherObject.Save();

                VoucherCustomType voucherCustomType = new VoucherCustomType(session)
                {
                    VoucherId    = paymentVouches,
                    ObjectTypeId = ObjectType.GetDefault(session, ObjectTypeEnum.VOUCHER_PAYMENT)
                };
                voucherCustomType.Save();

                return(paymentVouches);
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
            }
        }
コード例 #12
0
ファイル: ObjectBO.cs プロジェクト: ewin66/dev
        public DynamicObjectListSerialize GetDynamicObjectList(Guid objectId)
        {
            DynamicObjectListSerialize ret = null;
            Session session = null;

            try
            {
                session = XpoHelper.GetNewSession();
                NAS.DAL.CMS.ObjectDocument.Object cmsObject =
                    session.GetObjectByKey <NAS.DAL.CMS.ObjectDocument.Object>(objectId);

                if (cmsObject == null)
                {
                    throw new Exception("Could not found CMS Object");
                }

                if (cmsObject.DynamicObjectList != null)
                {
                    using (MemoryStream stream = new MemoryStream(cmsObject.DynamicObjectList))
                    {
                        ret = DynamicObjectListSerialize.Deserialize(stream);
                    }
                }

                return(ret);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
コード例 #13
0
ファイル: ObjectBO.cs プロジェクト: ewin66/dev
        public NAS.DAL.CMS.ObjectDocument.Object CreateCMSObject(Session session,
                                                                 ObjectTypeEnum type,
                                                                 params ObjectCustomFieldOption[] options)
        {
            NAS.DAL.CMS.ObjectDocument.Object CMSObject = null;
            try
            {
                //Get object type
                NAS.DAL.CMS.ObjectDocument.ObjectType CMSObjectType = ObjectType.GetDefault(session, type);
                //Create new CMS Object
                CMSObject = new DAL.CMS.ObjectDocument.Object(session)
                {
                    ObjectId     = Guid.NewGuid(),
                    ObjectTypeId = CMSObjectType
                };
                CMSObject.Save();

                foreach (var objectTypeCustomField in CMSObjectType.ObjectTypeCustomFields)
                {
                    CustomFieldTypeFlag flag = CustomFieldTypeFlag.CUSTOM_FIELD_TYPE_DEFAULT;
                    if (options.Length > 0)
                    {
                        ObjectCustomFieldOption option =
                            options.Where(r => r.CustomFieldId == objectTypeCustomField.CustomFieldId.CustomFieldId).FirstOrDefault();
                        if (option != null)
                        {
                            flag = option.ObjectCustomFieldFlag;
                        }
                    }
                    AttachObjectCustomFieldWithDefaultValue(session, CMSObject, objectTypeCustomField, flag);
                }
                return(CMSObject);
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #14
0
 private Guid GetCMSObjectIdOfTransaction(Guid transactionId)
 {
     if (transactionId != null && !transactionId.Equals(Guid.Empty))
     {
         NAS.DAL.CMS.ObjectDocument.Object cmsObject = null;
         using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
         {
             NAS.DAL.Accounting.Journal.Transaction transaction =
                 uow.GetObjectByKey <NAS.DAL.Accounting.Journal.Transaction>(transactionId);
             TransactionObject transactionObject =
                 transaction.TransactionObjects.FirstOrDefault();
             if (transactionObject == null)
             {
                 return(Guid.Empty);
                 //ObjectBO objectBO = new ObjectBO();
                 //NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum objectType = ObjectTypeEnum.NAAN_DEFAULT;
                 //objectType = Strategy.GetObjectTypeEnum();
                 //cmsObject = objectBO.CreateCMSObject(uow, objectType);
                 //TransactionObject newTransactionObject = new TransactionObject(uow)
                 //{
                 //    ObjectId = cmsObject,
                 //    TransactionId = transaction
                 //};
                 //uow.CommitChanges();
             }
             else
             {
                 cmsObject = transactionObject.ObjectId;
             }
             return(cmsObject.ObjectId);
         }
     }
     else
     {
         return(Guid.Empty);
     }
 }
コード例 #15
0
ファイル: ObjectBO.cs プロジェクト: ewin66/dev
        public void SetDynamicObjectListItem(Session session, Guid objectId, DynamicObjectListSerializeDataItem data)
        {
            DynamicObjectListSerialize dynamicObjectList = null;

            NAS.DAL.CMS.ObjectDocument.Object CMSObject =
                session.GetObjectByKey <NAS.DAL.CMS.ObjectDocument.Object>(objectId);

            if (CMSObject == null)
            {
                return;
            }

            if (CMSObject.DynamicObjectList != null)
            {
                using (MemoryStream stream = new MemoryStream(CMSObject.DynamicObjectList))
                {
                    dynamicObjectList = DynamicObjectListSerialize.Deserialize(stream);
                    if (dynamicObjectList == null)
                    {
                        dynamicObjectList = new DynamicObjectListSerialize();
                    }
                }
            }
            else
            {
                dynamicObjectList = new DynamicObjectListSerialize();
            }

            using (MemoryStream stream = new MemoryStream())
            {
                dynamicObjectList[data.GetKey()] = data;
                DynamicObjectListSerialize.Serialize(dynamicObjectList, stream);
                CMSObject.DynamicObjectList = stream.ToArray();
                CMSObject.Save();
            }
        }
コード例 #16
0
ファイル: ObjectBO.cs プロジェクト: ewin66/dev
        public void RemoveDynamicObjectListItem(Session session, Guid objectId, Guid objectCustomFieldId)
        {
            DynamicObjectListSerialize dynamicObjectList = null;

            NAS.DAL.CMS.ObjectDocument.Object CMSObject =
                session.GetObjectByKey <NAS.DAL.CMS.ObjectDocument.Object>(objectId);

            if (CMSObject == null)
            {
                return;
            }

            if (CMSObject.DynamicObjectList != null)
            {
                using (MemoryStream stream = new MemoryStream(CMSObject.DynamicObjectList))
                {
                    dynamicObjectList = DynamicObjectListSerialize.Deserialize(stream);
                    if (dynamicObjectList == null)
                    {
                        dynamicObjectList = new DynamicObjectListSerialize();
                    }
                }

                using (MemoryStream stream = new MemoryStream())
                {
                    string key = objectCustomFieldId.ToString().Replace("-", "");
                    if (dynamicObjectList.ContainsKey(key))
                    {
                        dynamicObjectList.Remove(key);
                    }
                    DynamicObjectListSerialize.Serialize(dynamicObjectList, stream);
                    CMSObject.DynamicObjectList = stream.ToArray();
                    CMSObject.Save();
                }
            }
        }
コード例 #17
0
 private Guid GetCMSObjectIdOfGeneralJounal(Guid generalJounalId)
 {
     if (generalJounalId != null && !generalJounalId.Equals(Guid.Empty))
     {
         NAS.DAL.CMS.ObjectDocument.Object cmsObject = null;
         using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
         {
             GeneralJournal       generalJournal       = uow.GetObjectByKey <GeneralJournal>(generalJounalId);
             GeneralJournalObject generalJournalObject =
                 generalJournal.GeneralJournalObjects.FirstOrDefault();
             if (generalJournalObject == null)
             {
                 return(Guid.Empty);
                 //ObjectBO objectBO = new ObjectBO();
                 //NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum objectType = ObjectTypeEnum.NAAN_DEFAULT; ;
                 //objectType = Strategy.GetObjectTypeEnum();
                 //cmsObject = objectBO.CreateCMSObject(uow, objectType);
                 //GeneralJournalObject newTransactionObject = new GeneralJournalObject(uow)
                 //{
                 //    ObjectId = cmsObject,
                 //    GeneralJournalId = generalJournal
                 //};
                 //uow.CommitChanges();
             }
             else
             {
                 cmsObject = generalJournalObject.ObjectId;
             }
             return(cmsObject.ObjectId);
         }
     }
     else
     {
         return(Guid.Empty);
     }
 }
コード例 #18
0
ファイル: CMSObjectRelationBO.cs プロジェクト: ewin66/dev
        /// <summary>
        /// Tạo dữ liệu cho CMS Object Inventory
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="uow"></param>
        /// <param name="InventoryObjectId"></param>
        /// <param name="CMSObjectType"></param>
        public void PopulateCMSObjecForInventoryObject <T>(
            UnitOfWork uow,
            Guid InventoryObjectId,
            DAL.CMS.ObjectDocument.ObjectTypeEnum CMSObjectType)
        {
            ObjectBO bo = new ObjectBO();

            if (typeof(T).Equals(typeof(NAS.DAL.Inventory.Command.InventoryCommand)))
            {
                NAS.DAL.Inventory.Command.InventoryCommand inventoryObject =
                    uow.GetObjectByKey <NAS.DAL.Inventory.Command.InventoryCommand>(InventoryObjectId);
                NAS.DAL.CMS.ObjectDocument.Object o   = bo.CreateCMSObject(uow, CMSObjectType);
                InventoryCommandObject            ICO = new InventoryCommandObject(uow);
                ICO.ObjectId           = o;
                ICO.InventoryCommandId = (inventoryObject as NAS.DAL.Inventory.Command.InventoryCommand);
                ICO.Save();
                NAS.DAL.CMS.ObjectDocument.ObjectType type =
                    NAS.DAL.CMS.ObjectDocument.ObjectType.GetDefault(uow, CMSObjectType);
                if (type == null)
                {
                    throw new Exception("The ObjectType is not exist in system");
                }

                InventoryCommandCustomType ICCT = new InventoryCommandCustomType(uow);
                ICCT.ObjectTypeId       = type;
                ICCT.InventoryCommandId = (inventoryObject as NAS.DAL.Inventory.Command.InventoryCommand);
                ICCT.Save();
            }
            else if (typeof(T).Equals(typeof(NAS.DAL.Inventory.Command.InventoryCommandItemTransaction)))
            {
                InventoryCommandItemTransaction transactionObject =
                    uow.GetObjectByKey <InventoryCommandItemTransaction>(InventoryObjectId);
                NAS.DAL.CMS.ObjectDocument.Object o   = bo.CreateCMSObject(uow, CMSObjectType);
                InventoryTransactionObject        ITO = new InventoryTransactionObject(uow);
                ITO.ObjectId = o;
                ITO.InventoryTransactionId = (transactionObject as NAS.DAL.Inventory.Journal.InventoryTransaction);
                ITO.Save();

                NAS.DAL.CMS.ObjectDocument.ObjectType type =
                    NAS.DAL.CMS.ObjectDocument.ObjectType.GetDefault(uow, CMSObjectType);
                InventoryTransactionCustomType ITCT = new InventoryTransactionCustomType(uow);
                ITCT.ObjectTypeId           = type;
                ITCT.InventoryTransactionId = (transactionObject as NAS.DAL.Inventory.Journal.InventoryTransaction);
                ITCT.Save();
            }
            else if (typeof(T).Equals(typeof(NAS.DAL.Inventory.Command.InventoryCommandFinancialTransaction)))
            {
                InventoryCommandFinancialTransaction transactionObject =
                    uow.GetObjectByKey <InventoryCommandFinancialTransaction>(InventoryObjectId);
                NAS.DAL.CMS.ObjectDocument.Object o = bo.CreateCMSObject(uow, CMSObjectType);
                TransactionObject TO = new TransactionObject(uow);
                TO.ObjectId      = o;
                TO.TransactionId = (transactionObject as Transaction);
                TO.Save();
            }
            else if (typeof(T).Equals(typeof(NAS.DAL.Accounting.Journal.GeneralJournal)))
            {
                GeneralJournal journalObject =
                    uow.GetObjectByKey <GeneralJournal>(InventoryObjectId);
                NAS.DAL.CMS.ObjectDocument.Object o = bo.CreateCMSObject(uow, CMSObjectType);
                GeneralJournalObject GJO            = new GeneralJournalObject(uow);
                GJO.ObjectId         = o;
                GJO.GeneralJournalId = (journalObject as GeneralJournal);
                GJO.Save();
                NAS.DAL.CMS.ObjectDocument.ObjectType type =
                    NAS.DAL.CMS.ObjectDocument.ObjectType.GetDefault(uow, CMSObjectType);
                GeneralJournalCustomType GJCT = new GeneralJournalCustomType(uow);
                GJCT.ObjectTypeId     = type;
                GJCT.GeneralJournalId = (journalObject as GeneralJournal);
                GJCT.Save();
            }
            else if (typeof(T).Equals(typeof(NAS.DAL.Inventory.Journal.InventoryJournal)))
            {
                InventoryJournal journalObject =
                    uow.GetObjectByKey <InventoryJournal>(InventoryObjectId);
                NAS.DAL.CMS.ObjectDocument.Object o   = bo.CreateCMSObject(uow, CMSObjectType);
                InventoryJournalObject            ITO = new InventoryJournalObject(uow);
                ITO.ObjectId           = o;
                ITO.InventoryJournalId = (journalObject as InventoryJournal);
                ITO.Save();

                NAS.DAL.CMS.ObjectDocument.ObjectType type =
                    NAS.DAL.CMS.ObjectDocument.ObjectType.GetDefault(uow, CMSObjectType);
                InventoryJournalCustomType ITCT = new InventoryJournalCustomType(uow);
                ITCT.ObjectTypeId       = type;
                ITCT.InventoryJournalId = (journalObject as InventoryJournal);
                ITCT.Save();
            }
            uow.FlushChanges();
        }
コード例 #19
0
ファイル: CMSObjectRelationBO.cs プロジェクト: ewin66/dev
        /// <summary>
        /// Tìm đối tượng CMS object của InventoryJournal
        /// </summary>
        /// <typeparam name="T">is NAS.DAL.Inventory.Command.InventoryCommandFinancialTransaction
        ///         or NAS.DAL.Inventory.Command.InventoryCommandItemTransaction
        /// </typeparam>
        /// <param name="transactionId"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public NAS.DAL.CMS.ObjectDocument.Object GetCMSTransaction <T>(
            Guid transactionId,
            ObjectTypeEnum type)
        {
            if (type != ObjectTypeEnum.INVENTORY_IN && type != ObjectTypeEnum.INVENTORY_MOVE && type != ObjectTypeEnum.INVENTORY_OUT)
            {
                throw new Exception("The Type is invalid");
            }

            if (!typeof(T).Equals(typeof(NAS.DAL.Inventory.Command.InventoryCommandFinancialTransaction)) &&
                !typeof(T).Equals(typeof(NAS.DAL.Inventory.Command.InventoryCommandItemTransaction)))
            {
                throw new Exception("The Generic Type is invalid");
            }

            if (transactionId != null && !transactionId.Equals(Guid.Empty))
            {
                NAS.DAL.CMS.ObjectDocument.Object cmsObject = null;
                using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
                {
                    if (typeof(T).Equals(typeof(NAS.DAL.Inventory.Command.InventoryCommandItemTransaction)))
                    {
                        InventoryCommandItemTransaction transaction       = uow.GetObjectByKey <InventoryCommandItemTransaction>(transactionId);
                        InventoryTransactionObject      transactionObject =
                            transaction.InventoryTransactionObjects.FirstOrDefault();
                        if (transactionObject == null)
                        {
                            ObjectBO objectBO = new ObjectBO();
                            cmsObject = objectBO.CreateCMSObject(uow, type);
                            InventoryTransactionObject newTransactionObject = new InventoryTransactionObject(uow)
                            {
                                ObjectId = cmsObject,
                                InventoryTransactionId = transaction
                            };

                            NAS.DAL.CMS.ObjectDocument.ObjectType objectType
                                = uow.FindObject <ObjectType>(new BinaryOperator("Name", Enum.GetName(typeof(ObjectTypeEnum), type)));

                            if (objectType == null)
                            {
                                throw new Exception("The OjectType is not exist in system");
                            }

                            InventoryTransactionCustomType newTransactionCustomType = new InventoryTransactionCustomType(uow)
                            {
                                ObjectTypeId           = objectType,
                                InventoryTransactionId = transaction
                            };

                            newTransactionCustomType.Save();
                            uow.CommitChanges();
                        }
                        else
                        {
                            cmsObject = transactionObject.ObjectId;
                        }
                        return(cmsObject);
                    }
                    else
                    {
                        InventoryCommandFinancialTransaction transaction = uow.GetObjectByKey <InventoryCommandFinancialTransaction>(transactionId);
                        TransactionObject transactionObject =
                            transaction.TransactionObjects.FirstOrDefault();
                        if (transactionObject == null)
                        {
                            ObjectBO objectBO = new ObjectBO();
                            cmsObject = objectBO.CreateCMSObject(uow, type);
                            TransactionObject newTransactionObject = new TransactionObject(uow)
                            {
                                ObjectId      = cmsObject,
                                TransactionId = transaction
                            };
                            uow.CommitChanges();
                        }
                        else
                        {
                            cmsObject = transactionObject.ObjectId;
                        }
                        return(cmsObject);
                    }
                }
            }
            else
            {
                return(null);
            }
        }
コード例 #20
0
ファイル: ucBalanceInit.ascx.cs プロジェクト: ewin66/dev
        protected void grdBalanceLine_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
        {
            if (cboBalanceInitAccount.Value == null)
            {
                grdBalanceLine.JSProperties.Add("cpAccountInvalid", "invalid");
                e.Cancel = true;
                return;
            }

            if (cboBalanceInitCurrency.Value == null)
            {
                grdBalanceLine.JSProperties.Add("cpCurrencyInvalid", "invalid");
                e.Cancel = true;
                return;
            }

            CriteriaOperator _filter = null;

            BalanceForwardTransaction balanceForwardTransaction = session.GetObjectByKey <BalanceForwardTransaction>(Guid.Parse(e.OldValues["TransactionId!Key"].ToString()));

            if (balanceForwardTransaction != null)
            {
                if (cboAccountPeriod.Value == null)
                {
                    throw new Exception("Chưa chọn kỳ kế toán !");
                }

                AccountingPeriod _accountingPeriod = session.GetObjectByKey <AccountingPeriod>(Guid.Parse(cboAccountPeriod.Value.ToString()));

                if (_accountingPeriod == null)
                {
                    throw new Exception("Chưa chọn kỳ kế toán !");
                }

                balanceForwardTransaction.AccountingPeriodId = _accountingPeriod;

                balanceForwardTransaction.Code        = e.NewValues["TransactionId.Code"].ToString();
                balanceForwardTransaction.Description = e.NewValues["TransactionId.Description"].ToString();

                balanceForwardTransaction.Save();
            }

            ASPxSpinEdit c = (ASPxSpinEdit)grdBalanceLine.FindEditRowCellTemplateControl((GridViewDataColumn)grdBalanceLine.Columns["Debit"], "colBalanceInitDebit");

            e.NewValues["Debit"] = c.Value.ToString();
            c = (ASPxSpinEdit)grdBalanceLine.FindEditRowCellTemplateControl((GridViewDataColumn)grdBalanceLine.Columns["Credit"], "colBalanceInitCredit");
            e.NewValues["Credit"] = c.Value.ToString();

            e.NewValues["AccountId!Key"]  = cboBalanceInitAccount.Value.ToString();
            e.NewValues["CurrencyId!Key"] = cboBalanceInitCurrency.Value.ToString();

            // Check not has Object to Create

            GeneralJournal debitGeneralJournal = session.GetObjectByKey <GeneralJournal>(Guid.Parse(e.OldValues["GeneralJournalId"].ToString()));

            if (debitGeneralJournal != null)
            {
                _filter = new BinaryOperator("GeneralJournalId.GeneralJournalId", debitGeneralJournal.GeneralJournalId, BinaryOperatorType.Equal);
                GeneralJournalObject debitGeneralJournalObject = session.FindObject <GeneralJournalObject>(_filter);
                if (debitGeneralJournalObject == null)
                {
                    ObjectBO objectBO = new ObjectBO();
                    NAS.DAL.CMS.ObjectDocument.Object debitJounalCMSObject = objectBO.CreateCMSObject(session, ObjectTypeEnum.OPENBALANCE_ACCOUTING);

                    debitGeneralJournalObject = new GeneralJournalObject(session);
                    debitGeneralJournalObject.GeneralJournalId = debitGeneralJournal;
                    debitGeneralJournalObject.ObjectId         = debitJounalCMSObject;
                    debitGeneralJournalObject.Save();

                    ObjectType objectType = NAS.DAL.CMS.ObjectDocument.ObjectType.GetDefault(session, ObjectTypeEnum.OPENBALANCE_ACCOUTING);

                    GeneralJournalCustomType generalJournalCustomType = new GeneralJournalCustomType(session);
                    generalJournalCustomType.GeneralJournalId = debitGeneralJournal;
                    generalJournalCustomType.ObjectTypeId     = objectType;
                    generalJournalCustomType.Save();
                }
            }

            BalanceLineSetData();
            grdBalanceLine.JSProperties.Add("cpRefreshTree", "refresh");
        }
コード例 #21
0
ファイル: uManufacturerEdit.ascx.cs プロジェクト: ewin66/dev
        protected void popManufacturerEdit_WindowCallback(object source, DevExpress.Web.ASPxPopupControl.PopupWindowCallbackArgs e)
        {
            string[] args = e.Parameter.Split('|');
            switch (args[0])
            {
            case "new":

                ManufacturerOrg tempManufacturerOrg = ManufacturerOrg.InitNewRow(session);
                PrivateSession.Instance.ManufacturerOrgId = tempManufacturerOrg.OrganizationId;
                frmManufacturerEdit.DataSourceID          = "dsManufacturer";
                dsManufacturer.CriteriaParameters["ManufacturerOrgId"].DefaultValue = PrivateSession.Instance.ManufacturerOrgId.ToString();
                ClearForm();
                //Get object id
                //Bind data to gridview

                #region add manufacturer
                session.BeginTransaction();
                try
                {
                    //ObjectType
                    ObjectType objectType =
                        ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.MANUFACTURER);

                    // object
                    NAS.BO.CMS.ObjectDocument.ObjectBO objectBO  = new NAS.BO.CMS.ObjectDocument.ObjectBO();
                    NAS.DAL.CMS.ObjectDocument.Object  cmsobject =
                        objectBO.CreateCMSObject(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.MANUFACTURER);

                    // OrganizationObject
                    OrganizationObject organizatoinObject = new OrganizationObject(session)
                    {
                        ObjectId       = cmsobject,
                        OrganizationId = tempManufacturerOrg
                    };
                    organizatoinObject.Save();

                    // OrganizationCustomType
                    OrganizationCustomType organizationCustomType = new OrganizationCustomType(session)
                    {
                        ObjectTypeId   = objectType,
                        OrganizationId = tempManufacturerOrg
                    };
                    organizationCustomType.Save();
                    session.CommitTransaction();
                }
                catch
                {
                    session.RollbackTransaction();
                }


                OrganizationObject organizationObject = tempManufacturerOrg.OrganizationObjects.FirstOrDefault();
                grid_of_Manufacturer.CMSObjectId = organizationObject.ObjectId.ObjectId;
                grid_of_Manufacturer.DataBind();
                #endregion

                //2013-11-22 Khoa.Truong DEL START
                //gridviewCustomFields.CMSObjectId = CurrentManufacturerOrg.ObjectId.ObjectId;
                //gridviewCustomFields.DataBind();
                //2013-11-22 Khoa.Truong DEL END
                break;

            case "edit":
                ClearForm();
                frmManufacturerEdit.DataSourceID = "dsManufacturer";
                if (args.Length > 1)
                {
                    PrivateSession.Instance.ManufacturerOrgId = Guid.Parse(args[1]);
                    dsManufacturer.CriteriaParameters["ManufacturerOrgId"].DefaultValue = PrivateSession.Instance.ManufacturerOrgId.ToString();
                    txtCode.Text = CurrentManufacturerOrg.Code;
                    //Get object id
                    //Bind data to gridview

                    #region edit manufacturer
                    if (CurrentManufacturerOrg.OrganizationObjects.FirstOrDefault() == null)
                    {
                        session.BeginTransaction();
                        try
                        {
                            ObjectType objectType1 =
                                ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.MANUFACTURER);

                            // object
                            NAS.BO.CMS.ObjectDocument.ObjectBO objectBO1  = new NAS.BO.CMS.ObjectDocument.ObjectBO();
                            NAS.DAL.CMS.ObjectDocument.Object  cmsobject1 =
                                objectBO1.CreateCMSObject(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.MANUFACTURER);

                            OrganizationObject organizatoinObject1 = new OrganizationObject(session)
                            {
                                ObjectId       = cmsobject1,
                                OrganizationId = CurrentManufacturerOrg
                            };
                            organizatoinObject1.Save();

                            // OrganizationCustomType
                            OrganizationCustomType organizationCustomType1 = new OrganizationCustomType(session)
                            {
                                ObjectTypeId   = objectType1,
                                OrganizationId = CurrentManufacturerOrg
                            };
                            organizationCustomType1.Save();
                            session.CommitTransaction();
                        }
                        catch (Exception)
                        {
                            session.RollbackTransaction();
                            throw;
                        }

                        OrganizationObject organizationObject1 = CurrentManufacturerOrg.OrganizationObjects.FirstOrDefault();
                        grid_of_Manufacturer.CMSObjectId = organizationObject1.ObjectId.ObjectId;
                        grid_of_Manufacturer.DataBind();
                    }

                    else
                    {
                        OrganizationObject organizationObject1 = CurrentManufacturerOrg.OrganizationObjects.FirstOrDefault();
                        grid_of_Manufacturer.CMSObjectId = organizationObject1.ObjectId.ObjectId;
                        grid_of_Manufacturer.DataBind();
                    }
                    #endregion



                    //2013-11-22 Khoa.Truong DEL START
                    //gridviewCustomFields.CMSObjectId = CurrentManufacturerOrg.ObjectId.ObjectId;
                    //gridviewCustomFields.DataBind();
                    //2013-11-22 Khoa.Truong DEL END
                }
                break;

            case "save":
                bool   isSuccess   = true;
                string recordIdStr = null;
                try
                {
                    //Check validation
                    if (!ASPxEdit.AreEditorsValid(pagMunufacturer, true))
                    {
                        popManufacturerEdit.JSProperties.Add("cpInvalid", true);
                        pagMunufacturer.ActiveTabIndex = 0;
                        return;
                    }
                    //Logic to save data
                    if (args.Length > 1)
                    {
                        //Update mode
                        //Update general information
                        recordIdStr = args[1];
                        Guid            recordId            = Guid.Parse(recordIdStr);
                        ManufacturerOrg editManufacturerOrg =
                            session.GetObjectByKey <ManufacturerOrg>(PrivateSession.Instance.ManufacturerOrgId);
                        editManufacturerOrg.Code      = txtCode.Text;
                        editManufacturerOrg.Name      = txtName.Text;
                        editManufacturerOrg.RowStatus = short.Parse(cbRowStatus.SelectedItem.Value.ToString());
                        editManufacturerOrg.Save();
                    }
                    else
                    {
                        //Insert mode
                        ManufacturerOrg newManufacturerOrg =
                            session.GetObjectByKey <ManufacturerOrg>(PrivateSession.Instance.ManufacturerOrgId);
                        newManufacturerOrg.Code      = txtCode.Text;
                        newManufacturerOrg.Name      = txtName.Text;
                        newManufacturerOrg.RowStatus = short.Parse(cbRowStatus.SelectedItem.Value.ToString());
                        newManufacturerOrg.Save();
                    }
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    throw;
                }
                finally
                {
                    popManufacturerEdit.JSProperties.Add("cpCallbackArgs",
                                                         String.Format("{{ \"recordId\": \"{0}\", \"isSuccess\": {1} }}", recordIdStr, isSuccess.ToString().ToLower()));
                }
                break;

            default:
                break;
            }
        }
コード例 #22
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
                ReceiptVouches receiptVouches = uow.GetObjectByKey <ReceiptVouches>(voucherId);

                //Create new transaction
                ReceiptVouchesTransaction transaction = new ReceiptVouchesTransaction(uow)
                {
                    TransactionId    = Guid.NewGuid(),
                    Amount           = amount,
                    Code             = code,
                    CreateDate       = DateTime.Now,
                    Description      = description,
                    IssueDate        = issuedDate,
                    ReceiptVouchesId = receiptVouches,
                    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_RECEIPT);

                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_RECEIPT);
                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_RECEIPT);
                creditGeneralJournalObject = new GeneralJournalObject(uow)
                {
                    GeneralJournalId = creditGeneralJournal,
                    ObjectId         = creditJounalCMSObject
                };

                uow.FlushChanges();

                //Copy readonly data from original artifact
                //Get origin CMS object
                VoucherObject voucherObject = receiptVouches.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();
                }
            }
        }
コード例 #23
0
ファイル: ItemBO.cs プロジェクト: ewin66/dev
        public void updateAllCommonInfoOfItem(Session session, Guid ItemId, string code, string name,
                                              Guid manufacturerId, List <Guid> objectTypeId)
        {
            ObjectBO bo = new ObjectBO();

            try
            {
                session.BeginTransaction();
                Item item = session.GetObjectByKey <Item>(ItemId);
                if (item == null)
                {
                    throw new Exception(String.Format("Không tồn tại ItemId: {0} trong Item table", ItemId));
                }

                ManufacturerOrg manu = session.GetObjectByKey <ManufacturerOrg>(manufacturerId);
                //Issue dropdownlist ---START
                //if (manu == null)
                //    throw new Exception(String.Format("Không tồn tại ManufacturerOrgId: {0} trong Item ManufacturerOrg", manufacturerId));
                //Issue dropdownlist ---END
                item.Code = code;
                item.Name = name;
                item.ManufacturerOrgId = manu;
                item.RowStatus         = Utility.Constant.ROWSTATUS_ACTIVE;
                item.Save();

                removeItemCustomTypeFromItem(session, ItemId);

                foreach (Guid g in objectTypeId)
                {
                    addItemCustomTypeToItem(session, g, ItemId);
                }

                foreach (Guid g in objectTypeId)
                {
                    if (!checkAlreadyHasObjectWithObjectType(session, ItemId, g))
                    {
                        NAS.DAL.CMS.ObjectDocument.Object o = bo.CreateCMSObject(session, g);
                        ItemObject it = new ItemObject(session);
                        it.ObjectId = o;
                        it.ItemId   = item;
                        it.Save();
                    }
                }

                for (int i = item.ItemObjects.Count - 1; i >= 0; i--)
                {
                    ItemObject tmp = item.ItemObjects[i];
                    if (!item.ItemCustomTypes.Select(r => r.ObjectTypeId).Contains(tmp.ObjectId.ObjectTypeId))
                    {
                        bo.DeleteCMSObject(session, tmp.ObjectId.ObjectId);
                    }
                }

                //foreach (ItemObject io in item.ItemObjects)
                //{
                //    if(!item.ItemCustomTypes.Select(r => r.ObjectTypeId).Contains(io.ObjectId.ObjectTypeId)) {
                //        bo.DeleteCMSObject(session, io.ObjectId.ObjectId);
                //    }
                //}

                session.CommitTransaction();
            }
            catch (Exception)
            {
                session.RollbackTransaction();
                throw;
            }
        }
コード例 #24
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;
            }
        }
コード例 #25
0
        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();
                }
            }
        }
コード例 #26
0
ファイル: ObjectBO.cs プロジェクト: ewin66/dev
        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();
                }
            }
        }