Ejemplo n.º 1
0
        public static void DeleteLogical(Guid manufacturerOrgId)
        {
            Session session = null;

            try
            {
                session = XpoHelper.GetNewSession();
                //Finds ManufacturerOrg by Id
                ManufacturerOrg manufacturerOrg = session.GetObjectByKey <ManufacturerOrg>(manufacturerOrgId);
                //Check foreign key constraint with Item table
                var itemList = manufacturerOrg.Items.Where(r => r.RowStatus > 0);
                if (itemList.Count() > 0)
                {
                    string param0 = manufacturerOrg.Name;
                    string param1 = itemList.First().Name;
                    throw new Exception(String.Format("Nhà sản xuất '{0}' đang được cấu hình trong sản phẩm '{1}'", param0, param1));
                }
                manufacturerOrg.RowStatus = Utility.Constant.ROWSTATUS_DELETED;
                manufacturerOrg.Save();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
Ejemplo n.º 2
0
        public void ItemRequestedByValue(Session session, object source, DevExpress.Web.ASPxEditors.ListEditItemRequestedByValueEventArgs e)
        {
            ASPxComboBox    combo = source as ASPxComboBox;
            ManufacturerOrg obj   = session.GetObjectByKey <ManufacturerOrg>(e.Value);

            if (obj != null)
            {
                combo.DataSource = new ManufacturerOrg[] { obj };
                combo.DataBindItems();
            }
        }
        public override List <NASCustomFieldPredefinitionData> GetSelectedPredefinitionDataFromList(object source)
        {
            List <NASCustomFieldPredefinitionData> ret = null;
            Session session = null;

            try
            {
                session = XpoHelper.GetNewSession();

                ASPxGridLookup gridlookup = source as ASPxGridLookup;

                var selectedIds = gridlookup.GridView
                                  .GetSelectedFieldValues("OrganizationId")
                                  .Select(r => Guid.Parse(r.ToString()));

                if (selectedIds != null)
                {
                    ret = new List <NASCustomFieldPredefinitionData>();
                    foreach (var Id in selectedIds)
                    {
                        ManufacturerOrg manufacturerOrg =
                            session.GetObjectByKey <ManufacturerOrg>(Id);

                        if (manufacturerOrg != null)
                        {
                            NASCustomFieldPredefinitionData retItem = new NASCustomFieldPredefinitionData()
                            {
                                Code              = manufacturerOrg.Code,
                                Description       = manufacturerOrg.Description,
                                Name              = manufacturerOrg.Name,
                                PredefinitionType = Enum.GetName(typeof(MultiSelectionBuiltInTypeEnum),
                                                                 MultiSelectionBuiltInTypeEnum.MULTI_CHOICE_LIST_MANUFACTURER),
                                RefId = manufacturerOrg.OrganizationId
                            };
                            ret.Add(retItem);
                        }
                    }
                }
                return(ret);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
        public override List <NASCustomFieldPredefinitionData> GetPredefinitionDataOfObject(Guid objectCustomFieldId)
        {
            List <NASCustomFieldPredefinitionData> ret = null;
            Session session = null;

            try
            {
                session = XpoHelper.GetNewSession();

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

                if (objectCustomField.ObjectCustomFieldDatas != null)
                {
                    ret = new List <NASCustomFieldPredefinitionData>();

                    foreach (var data in objectCustomField.ObjectCustomFieldDatas)
                    {
                        PredefinitionData predefinitionData = (PredefinitionData)data.CustomFieldDataId;

                        ManufacturerOrg manufacturerOrg =
                            session.GetObjectByKey <ManufacturerOrg>(predefinitionData.RefId);

                        if (manufacturerOrg != null)
                        {
                            NASCustomFieldPredefinitionData retItem = new NASCustomFieldPredefinitionData()
                            {
                                Code              = manufacturerOrg.Code,
                                Description       = manufacturerOrg.Description,
                                Name              = manufacturerOrg.Name,
                                PredefinitionType = Enum.GetName(typeof(MultiSelectionBuiltInTypeEnum),
                                                                 MultiSelectionBuiltInTypeEnum.MULTI_CHOICE_LIST_MANUFACTURER),
                                RefId = manufacturerOrg.OrganizationId
                            };
                            ret.Add(retItem);
                        }
                    }
                }
                return(ret);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
        public CustomFieldDataPreDefinitionData GetData(Guid objectCustomFieldId)
        {
            CustomFieldDataPreDefinitionData ret = null;
            Session session = null;

            try
            {
                session = XpoHelper.GetNewSession();

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

                if (objectCustomField.ObjectCustomFieldDatas != null)
                {
                    ret = new CustomFieldDataPreDefinitionData();

                    foreach (var data in objectCustomField.ObjectCustomFieldDatas)
                    {
                        PredefinitionData predefinitionData = (PredefinitionData)data.CustomFieldDataId;

                        ManufacturerOrg manufacturerOrg =
                            session.GetObjectByKey <ManufacturerOrg>(predefinitionData.RefId);

                        if (manufacturerOrg != null)
                        {
                            CustomFieldDataPreDefinitionDataItem item = new CustomFieldDataPreDefinitionDataItem()
                            {
                                CustomFieldDataId = predefinitionData.CustomFieldDataId,
                                PredefinitionType = predefinitionData.PredefinitionType,
                                RefId             = predefinitionData.RefId,
                                DisplayText       = manufacturerOrg.Name
                            };
                            ret.Add(item);
                        }
                    }
                }
                return(ret);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
Ejemplo n.º 6
0
        public override NASCustomFieldPredefinitionData GetSelectedPredefinitionDataFromList(object source)
        {
            NASCustomFieldPredefinitionData ret = null;
            Session session = null;

            try
            {
                ASPxComboBox combo = source as ASPxComboBox;
                session = XpoHelper.GetNewSession();

                if (combo.Value == null)
                {
                    return(null);
                }

                Guid manufacturerOrgId = (Guid)combo.Value;

                ManufacturerOrg manufacturerOrg =
                    session.GetObjectByKey <ManufacturerOrg>(manufacturerOrgId);

                if (manufacturerOrg != null)
                {
                    ret = new NASCustomFieldPredefinitionData()
                    {
                        Code              = manufacturerOrg.Code,
                        Description       = manufacturerOrg.Description,
                        Name              = manufacturerOrg.Name,
                        PredefinitionType = Enum.GetName(typeof(SingleSelectionBuiltInTypeEnum),
                                                         SingleSelectionBuiltInTypeEnum.SINGLE_CHOICE_LIST_MANUFACTURER),
                        RefId = manufacturerOrg.OrganizationId
                    };
                }

                return(ret);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
Ejemplo n.º 7
0
        public override NASCustomFieldPredefinitionData GetPredefinitionDataOfObject(Guid objectCustomFieldId)
        {
            NASCustomFieldPredefinitionData ret = null;
            Session session = null;

            try
            {
                session = XpoHelper.GetNewSession();
                ObjectCustomFieldData objectCustomFieldData =
                    session.GetObjectByKey <ObjectCustomField>(objectCustomFieldId).ObjectCustomFieldDatas.FirstOrDefault();
                if (objectCustomFieldData != null)
                {
                    PredefinitionData predefinitionData =
                        (PredefinitionData)objectCustomFieldData.CustomFieldDataId;

                    ManufacturerOrg manufacturerOrg =
                        session.GetObjectByKey <ManufacturerOrg>(predefinitionData.RefId);

                    if (manufacturerOrg != null)
                    {
                        ret = new NASCustomFieldPredefinitionData()
                        {
                            Code              = manufacturerOrg.Code,
                            Description       = manufacturerOrg.Description,
                            Name              = manufacturerOrg.Name,
                            PredefinitionType = Enum.GetName(typeof(SingleSelectionBuiltInTypeEnum),
                                                             SingleSelectionBuiltInTypeEnum.SINGLE_CHOICE_LIST_MANUFACTURER),
                            RefId = manufacturerOrg.OrganizationId
                        };
                    }
                }
                return(ret);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
Ejemplo n.º 8
0
        public AccountActor GetSelectedItem(object source)
        {
            Session session = null;

            try
            {
                session = XpoHelper.GetNewSession();
                ASPxComboBox combo = source as ASPxComboBox;
                //Get selected manufacturer
                if (combo.Value == null)
                {
                    return(null);
                }
                Guid            selectedId      = (Guid)combo.Value;
                ManufacturerOrg manufacturerOrg = session.GetObjectByKey <ManufacturerOrg>(selectedId);
                if (manufacturerOrg == null)
                {
                    return(null);
                }
                AccountActor ret = new AccountActor()
                {
                    AccountActorTypeId =
                        session.FindObject <AccountActorType>(new BinaryOperator("Code",
                                                                                 Enum.GetName(typeof(AccountActorTypeEnum),
                                                                                              AccountActorTypeEnum.MANUFACTURER))).AccountActorTypeId,
                    Code        = manufacturerOrg.Code,
                    Description = manufacturerOrg.Description,
                    Name        = manufacturerOrg.Name,
                    RefId       = manufacturerOrg.OrganizationId
                };
                return(ret);
            }
            catch (Exception)
            {
                return(null);
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
Ejemplo n.º 9
0
        public void collectData()
        {
            currentItem = session.GetObjectByKey <Item>(ItemId);
            if (currentItem != null)
            {
                currentItem.Code        = txtProductCode.Text;
                currentItem.Name        = txtProductName.Text;
                currentItem.Description = HtmlEditDescription.Html;
                currentItem.RowStatus   = cboProductRowStatus.SelectedItem != null?
                                          short.Parse(cboProductRowStatus.SelectedItem.Value.ToString()) : short.Parse("1");

                //if (cboProductManufacturer.SelectedIndex == -1) {
                //    throw new Exception("Vui lòng chọn nhà sản xuất");
                //}
                try
                {
                    if (cboProductManufacturer.SelectedItem != null)
                    {
                        ManufacturerOrg manufacturer = session.GetObjectByKey <ManufacturerOrg>(
                            Guid.Parse(
                                cboProductManufacturer.SelectedItem.GetValue("OrganizationId").ToString()
                                ));
                        if (manufacturer != null)
                        {
                            currentItem.ManufacturerOrgId = manufacturer;
                        }
                    }
                }
                catch (Exception)
                { }

                selectedObjectTypeId = new List <Guid>();
                foreach (ListEditItem l in lbType.Items)
                {
                    if (l.Selected)
                    {
                        selectedObjectTypeId.Add(Guid.Parse(l.Value.ToString()));
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public void Populate(string dataFilePath)
        {
            string          filePath      = dataFilePath;
            string          connStr       = Utils.GetOleConnectionString(filePath, true);
            string          dataSheetName = "dmnoisanxuat";
            OleDbConnection connection    = null;

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

                OleDbCommand command =
                    new OleDbCommand("select * from [" + dataSheetName + "$]", connection);


                List <OrganizationEntity> organizationEntityList = new List <OrganizationEntity>();

                using (OleDbDataReader dr = command.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        //Collect data
                        OrganizationEntity organizationEntity = new OrganizationEntity()
                        {
                            Code = (string)Utils.ConvertToNullIfDbNull(dr["Code"]),
                            Name = (string)Utils.ConvertToNullIfDbNull(dr["Name"])
                        };

                        organizationEntityList.Add(organizationEntity);
                    }
                }

                using (Session session = XpoHelper.GetNewSession())
                {
                    //Populate NAAN_DEFAULT data
                    Util.Populate();


                    foreach (var organizationEntity in organizationEntityList)
                    {
                        try
                        {
                            //Check required
                            if (organizationEntity.Code == null || organizationEntity.Code.Trim().Length == 0)
                            {
                                continue;
                            }

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

                            //Get default organization type
                            OrganizationType defaultOrganizationType =
                                Util.getXPCollection <OrganizationType>(session, "Code", "NAAN_DEFAULT").FirstOrDefault();

                            ManufacturerOrg manufacturerOrg = new ManufacturerOrg(session)
                            {
                                Code                 = organizationEntity.Code,
                                Name                 = organizationEntity.Name,
                                RowStatus            = Constant.ROWSTATUS_ACTIVE,
                                RowCreationTimeStamp = DateTime.Now
                            };

                            manufacturerOrg.Save();
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (connection != null)
                {
                    connection.Dispose();
                }
            }
        }
Ejemplo n.º 11
0
        public void InsertItems(List <ItemEntity> itemEntityList, string itemTradingTypeName, string objectTypeName)
        {
            using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
            {
                foreach (var itemEntity in itemEntityList)
                {
                    try
                    {
                        if (itemEntity.Code.Equals("EVE006"))
                        {
                            string debug = "Y";
                        }
                        //Check required
                        if (itemEntity.Code == null || itemEntity.Code.Trim().Length == 0)
                        {
                            continue;
                        }

                        //Check dupplicate code
                        bool isExist =
                            NAS.DAL.Util.isExistXpoObject <NAS.DAL.Nomenclature.Item.Item>
                                ("Code", itemEntity.Code,
                                Constant.ROWSTATUS_ACTIVE,
                                Constant.ROWSTATUS_DEFAULT,
                                Constant.ROWSTATUS_INACTIVE);
                        if (isExist)
                        {
                            continue;
                        }
                        //Get item trading type
                        ItemTradingType itemTradingType =
                            Util.getXPCollection <ItemTradingType>(uow, "Name", itemTradingTypeName).FirstOrDefault();
                        //Get Manufacturer
                        ManufacturerOrg manufacturerOrg =
                            Util.getXPCollection <ManufacturerOrg>(uow, "Code", itemEntity.ManufacturerCode,
                                                                   Constant.ROWSTATUS_ACTIVE).FirstOrDefault();

                        if (manufacturerOrg == null)
                        {
                            manufacturerOrg = Util.getDefaultXpoObject <ManufacturerOrg>(uow);
                        }

                        //Insert into Item table
                        NAS.DAL.Nomenclature.Item.Item item = new NAS.DAL.Nomenclature.Item.Item(uow)
                        {
                            Code                 = itemEntity.Code,
                            Description          = itemEntity.Description,
                            ManufacturerOrgId    = manufacturerOrg,
                            ItemTradingTypeId    = itemTradingType,
                            Name                 = itemEntity.Name,
                            RowStatus            = Constant.ROWSTATUS_ACTIVE,
                            RowCreationTimeStamp = DateTime.Now
                        };
                        item.Save();

                        //Get Supplier
                        SupplierOrg supplierOrg = Util.getXPCollection <SupplierOrg>(uow, "Code", itemEntity.SupplierCode,
                                                                                     Constant.ROWSTATUS_ACTIVE).FirstOrDefault();
                        if (supplierOrg != null)
                        {
                            //Insert into ItemSupplier table
                            ItemSupplier itemSupplier = new ItemSupplier(uow)
                            {
                                ItemId        = item,
                                SupplierOrgId = supplierOrg
                            };
                            itemSupplier.Save();
                        }

                        ObjectType objectType = Util.getXPCollection <ObjectType>(uow, "Name", objectTypeName,
                                                                                  Constant.ROWSTATUS_ACTIVE).FirstOrDefault();
                        if (objectType != null)
                        {
                            //Insert into ItemSupplier table
                            ItemCustomType itemCustomType = new ItemCustomType(uow)
                            {
                                ItemId       = item,
                                ObjectTypeId = objectType
                            };
                            itemCustomType.Save();
                        }

                        uow.CommitChanges();

                        //using (Session itemUnitSession = XpoHelper.GetNewSession())
                        //{
                        //    //Get UNIT relation type
                        //    ItemUnitRelationType unitRelationType =
                        //        NAS.DAL.Util.getXPCollection<ItemUnitRelationType>(itemUnitSession, "Name", "UNIT").FirstOrDefault();
                        //    itemEntity.ItemUnits = itemEntity.ItemUnits.OrderBy(r => r.Level).ToList();

                        //    ////Insert into ItemUnit
                        //    foreach (ItemUnitEntity itemUnitEntity in itemEntity.ItemUnits)
                        //    {

                        //        NAS.DAL.Nomenclature.Item.Item itemTemp =
                        //            NAS.DAL.Util.getXPCollection<NAS.DAL.Nomenclature.Item.Item>
                        //                (itemUnitSession, "Code", itemUnitEntity.ItemCode).FirstOrDefault();

                        //        Unit unit =
                        //            NAS.DAL.Util.getXPCollection<Unit>(itemUnitSession, "Code", itemUnitEntity.UnitCode).FirstOrDefault();

                        //        if (unit == null)
                        //            break;

                        //        Unit parentUnit =
                        //            NAS.DAL.Util.getXPCollection<Unit>(itemUnitSession, "Code", itemUnitEntity.ParentUnitCode).FirstOrDefault();

                        //        ItemUnit parentItemUnit = itemTemp.ItemUnits.Where(r => r.UnitId == parentUnit).FirstOrDefault();

                        //        ItemUnit itemUnit = new ItemUnit(itemUnitSession)
                        //        {
                        //            ItemId = itemTemp,
                        //            ItemUnitRelationTypeId = unitRelationType,
                        //            NumRequired = itemUnitEntity.NumRequired,
                        //            RowStatus = Constant.ROWSTATUS_ACTIVE,
                        //            UnitId = unit,
                        //            ParentItemUnitId = parentItemUnit,
                        //            RowCreationTimeStamp = DateTime.Now
                        //        };
                        //        itemUnit.Save();
                        //    }
                        //}
                    }
                    catch (Exception ex)
                    {
                        string msg = ex.Message;
                    }
                }
            }
        }
Ejemplo n.º 12
0
        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;
            }
        }
Ejemplo n.º 13
0
Archivo: ItemBO.cs Proyecto: 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;
            }
        }
Ejemplo n.º 14
0
Archivo: Util.cs Proyecto: ewin66/dev
        /// <summary>
        /// Populate default data to database
        /// </summary>
        public static void Populate()
        {
            try
            {
                ////NAS.DAL.Accounting.AccountChart
                NAS.DAL.BI.Accounting.Account.CorrespondFinancialAccountDim.Populate();
                NAS.DAL.BI.Accounting.Account.FinancialAccountDim.Populate();
                Account.Populate();
                AccountType.Populate();
                AccountCategory.Populate();
                Currency.Populate();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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