Пример #1
0
        public static void Populate()
        {
            Session session = null;

            try
            {
                session = XpoHelper.GetNewSession();
                //insert default data into CodeRuleDataType table

                if (!Util.isExistXpoObject <CodeRuleDataType>("Code", "STRING"))
                {
                    CodeRuleDataType codeRuleDataType = new CodeRuleDataType(session)
                    {
                        Code        = "STRING",
                        Name        = "Chuỗi",
                        Description = "Chuỗi kí tự"
                    };
                    codeRuleDataType.Save();
                }

                if (!Util.isExistXpoObject <CodeRuleDataType>("Code", "DATETIME"))
                {
                    CodeRuleDataType codeRuleDataType = new CodeRuleDataType(session)
                    {
                        Code        = "DATETIME",
                        Name        = "Ngày tháng",
                        Description = "Ngày tháng"
                    };
                    codeRuleDataType.Save();
                }

                if (!Util.isExistXpoObject <CodeRuleDataType>("Code", "NUMBER"))
                {
                    CodeRuleDataType codeRuleDataType = new CodeRuleDataType(session)
                    {
                        Code        = "NUMBER",
                        Name        = "Số",
                        Description = "Số"
                    };
                    codeRuleDataType.Save();
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
Пример #2
0
        public static void Populate()
        {
            Session session = null;

            try
            {
                session = XpoHelper.GetNewSession();

                CodeRuleDataType.Populate();
                //insert default data into CodeRuleDataFormat table

                #region STRING

                //Get STRING data type
                CodeRuleDataType stringDataType =
                    Util.getXPCollection <CodeRuleDataType>(session, "Code", "STRING").FirstOrDefault();

                if (!Util.isExistXpoObject <CodeRuleDataFormat>("Code", "NORMAL"))
                {
                    CodeRuleDataFormat codeRuleDataFormat = new CodeRuleDataFormat(session)
                    {
                        Code               = "NORMAL",
                        Name               = "Không định dạng",
                        Description        = "Không định dạng",
                        FormatString       = "{0}",
                        CodeRuleDataTypeId = stringDataType
                    };
                    codeRuleDataFormat.Save();
                }

                if (!Util.isExistXpoObject <CodeRuleDataFormat>("Code", "LOWERCASE"))
                {
                    CodeRuleDataFormat codeRuleDataFormat = new CodeRuleDataFormat(session)
                    {
                        Code               = "LOWERCASE",
                        Name               = "Chữ thường",
                        Description        = "Chữ thường",
                        FormatString       = "{0}",
                        CodeRuleDataTypeId = stringDataType
                    };
                    codeRuleDataFormat.Save();
                }

                if (!Util.isExistXpoObject <CodeRuleDataFormat>("Code", "UPPERCASE"))
                {
                    CodeRuleDataFormat codeRuleDataFormat = new CodeRuleDataFormat(session)
                    {
                        Code               = "UPPERCASE",
                        Name               = "Chữ hoa",
                        Description        = "Chữ hoa",
                        FormatString       = "{0}",
                        CodeRuleDataTypeId = stringDataType
                    };
                    codeRuleDataFormat.Save();
                }

                //if (!Util.isExistXpoObject<CodeRuleDataFormat>("Code", "ACSII"))
                //{
                //    CodeRuleDataFormat codeRuleDataFormat = new CodeRuleDataFormat(session)
                //    {
                //        Code = "ACSII",
                //        Name = "Chữ không dấu",
                //        Description = "Chữ không dấu",
                //        FormatString = "{0}",
                //        CodeRuleDataTypeId = stringDataType
                //    };
                //    codeRuleDataFormat.Save();
                //}

                //if (!Util.isExistXpoObject<CodeRuleDataFormat>("Code", "UPPERCASE_ACSII"))
                //{
                //    CodeRuleDataFormat codeRuleDataFormat = new CodeRuleDataFormat(session)
                //    {
                //        Code = "UPPERCASE_ACSII",
                //        Name = "Chữ hoa không dấu",
                //        Description = "Chữ hoa không dấu",
                //        FormatString = "{0}",
                //        CodeRuleDataTypeId = stringDataType
                //    };
                //    codeRuleDataFormat.Save();
                //}

                //if (!Util.isExistXpoObject<CodeRuleDataFormat>("Code", "LOWERCASE_ACSII"))
                //{
                //    CodeRuleDataFormat codeRuleDataFormat = new CodeRuleDataFormat(session)
                //    {
                //        Code = "LOWERCASE_ACSII",
                //        Name = "Chữ thường không dấu",
                //        Description = "Chữ thường không dấu",
                //        FormatString = "{0}",
                //        CodeRuleDataTypeId = stringDataType
                //    };
                //    codeRuleDataFormat.Save();
                //}

                #endregion

                #region DATETIME
                //Get DATETIME data type
                CodeRuleDataType datetimeDataType =
                    Util.getXPCollection <CodeRuleDataType>(session, "Code", "DATETIME").FirstOrDefault();

                if (!Util.isExistXpoObject <CodeRuleDataFormat>("Code", "YEAR"))
                {
                    CodeRuleDataFormat codeRuleDataFormat = new CodeRuleDataFormat(session)
                    {
                        Code               = "YEAR",
                        Name               = "yyyy(năm)",
                        Description        = "Năm",
                        FormatString       = "{0:yyyy}",
                        CodeRuleDataTypeId = datetimeDataType
                    };
                    codeRuleDataFormat.Save();
                }

                if (!Util.isExistXpoObject <CodeRuleDataFormat>("Code", "MONTH"))
                {
                    CodeRuleDataFormat codeRuleDataFormat = new CodeRuleDataFormat(session)
                    {
                        Code               = "MONTH",
                        Name               = "MM(tháng)",
                        Description        = "Tháng",
                        FormatString       = "{0:MM}",
                        CodeRuleDataTypeId = datetimeDataType
                    };
                    codeRuleDataFormat.Save();
                }

                if (!Util.isExistXpoObject <CodeRuleDataFormat>("Code", "DAY"))
                {
                    CodeRuleDataFormat codeRuleDataFormat = new CodeRuleDataFormat(session)
                    {
                        Code               = "DAY",
                        Name               = "dd(ngày)",
                        Description        = "Ngày",
                        FormatString       = "{0:dd}",
                        CodeRuleDataTypeId = datetimeDataType
                    };
                    codeRuleDataFormat.Save();
                }

                if (!Util.isExistXpoObject <CodeRuleDataFormat>("Code", "HOUR"))
                {
                    CodeRuleDataFormat codeRuleDataFormat = new CodeRuleDataFormat(session)
                    {
                        Code               = "HOUR",
                        Name               = "HH(giờ)",
                        Description        = "Giờ",
                        FormatString       = "{0:HH}",
                        CodeRuleDataTypeId = datetimeDataType
                    };
                    codeRuleDataFormat.Save();
                }

                if (!Util.isExistXpoObject <CodeRuleDataFormat>("Code", "MINUTE"))
                {
                    CodeRuleDataFormat codeRuleDataFormat = new CodeRuleDataFormat(session)
                    {
                        Code               = "MINUTE",
                        Name               = "mm(phút)",
                        Description        = "Phút",
                        FormatString       = "{0:mm}",
                        CodeRuleDataTypeId = datetimeDataType
                    };
                    codeRuleDataFormat.Save();
                }

                if (!Util.isExistXpoObject <CodeRuleDataFormat>("Code", "SECOND"))
                {
                    CodeRuleDataFormat codeRuleDataFormat = new CodeRuleDataFormat(session)
                    {
                        Code               = "SECOND",
                        Name               = "ss(giây)",
                        Description        = "Giây",
                        FormatString       = "{0:ss}",
                        CodeRuleDataTypeId = datetimeDataType
                    };
                    codeRuleDataFormat.Save();
                }
                #endregion

                #region NUMBER
                //Get NUMBER data type
                CodeRuleDataType numberDataType =
                    Util.getXPCollection <CodeRuleDataType>(session, "Code", "NUMBER").FirstOrDefault();

                if (!Util.isExistXpoObject <CodeRuleDataFormat>("Code", "DECIMAL"))
                {
                    CodeRuleDataFormat codeRuleDataFormat = new CodeRuleDataFormat(session)
                    {
                        Code               = "DECIMAL",
                        Name               = "Số thập phân",
                        Description        = "Số thập phân",
                        FormatString       = "{0:D}",
                        CodeRuleDataTypeId = numberDataType
                    };
                    codeRuleDataFormat.Save();
                }

                if (!Util.isExistXpoObject <CodeRuleDataFormat>("Code", "DECIMAL_WITH_GROUP"))
                {
                    CodeRuleDataFormat codeRuleDataFormat = new CodeRuleDataFormat(session)
                    {
                        Code               = "DECIMAL_WITH_GROUP",
                        Name               = "Số thập phân có dấu phân cách hàng nghìn",
                        Description        = "Số thập phân có dấu phân cách hàng nghìn",
                        FormatString       = "{0:#,###}",
                        CodeRuleDataTypeId = numberDataType
                    };
                    codeRuleDataFormat.Save();
                }
                #endregion
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }