コード例 #1
0
        private void CopyTable(SqlQueries sqlQueries)
        {
            if (!string.IsNullOrEmpty(tableName) && sqlQueries.TableName != tableName)
            {
                return;
            }

            logInfo.Info = $"Table: {sqlQueries.TableName}";

            //Check User table
            //var userInfo = WorkReader.CreateInfo($"{sqlQueries.TableName} -> {sqlQueries.NewTableName}" ,0,0);
            var userInfo = WorkReader.CreateInfo(sqlQueries.NewTableName, 0, 0);

            _infoList.Add(userInfo);

            logInfo.Info = $"New table {userInfo.TableName}";

            var maxId = CheckAndCreateTable(sqlQueries.NewTableName, sqlQueries.SqlCreate(), userInfo);

            if (maxId < 0)
            {
                return;
            }

            logInfo.Info = $"Create new table {sqlQueries.NewTableName}";

            var reader = ReadRecords(sqlQueries, maxId, sqlQueries.SqlSelect(maxId), userInfo);

            if (reader == null)
            {
                return;
            }

            logInfo.Info = $"Table {sqlQueries.TableName}. Row count: {userInfo.Count}";

            sqlQueries.Insert(reader, DesSqlCon, userInfo, logInfo);
        }
コード例 #2
0
        protected void CopyRows(SqlDataReader reader, SqlCommand cmd, InfoDto info, LogInfo logInfo)
        {
            if (reader == null || cmd == null || info == null)
            {
                logInfo.Info = "Reader is null";
                return;
            }

            int    count = 1;
            object key   = null;

            while (reader.Read())
            {
                try
                {
                    /*
                     * Object[] values = new Object[reader.FieldCount];
                     * int fieldCount = reader.GetValues(values);
                     * key = values[0];
                     *
                     * for (int ix = 0; ix < fieldCount; ix++)
                     *  cmd.Parameters[ix].Value = values[ix];*/


                    for (int ix = 0; ix != cmd.Parameters.Count - 1; ix++)
                    {
                        WorkReader.SetParameter(cmd.Parameters, reader, ix);

                        //cmd.Parameters[ix].Value =
                        //WorkReader.NullToDBNull(SetParameter(cmd.Parameters[ix].ParameterName, WorkReader.DBNullToNull(cmd.Parameters[ix].Value)));

                        if (ix == 0)
                        {
                            key = cmd.Parameters[ix].Value;
                        }
                    }

                    cmd.Parameters[$"@{ncId}"].Value = Guid.NewGuid();
                }
                catch (Exception ex)
                {
                    logInfo.Info = "copy rows - SetParameter";
                    info.Info    = $"Id: {key} {ex.Message}";
                    return;
                }

                //Console.WriteLine(reader.GetValue(0));

                try
                {
                    cmd.ExecuteNonQuery();
                    if (count % mod == 0)
                    {
                        info.Imported = count;
                    }

                    if (count % 10 == 0)
                    {
                        logInfo.Info = $"Saved: {count}";
                    }

                    count++;

                    if (_token.IsCancellationRequested)
                    {
                        if (String.IsNullOrEmpty(info.Info))
                        {
                            info.Info = "Esc stop";
                        }
                        else
                        {
                            info.Info = $"{info.Info} Esc stop";
                        }
                        //_token.ThrowIfCancellationRequested();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    logInfo.Info = "copy rows - ExecuteNonQuery";
                    info.Info    = ex.Message;
                    break;
                }

                // Thread.Sleep(250);
            }

            info.Imported = count - 1;
        }
コード例 #3
0
 public ActionResult Add(WorkReader work)
 {
     return(View());
 }