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 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.º 3
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;
            }
        }