Exemplo n.º 1
0
        private string execute(salsum s)
        {
            SqlDbAccess dbAccess = new SqlDbAccess(PKDBHelper.ConnectString);
            dbAccess.CommandTimeout = 120;
            string jsonset = string.Empty;

            if (("{SLT}{SLT2}{SLT3}").IndexOf("{" + s.rmode + "}") >= 0)
            {
                string query = @"MBL_SALSUM_Q1";
                SqlParamCollection parameters = new SqlParamCollection();

                PKDBHelper.SqlAddParam(parameters, "@INFDS", SqlDbType.VarChar, 100, s.infds);
                PKDBHelper.SqlAddParam(parameters, "@RTNCD", SqlDbType.VarChar, 100, s.rtncd);
                PKDBHelper.SqlAddParam(parameters, "@RMODE", SqlDbType.VarChar, 20, s.rmode);
                PKDBHelper.SqlAddParam(parameters, "@TDATE", SqlDbType.VarChar, 8, s.tdate);
                PKDBHelper.SqlAddParam(parameters, "@SLTTG", SqlDbType.VarChar, 10, s.slttg);

                DataTable  dt = dbAccess.ExecuteSpDataSet(query, parameters).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    return JsonConvert.SerializeObject(dt); //, Formatting.Indented);
                }
                else
                {
                    return string.Empty;
                }
            }
            else
            {
                return string.Empty;
            }
        }
Exemplo n.º 2
0
        private string execute(pgmmas p)
        {
            SqlDbAccess dbAccess = new SqlDbAccess(PKDBHelper.ConnectString);
            string jsonset = string.Empty;

            if (("{SLT}").IndexOf("{" + p.rmode + "}") >= 0)
            {
                string query = @"SYS_PGMMAS_Q1";
                SqlParamCollection parameters = new SqlParamCollection();

                PKDBHelper.SqlAddParam(parameters, "@INFDS", SqlDbType.VarChar, 100, p.infds);
                PKDBHelper.SqlAddParam(parameters, "@RTNCD", SqlDbType.VarChar, 100, p.rtncd);
                PKDBHelper.SqlAddParam(parameters, "@RMODE", SqlDbType.VarChar, 20, p.rmode);
                PKDBHelper.SqlAddParam(parameters, "@USRID", SqlDbType.VarChar, 10, p.usrid);
                PKDBHelper.SqlAddParam(parameters, "@USRTY", SqlDbType.VarChar, 10, p.usrty);
                PKDBHelper.SqlAddParam(parameters, "@SYSCD", SqlDbType.VarChar, 20, p.syscd);
                PKDBHelper.SqlAddParam(parameters, "@ISMBL", SqlDbType.VarChar, 1, p.ismbl);

                DataTable  dt = dbAccess.ExecuteSpDataSet(query, parameters).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    return JsonConvert.SerializeObject(dt, Formatting.Indented);
                }
                else
                {
                    return string.Empty;
                }
            }
            else
            {
                return string.Empty;
            }
        }
Exemplo n.º 3
0
        private string execute(usrmas p)
        {
            SqlDbAccess dbAccess = new SqlDbAccess(PKDBHelper.ConnectString);
            string jsonset = string.Empty;

            if (("{CHKUSR}{CHKAUTH}{SLT}").IndexOf("{" + p.rmode + "}") >= 0)
            {
                string query = @"MBL_USRMAS_M1";
                SqlParamCollection parameters = new SqlParamCollection();

                PKDBHelper.SqlAddParam(parameters, "@INFDS", SqlDbType.VarChar, 100, p.infds);
                PKDBHelper.SqlAddParam(parameters, "@RTNCD", SqlDbType.VarChar, 100, p.rtncd);
                PKDBHelper.SqlAddParam(parameters, "@RMODE", SqlDbType.VarChar, 20, p.rmode);
                PKDBHelper.SqlAddParam(parameters, "@USRID", SqlDbType.VarChar, 10, p.usrid);
                PKDBHelper.SqlAddParam(parameters, "@PASWD", SqlDbType.VarChar, 10, p.paswd);
                PKDBHelper.SqlAddParam(parameters, "@IPADR", SqlDbType.VarChar, 20, p.ipadr);
                PKDBHelper.SqlAddParam(parameters, "@FDATE", SqlDbType.Char, 8, p.fdate);
                PKDBHelper.SqlAddParam(parameters, "@TDATE", SqlDbType.Char, 8, p.tdate);
                PKDBHelper.SqlAddParam(parameters, "@SSNID", SqlDbType.VarChar, 50, p.ssnid);
                PKDBHelper.SqlAddParam(parameters, "@FRMNM", SqlDbType.VarChar, 100, p.frmnm);

                //PKDBHelper.SqlAddParam(parameters, "@DPTCD", SqlDbType.Char, 20, p.dptcd);
                //PKDBHelper.SqlAddParam(parameters, "@USEYN", SqlDbType.Char, 1, p.useyn);

                DataTable  dt = dbAccess.ExecuteSpDataSet(query, parameters).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    return JsonConvert.SerializeObject(dt, Formatting.Indented);

                    //if (dt.Rows[0]["RESULT"].ToString() == "OK")
                    //{
                    //    return "OK";
                    //}
                    //else
                    //{
                    //    if (dt.Rows[0]["MSGID"].ToString() == "ERR0008")
                    //    {
                    //        return "ERR_USER";
                    //        //PKMessageBox.ShowError("사용자가 등록되어 있지 않습니다!", DialogButtons.Ok, "로그인 에러");
                    //    }
                    //    else
                    //    {
                    //        return "ERR_PWD";
                    //        //PKMessageBox.ShowError("비밀번호를 다시 입력하세요!", DialogButtons.Ok, "로그인 에러");

                    //    }
                    //}
                }
                else
                {
                    return string.Empty;
                }
            }
            else
            {
                return string.Empty;
            }
        }
Exemplo n.º 4
0
        private string execute(dptmas d)
        {
            SqlDbAccess dbAccess = new SqlDbAccess(PKDBHelper.ConnectString);
            string jsonset = string.Empty;

            if (("{SLT}").IndexOf("{" + d.rmode + "}") >= 0)
            {
                string query = @"MBL_DPTMAS_M1";
                SqlParamCollection parameters = new SqlParamCollection();

                PKDBHelper.SqlAddParam(parameters, "@INFDS", SqlDbType.VarChar, 100, d.infds);
                PKDBHelper.SqlAddParam(parameters, "@RTNCD", SqlDbType.VarChar, 100, d.rtncd);
                PKDBHelper.SqlAddParam(parameters, "@RMODE", SqlDbType.VarChar, 20, d.rmode);
                PKDBHelper.SqlAddParam(parameters, "@DPTCD", SqlDbType.VarChar, 10, d.dptcd);

                DataTable  dt = dbAccess.ExecuteSpDataSet(query, parameters).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        if(dt.Rows[i]["HPTEL"].ToString().Trim()!=string.Empty)
                        {
                            dt.Rows[i]["HPTEL"] = CryptoHelper.DecryptText(dt.Rows[i]["HPTEL"].ToString().Trim());
                        }

                        if (dt.Rows[i]["EMAIL"].ToString().Trim() != string.Empty)
                        {
                            dt.Rows[i]["EMAIL"] = CryptoHelper.DecryptText(dt.Rows[i]["EMAIL"].ToString().Trim());
                        }

                        if (dt.Rows[i]["TELNO"].ToString().Trim() != string.Empty)
                        {
                            dt.Rows[i]["TELNO"] = CryptoHelper.DecryptText(dt.Rows[i]["TELNO"].ToString().Trim());
                        }

                        //if (dt.Rows[i]["GNAME"].ToString().Trim() != string.Empty)
                        //{
                        //    dt.Rows[i]["GNAME"] = "XXX"; //dt.Rows[i]["GNAME"].ToString().Trim().Replace('(', 'X').Replace(')', 'Y');
                        //}
                    }

                    return JsonConvert.SerializeObject(dt); //, Formatting.Indented);
                }
                else
                {
                    return string.Empty;
                }
            }
            else
            {
                return string.Empty;
            }
        }
        private IEnumerable<string> DeployRun(string action, ComponentRunContext runContext)
        {
            var sb = new StringBuilder();
            var dbName = SqlUtils.ToBracketedIdentifier(mDatabaseInfo.Name);
            var sqlParams = new SqlParamCollection();

            sb.AppendFormat(
                "USE [master]\n" +
                "IF db_id(@dbName) IS NOT NULL\n" +
                "  ALTER DATABASE {0} SET SINGLE_USER WITH ROLLBACK IMMEDIATE\n" +
                "RESTORE DATABASE {0} FROM DISK = @backupFile WITH FILE = 1, NOUNLOAD, STATS = 5",
                dbName);

            sqlParams.Add("@dbName", SqlDbType.NVarChar).Value = mDatabaseInfo.Name;
            sqlParams.Add("@backupFile", SqlDbType.NVarChar).Value = mDatabaseInfo.BackupFilePath;

            if (mDatabaseInfo.Relocate)
            {
                var names = SqlUtils.GetLogicalAndPhysicalNamesFromBackupFile(mDatabaseInfo.Connection, mDatabaseInfo.BackupFilePath);

                var i = 0;
                foreach (var tuple in names)
                {
                    var logical = string.Format("@l{0}", i);
                    var physical = string.Format("@p{0}", i);
                    sb.AppendFormat(",\n  MOVE {0} TO {1}", logical, physical);

                    var destPath = GetRelocation(tuple.Item2);
                    sqlParams.Add(logical, SqlDbType.NVarChar).Value = tuple.Item1;
                    sqlParams.Add(physical, SqlDbType.NVarChar).Value = destPath;

                    ++i;
                }
            }

            sb.AppendFormat(
                "\nALTER DATABASE {0} SET MULTI_USER\n", dbName);

            yield return string.Format("Restoring {0}", mDatabaseInfo.Name);

            if (!runContext.DryRun)
            {
                using (var process = SqlUtils.Exec(mDatabaseInfo.Connection, sb.ToString(), sqlParams))
                {
                    foreach (var processOutputLine in process.GetOutput())
                    {
                        yield return processOutputLine.Line;
                    }
                }
            }

            yield return "Database restore completed.";
        }
Exemplo n.º 6
0
        public static IProcessExecutionResult BackupDatabase(DatabaseConnectionConfig databaseConnection, string dbName, string backupFilePath, bool compress)
        {
            var sb = new StringBuilder();
            sb.AppendFormat("BACKUP DATABASE {0} TO DISK = @backupFile WITH FORMAT, INIT, NAME = @name, SKIP, NOREWIND, NOUNLOAD, STATS = 10",
                ToBracketedIdentifier(dbName));

            var parameters = new SqlParamCollection();
            parameters.Add("@backupFile", SqlDbType.NVarChar).Value = backupFilePath;
            parameters.Add("@name", SqlDbType.NVarChar).Value = dbName;

            if (compress)
                sb.Append(", COMPRESSION");

            return new SqlCommandExecutionResult(databaseConnection, dbName, sb.ToString(), parameters);
        }
        public Error.Types Update(
            Context context,
            SiteSettings ss,
            SqlParamCollection param = null,
            List <SqlStatement> additionalStatements = null,
            bool otherInitValue = false,
            bool setBySession   = true,
            bool get            = true)
        {
            if (setBySession)
            {
                SetBySession(context: context);
            }
            var timestamp  = Timestamp.ToDateTime();
            var statements = new List <SqlStatement>();

            UpdateStatements(
                context: context,
                ss: ss,
                statements: statements,
                timestamp: timestamp,
                param: param,
                otherInitValue: otherInitValue,
                additionalStatements: additionalStatements);
            var response = Rds.ExecuteScalar_response(
                context: context,
                transactional: true,
                statements: statements.ToArray());

            if (response.Count == 0)
            {
                return(Error.Types.UpdateConflicts);
            }
            if (get)
            {
                Get(context: context);
            }
            return(Error.Types.None);
        }
Exemplo n.º 8
0
        public Error.Types UpdateOrCreate(
            RdsUser rdsUser          = null,
            SqlWhereCollection where = null,
            SqlParamCollection param = null)
        {
            SetBySession();
            var statements = new List <SqlStatement>
            {
                Rds.UpdateOrInsertMailAddresses(
                    where : where ?? Rds.MailAddressesWhereDefault(this),
                    param: param ?? Rds.MailAddressesParamDefault(this, setDefault: true))
            };
            var response = Rds.ExecuteScalar_response(
                rdsUser: rdsUser,
                transactional: true,
                selectIdentity: true,
                statements: statements.ToArray());

            MailAddressId = (response.Identity ?? MailAddressId).ToLong();
            Get();
            return(Error.Types.None);
        }
 public ErrorData UpdateOrCreate(
     Context context,
     SqlWhereCollection where = null,
     SqlParamCollection param = null)
 {
     SetBySession(context: context);
     var statements = new List<SqlStatement>
     {
         Rds.UpdateOrInsertExportSettings(
             where: where ?? Rds.ExportSettingsWhereDefault(this),
             param: param ?? Rds.ExportSettingsParamDefault(
                 context: context, exportSettingModel: this, setDefault: true))
     };
     var response = Rds.ExecuteScalar_response(
         context: context,
         transactional: true,
         selectIdentity: true,
         statements: statements.ToArray());
     ExportSettingId = (response.Id ?? ExportSettingId).ToLong();
     Get(context: context);
     return new ErrorData(type: Error.Types.None);
 }
Exemplo n.º 10
0
        private IEnumerable <DataRow> Get(
            IContext context,
            SqlColumnCollection column   = null,
            SqlJoinCollection join       = null,
            SqlWhereCollection where     = null,
            SqlOrderByCollection orderBy = null,
            SqlParamCollection param     = null,
            Sqls.TableTypes tableType    = Sqls.TableTypes.Normal,
            bool distinct    = false,
            int top          = 0,
            int offset       = 0,
            int pageSize     = 0,
            bool history     = false,
            bool countRecord = false)
        {
            var statements = new List <SqlStatement>
            {
                Rds.SelectUsers(
                    dataTableName: "Main",
                    column: column ?? Rds.UsersDefaultColumns(),
                    join: join ?? Rds.UsersJoinDefault(),
                    where : where,
                    orderBy: orderBy,
                    param: param,
                    tableType: tableType,
                    distinct: distinct,
                    top: top,
                    offset: offset,
                    pageSize: pageSize,
                    countRecord: countRecord)
            };
            var dataSet = Rds.ExecuteDataSet(
                context: context,
                transactional: false,
                statements: statements.ToArray());

            TotalCount = Rds.Count(dataSet);
            return(dataSet.Tables["Main"].AsEnumerable());
        }
Exemplo n.º 11
0
        public Error.Types Create(
            RdsUser rdsUser           = null,
            Sqls.TableTypes tableType = Sqls.TableTypes.Normal,
            SqlParamCollection param  = null,
            bool paramAll             = false,
            bool get = true)
        {
            var statements = new List <SqlStatement>();

            CreateStatements(statements, tableType, param, paramAll);
            var newId = Rds.ExecuteScalar_long(
                rdsUser: rdsUser,
                transactional: true,
                statements: statements.ToArray());

            ExportSettingId = newId != 0 ? newId : ExportSettingId;
            if (get)
            {
                Get();
            }
            return(Error.Types.None);
        }
Exemplo n.º 12
0
        public ErrorData Update(
            Context context,
            SiteSettings ss,
            SqlParamCollection param = null,
            List <SqlStatement> additionalStatements = null,
            bool otherInitValue = false,
            bool setBySession   = true,
            bool get            = true)
        {
            if (setBySession)
            {
                SetBySession(context: context);
            }
            var statements = new List <SqlStatement>();

            statements.AddRange(UpdateStatements(
                                    context: context,
                                    ss: ss,
                                    param: param,
                                    otherInitValue: otherInitValue,
                                    additionalStatements: additionalStatements));
            var response = Rds.ExecuteScalar_response(
                context: context,
                transactional: true,
                statements: statements.ToArray());

            if (response.Event == "Conflicted")
            {
                return(new ErrorData(
                           type: Error.Types.UpdateConflicts,
                           id: OutgoingMailId));
            }
            if (get)
            {
                Get(context: context);
            }
            Libraries.Search.Indexes.Create(context, ss, ReferenceId, force: true);
            return(new ErrorData(type: Error.Types.None));
        }
Exemplo n.º 13
0
 public Error.Types Update(
     RdsUser rdsUser = null,
     SqlParamCollection param = null,
     List<SqlStatement> additionalStatements = null,
     bool otherInitValue = false,
     bool get = true)
 {
     SetBySession();
     var timestamp = Timestamp.ToDateTime();
     var statements = new List<SqlStatement>();
     UpdateStatements(statements, timestamp, param, otherInitValue, additionalStatements);
     var response = Rds.ExecuteScalar_response(
         rdsUser: rdsUser,
         transactional: true,
         statements: statements.ToArray());
     if (response.Count == 0) return Error.Types.UpdateConflicts;
     if (get) Get();
     var siteModel = new ItemModel(ReferenceId).GetSite();
     var ss = SiteSettingsUtilities.Get(siteModel, siteModel.SiteId);
     Libraries.Search.Indexes.Create(ss, ReferenceId, force: true);
     return Error.Types.None;
 }
Exemplo n.º 14
0
 public List <SqlStatement> CreateStatements(
     SiteSettings ss,
     Sqls.TableTypes tableType = Sqls.TableTypes.Normal,
     SqlParamCollection param  = null,
     bool paramAll             = false)
 {
     return(new List <SqlStatement>
     {
         Rds.InsertGroups(
             tableType: tableType,
             selectIdentity: true,
             param: param ?? Rds.GroupsParamDefault(
                 this, setDefault: true, paramAll: paramAll)),
         Rds.InsertGroupMembers(
             tableType: tableType,
             param: param ?? Rds.GroupMembersParam()
             .GroupId(raw: Def.Sql.Identity)
             .UserId(Sessions.UserId())
             .Admin(true)),
         StatusUtilities.UpdateStatus(StatusUtilities.Types.GroupsUpdated)
     });
 }
Exemplo n.º 15
0
 public List <SqlStatement> CreateStatements(
     List <SqlStatement> statements,
     SiteSettings ss,
     Sqls.TableTypes tableType = Sqls.TableTypes.Normal,
     SqlParamCollection param  = null,
     bool otherInitValue       = false)
 {
     statements.AddRange(new List <SqlStatement>
     {
         Rds.InsertItems(
             selectIdentity: true,
             param: Rds.ItemsParam()
             .ReferenceType("Wikis")
             .SiteId(SiteId)
             .Title(Title.DisplayValue)),
         Rds.InsertWikis(
             tableType: tableType,
             param: param ?? Rds.WikisParamDefault(
                 this, setDefault: true, otherInitValue: otherInitValue)),
     });
     return(statements);
 }
Exemplo n.º 16
0
 private List <SqlStatement> UpdateStatements(
     List <SqlStatement> statements,
     DateTime timestamp,
     SqlParamCollection param,
     bool paramAll = false,
     List <SqlStatement> additionalStatements = null)
 {
     statements.AddRange(new List <SqlStatement>
     {
         Rds.UpdateBinaries(
             verUp: VerUp,
             where : Rds.BinariesWhereDefault(this)
             .UpdatedTime(timestamp, _using: timestamp.InRange()),
             param: param ?? Rds.BinariesParamDefault(this, paramAll: paramAll),
             countRecord: true)
     });
     if (additionalStatements?.Any() == true)
     {
         statements.AddRange(additionalStatements);
     }
     return(statements);
 }
Exemplo n.º 17
0
 private List <SqlStatement> UpdateStatements(
     Context context,
     string dataTableName     = null,
     SqlWhereCollection where = null,
     SqlParamCollection param = null,
     bool otherInitValue      = false)
 {
     return(new List <SqlStatement>
     {
         Rds.UpdateDepts(
             dataTableName: dataTableName,
             where : where,
             param: param ?? Rds.DeptsParamDefault(
                 context: context,
                 deptModel: this,
                 otherInitValue: otherInitValue)),
         new SqlStatement(Def.Sql.IfConflicted.Params(DeptId)),
         StatusUtilities.UpdateStatus(
             tenantId: context.TenantId,
             type: StatusUtilities.Types.DeptsUpdated),
     });
 }
Exemplo n.º 18
0
        public Error.Types Create(
            SiteSettings ss,
            RdsUser rdsUser           = null,
            Sqls.TableTypes tableType = Sqls.TableTypes.Normal,
            SqlParamCollection param  = null,
            bool notice   = false,
            bool paramAll = false,
            bool get      = true)
        {
            var statements = CreateStatements(ss, tableType, param, paramAll);
            var newId      = Rds.ExecuteScalar_long(
                rdsUser: rdsUser,
                transactional: true,
                statements: statements.ToArray());

            WikiId = newId != 0 ? newId : WikiId;
            if (Contract.Notice() && notice)
            {
                SetTitle(ss);
                CheckNotificationConditions(ss);
                Notice(ss, "Created");
            }
            if (get)
            {
                Get(ss);
            }
            var fullText = FullText(ss, onCreating: true);

            Rds.ExecuteNonQuery(
                rdsUser: rdsUser,
                statements: Rds.UpdateItems(
                    param: Rds.ItemsParam()
                    .Title(Title.DisplayValue)
                    .FullText(fullText, _using: fullText != null)
                    .SearchIndexCreatedTime(DateTime.Now, _using: fullText != null),
                    where : Rds.ItemsWhere().ReferenceId(WikiId)));
            Libraries.Search.Indexes.Create(ss, this);
            return(Error.Types.None);
        }
Exemplo n.º 19
0
        public List <SqlStatement> UpdateStatements(
            Context context,
            SiteSettings ss,
            string dataTableName             = null,
            IEnumerable <string> permissions = null,
            bool permissionChanged           = false,
            SqlParamCollection param         = null,
            bool otherInitValue = false,
            List <SqlStatement> additionalStatements = null)
        {
            var timestamp  = Timestamp.ToDateTime();
            var statements = new List <SqlStatement>();

            var where = Rds.TenantsWhereDefault(this)
                        .UpdatedTime(timestamp, _using: timestamp.InRange());
            if (Versions.VerUp(
                    context: context,
                    ss: ss,
                    verUp: VerUp))
            {
                statements.Add(Rds.TenantsCopyToStatement(
                                   where : where,
                                   tableType: Sqls.TableTypes.History,
                                   ColumnNames()));
                Ver++;
            }
            statements.AddRange(UpdateStatements(
                                    context: context,
                                    dataTableName: dataTableName,
                                    where : where,
                                    param: param,
                                    otherInitValue: otherInitValue));
            statements.AddRange(UpdateAttachmentsStatements(context: context));
            if (additionalStatements?.Any() == true)
            {
                statements.AddRange(additionalStatements);
            }
            return(statements);
        }
Exemplo n.º 20
0
        public Error.Types Create(
            RdsUser rdsUser           = null,
            Sqls.TableTypes tableType = Sqls.TableTypes.Normal,
            SqlParamCollection param  = null,
            bool otherInitValue       = false,
            bool get = true)
        {
            var statements = new List <SqlStatement>();

            CreateStatements(statements, tableType, param, otherInitValue);
            var newId = Rds.ExecuteScalar_int(
                rdsUser: rdsUser,
                transactional: true,
                statements: statements.ToArray());

            TenantId = newId != 0 ? newId : TenantId;
            if (get)
            {
                Get();
            }
            return(Error.Types.None);
        }
Exemplo n.º 21
0
 public WikiModel Get(
     SiteSettings ss,
     Sqls.TableTypes tableType    = Sqls.TableTypes.Normal,
     SqlColumnCollection column   = null,
     SqlJoinCollection join       = null,
     SqlWhereCollection where     = null,
     SqlOrderByCollection orderBy = null,
     SqlParamCollection param     = null,
     bool distinct = false,
     int top       = 0)
 {
     Set(ss, Rds.ExecuteTable(statements: Rds.SelectWikis(
                                  tableType: tableType,
                                  column: column ?? Rds.WikisEditorColumns(ss),
                                  join: join ?? Rds.WikisJoinDefault(),
                                  where : where ?? Rds.WikisWhereDefault(this),
                                  orderBy: orderBy ?? null,
                                  param: param ?? null,
                                  distinct: distinct,
                                  top: top)));
     return(this);
 }
Exemplo n.º 22
0
        public Error.Types UpdateOrCreate(
            RdsUser rdsUser          = null,
            SqlWhereCollection where = null,
            SqlParamCollection param = null)
        {
            SetBySession();
            var statements = new List <SqlStatement>
            {
                Rds.UpdateOrInsertTemplates(
                    selectIdentity: true,
                    where : where ?? Rds.TemplatesWhereDefault(this),
                    param: param ?? Rds.TemplatesParamDefault(this, setDefault: true))
            };
            var newId = Rds.ExecuteScalar_int(
                rdsUser: rdsUser,
                transactional: true,
                statements: statements.ToArray());

            TemplateId = newId != 0 ? newId : TemplateId;
            Get();
            return(Error.Types.None);
        }
Exemplo n.º 23
0
        public Error.Types Update(
            SiteSettings ss,
            IEnumerable <string> permissions = null,
            bool permissionChanged           = false,
            RdsUser rdsUser          = null,
            SqlParamCollection param = null,
            bool paramAll            = false)
        {
            SetBySession();
            var statements = UpdateStatements(param, paramAll);

            try
            {
                var count = Rds.ExecuteScalar_int(
                    rdsUser: rdsUser,
                    transactional: true,
                    statements: statements.ToArray());
                if (count == 0)
                {
                    return(Error.Types.UpdateConflicts);
                }
            }
            catch (System.Data.SqlClient.SqlException e)
            {
                if (e.Number == 2601)
                {
                    return(Error.Types.LoginIdAlreadyUse);
                }
                else
                {
                    throw;
                }
            }
            Get(ss);
            UpdateMailAddresses();
            SetSiteInfo();
            return(Error.Types.None);
        }
Exemplo n.º 24
0
        public ErrorData Update(
            Context context,
            SiteSettings ss,
            SqlParamCollection param = null,
            List <SqlStatement> additionalStatements = null,
            bool otherInitValue = false,
            bool setBySession   = true,
            bool get            = true)
        {
            if (setBySession)
            {
                SetBySession(context: context);
            }
            var statements = new List <SqlStatement>();

            statements.AddRange(UpdateStatements(
                                    context: context,
                                    ss: ss,
                                    param: param,
                                    otherInitValue: otherInitValue,
                                    additionalStatements: additionalStatements));
            var response = Repository.ExecuteScalar_response(
                context: context,
                transactional: true,
                statements: statements.ToArray());

            if (response.Event == "Conflicted")
            {
                return(new ErrorData(
                           type: Error.Types.UpdateConflicts,
                           id: ExtensionId));
            }
            if (get)
            {
                Get(context: context);
            }
            return(new ErrorData(type: Error.Types.None));
        }
Exemplo n.º 25
0
        public Error.Types UpdateOrCreate(
            Context context,
            SqlWhereCollection where = null,
            SqlParamCollection param = null)
        {
            SetBySession(context: context);
            var statements = new List <SqlStatement>
            {
                Rds.UpdateOrInsertBinaries(
                    where : where ?? Rds.BinariesWhereDefault(this),
                    param: param ?? Rds.BinariesParamDefault(
                        context: context, binaryModel: this, setDefault: true))
            };
            var response = Rds.ExecuteScalar_response(
                context: context,
                transactional: true,
                selectIdentity: true,
                statements: statements.ToArray());

            BinaryId = (response.Identity ?? BinaryId).ToLong();
            Get(context: context);
            return(Error.Types.None);
        }
Exemplo n.º 26
0
        public ErrorData UpdateOrCreate(
            Context context,
            SqlWhereCollection where = null,
            SqlParamCollection param = null)
        {
            SetBySession(context: context);
            var statements = new List <SqlStatement>
            {
                Rds.UpdateOrInsertDemos(
                    where : where ?? Rds.DemosWhereDefault(this),
                    param: param ?? Rds.DemosParamDefault(
                        context: context, demoModel: this, setDefault: true))
            };
            var response = Repository.ExecuteScalar_response(
                context: context,
                transactional: true,
                selectIdentity: true,
                statements: statements.ToArray());

            DemoId = (response.Id ?? DemoId).ToInt();
            Get(context: context);
            return(new ErrorData(type: Error.Types.None));
        }
Exemplo n.º 27
0
        public Error.Types Update(
            RdsUser rdsUser          = null,
            SqlParamCollection param = null,
            bool paramAll            = false,
            bool get = true)
        {
            SetBySession();
            var statements = UpdateStatements(param, paramAll);
            var count      = Rds.ExecuteScalar_int(
                rdsUser: rdsUser,
                transactional: true,
                statements: statements.ToArray());

            if (count == 0)
            {
                return(Error.Types.UpdateConflicts);
            }
            if (get)
            {
                Get();
            }
            return(Error.Types.None);
        }
Exemplo n.º 28
0
        public Error.Types Update(
            SiteSettings ss,
            IEnumerable <string> permissions = null,
            bool permissionChanged           = false,
            RdsUser rdsUser          = null,
            SqlParamCollection param = null,
            bool paramAll            = false)
        {
            SetBySession();
            var statements = UpdateStatements(param, paramAll);
            var count      = Rds.ExecuteScalar_int(
                rdsUser: rdsUser,
                transactional: true,
                statements: statements.ToArray());

            if (count == 0)
            {
                return(Error.Types.UpdateConflicts);
            }
            Get(ss);
            SiteInfo.Reflesh();
            return(Error.Types.None);
        }
 public List<SqlStatement> CreateStatements(
     Context context,
     string dataTableName = null,
     Sqls.TableTypes tableType = Sqls.TableTypes.Normal,
     SqlParamCollection param = null,
     bool otherInitValue = false)
 {
     var statements = new List<SqlStatement>();
     statements.AddRange(new List<SqlStatement>
     {
         Rds.InsertExportSettings(
             dataTableName: dataTableName,
             tableType: tableType,
             selectIdentity: true,
             param: param ?? Rds.ExportSettingsParamDefault(
                 context: context,
                 exportSettingModel: this,
                 setDefault: true,
                 otherInitValue: otherInitValue))
     });
     statements.AddRange(UpdateAttachmentsStatements(context: context));
     return statements;
 }
 public ErrorData Create(
     Context context,
     SiteSettings ss,
     Sqls.TableTypes tableType = Sqls.TableTypes.Normal,
     SqlParamCollection param = null,
     bool otherInitValue = false,
     bool get = true)
 {
     var statements = new List<SqlStatement>();
     statements.AddRange(CreateStatements(
         context: context,
         tableType: tableType,
         param: param,
         otherInitValue: otherInitValue));
     var response = Rds.ExecuteScalar_response(
         context: context,
         transactional: true,
         selectIdentity: true,
         statements: statements.ToArray());
     ExportSettingId = (response.Id ?? ExportSettingId).ToLong();
     if (get) Get(context: context);
     return new ErrorData(type: Error.Types.None);
 }
Exemplo n.º 31
0
        public Error.Types Update(
            RdsUser rdsUser          = null,
            SqlParamCollection param = null,
            bool paramAll            = false)
        {
            SetBySession();
            var statements = UpdateStatements(param, paramAll);
            var count      = Rds.ExecuteScalar_int(
                rdsUser: rdsUser,
                transactional: true,
                statements: statements.ToArray());

            if (count == 0)
            {
                return(Error.Types.UpdateConflicts);
            }
            Get();
            var siteModel = new ItemModel(ReferenceId).GetSite();
            var ss        = SiteSettingsUtilities.Get(siteModel, siteModel.SiteId);

            Libraries.Search.Indexes.Create(ss, ReferenceId);
            return(Error.Types.None);
        }
Exemplo n.º 32
0
        public Error.Types Create(
            RdsUser rdsUser           = null,
            Sqls.TableTypes tableType = Sqls.TableTypes.Normal,
            SqlParamCollection param  = null,
            bool otherInitValue       = false,
            bool get = true)
        {
            var statements = new List <SqlStatement>();

            CreateStatements(statements, tableType, param, otherInitValue);
            var response = Rds.ExecuteScalar_response(
                rdsUser: rdsUser,
                transactional: true,
                selectIdentity: true,
                statements: statements.ToArray());

            HealthId = (response.Identity ?? HealthId).ToLong();
            if (get)
            {
                Get();
            }
            return(Error.Types.None);
        }
Exemplo n.º 33
0
 private List <SqlStatement> UpdateStatements(
     Context context,
     string dataTableName     = null,
     SqlWhereCollection where = null,
     SqlParamCollection param = null,
     bool otherInitValue      = false)
 {
     return(new List <SqlStatement>
     {
         Rds.UpdateMailAddresses(
             dataTableName: dataTableName,
             where : where,
             param: param ?? Rds.MailAddressesParamDefault(
                 context: context,
                 mailAddressModel: this,
                 otherInitValue: otherInitValue)),
         new SqlStatement(Def.Sql.IfConflicted.Params(MailAddressId))
         {
             IfConflicted = true,
             Id = MailAddressId
         }
     });
 }
Exemplo n.º 34
0
 public IssueCollection(
     Context context,
     SiteSettings ss,
     SqlColumnCollection column   = null,
     SqlJoinCollection join       = null,
     SqlWhereCollection where     = null,
     SqlOrderByCollection orderBy = null,
     SqlParamCollection param     = null,
     Sqls.TableTypes tableType    = Sqls.TableTypes.Normal,
     bool distinct = false,
     int top       = 0,
     int offset    = 0,
     int pageSize  = 0,
     bool get      = true,
     List <FormData> formDataSet = null)
 {
     if (get)
     {
         Set(
             context: context,
             ss: ss,
             dataRows: Get(
                 context: context,
                 ss: ss,
                 column: column,
                 join: join,
                 where : where,
                 orderBy: orderBy,
                 param: param,
                 tableType: tableType,
                 distinct: distinct,
                 top: top,
                 offset: offset,
                 pageSize: pageSize),
             formDataSet: formDataSet);
     }
 }
Exemplo n.º 35
0
 public MailAddressModel Get(
     Context context,
     Sqls.TableTypes tableType    = Sqls.TableTypes.Normal,
     SqlColumnCollection column   = null,
     SqlJoinCollection join       = null,
     SqlWhereCollection where     = null,
     SqlOrderByCollection orderBy = null,
     SqlParamCollection param     = null,
     bool distinct = false,
     int top       = 0)
 {
     Set(context, Rds.ExecuteTable(
             context: context,
             statements: Rds.SelectMailAddresses(
                 tableType: tableType,
                 column: column ?? Rds.MailAddressesDefaultColumns(),
                 join: join ?? Rds.MailAddressesJoinDefault(),
                 where : where ?? Rds.MailAddressesWhereDefault(this),
                 orderBy: orderBy,
                 param: param,
                 distinct: distinct,
                 top: top)));
     return(this);
 }
        public ErrorData UpdateOrCreate(
            Context context,
            SiteSettings ss,
            SqlWhereCollection where = null,
            SqlParamCollection param = null)
        {
            SetBySession(context: context);
            var statements = new List <SqlStatement>
            {
                Rds.UpdateOrInsertRegistrations(
                    where : where ?? Rds.RegistrationsWhereDefault(this),
                    param: param ?? Rds.RegistrationsParamDefault(
                        context: context, registrationModel: this, setDefault: true)),
            };
            var response = Rds.ExecuteScalar_response(
                context: context,
                transactional: true,
                selectIdentity: true,
                statements: statements.ToArray());

            RegistrationId = (response.Id ?? RegistrationId).ToInt();
            Get(context: context, ss: ss);
            return(new ErrorData(type: Error.Types.None));
        }
Exemplo n.º 37
0
 public static void SqlAddParam(SqlParamCollection pCols, string parameterName, System.Data.SqlDbType dbType, int size, System.Data.ParameterDirection direction, dynamic defaultVal, dynamic elementValue)
 {
     pCols.Add(parameterName, dbType, size, direction, elementValue == null ? defaultVal : elementValue);
 }
        private void RestoreDatabase(DatabaseBackupInfo db, bool dryRun, ILog log)
        {
            var sb = new StringBuilder();
            var dbName = SqlUtils.ToBracketedIdentifier(db.Name);
            var sqlParams = new SqlParamCollection();

            sb.AppendFormat(
                "USE [master]\n" +
                "IF db_id(@dbName) IS NOT NULL\n" +
                "  ALTER DATABASE {0} SET SINGLE_USER WITH ROLLBACK IMMEDIATE\n" +
                "RESTORE DATABASE {0} FROM DISK = @backupFile WITH FILE = 1, NOUNLOAD, STATS = 5",
                dbName);

            sqlParams.Add("@dbName", SqlDbType.NVarChar).Value = db.Name;
            sqlParams.Add("@backupFile", SqlDbType.NVarChar).Value = db.BackupFilePath;

            if (mDatabaseConnection.Relocate)
            {
                var names = SqlUtils.GetLogicalAndPhysicalNamesFromBackupFile(mDatabaseConnection, db.BackupFilePath);

                var i = 0;
                foreach (var tuple in names)
                {
                    var logical = string.Format("@l{0}", i);
                    var physical = string.Format("@p{0}", i);
                    sb.AppendFormat(",\n  MOVE {0} TO {1}", logical, physical);

                    var destPath = GetRelocation(db.Name, mDatabaseConnection.RelocatePath, tuple.Item2);
                    sqlParams.Add(logical, SqlDbType.NVarChar).Value = tuple.Item1;
                    sqlParams.Add(physical, SqlDbType.NVarChar).Value = destPath;

                    ++i;
                }
            }

            sb.AppendFormat(
                "\nALTER DATABASE {0} SET MULTI_USER\n", dbName);

            log.LogFormat("Restoring {0} from {1}", db.Name, db.BackupFilePath);

            if (!dryRun)
            {
                using (var process = SqlUtils.Exec(mDatabaseConnection, db.Name, sb.ToString(), sqlParams))
                using (log.IndentScope())
                {
                    foreach (var processOutputLine in process.GetOutput())
                    {
                        log.Log(processOutputLine.Line);
                    }
                }
            }

            log.Log("Database restore completed.");
        }