Ejemplo n.º 1
0
 private void 插入关机时间ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (SqlExecuter.记录关机事件())
     {
         MessageBox.Show("添加关机记录成功!");
     }
 }
Ejemplo n.º 2
0
        /****************************/

        #region 菜单栏
        #region 插入
        private void 插入开机时间ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (SqlExecuter.记录开机事件("[Table]"))
            {
                MessageBox.Show("插入记录成功!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Ejemplo n.º 3
0
 private void 休眠后再次添加开机记录()
 {
     new Thread(() =>
     {
         SqlExecuter.记录开机事件();
         ApplicationExit();
     }).Start();
 }
Ejemplo n.º 4
0
        public SqlDatabase([NotNull] SqlExecuter sqlExecuter, Identifier database)
        {
            _sqlExecuter = sqlExecuter ?? throw new ArgumentNullException(nameof(sqlExecuter));
            _database    = database;

            var builder = new SqlConnectionStringBuilder(sqlExecuter.ConnectionString)
            {
                InitialCatalog = database.Value
            };

            ConnectionString = builder.ToString();
        }
 private void 填补空处ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (AlertBusy())
     {
         return;
     }
     if (MessageBox.Show("该操作会将时长、当天使用次数、当月使用次数完全计算并填补,是否继续?", "一键填补", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
     {
         return;
     }
     SqlExecuter.记录结算();
     this.Focus();
     this.progressBar1.Value = 40;
     this.statusLabel.Text   = "正在填补空处";
     backgroundQueryMode     = QueryMode.显示后十五条数据;
     this.dbBackgroundWorker.RunWorkerAsync(null);
 }
        private void 插入开机记录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (AlertBusy())
            {
                return;
            }
            if (Cache.ExistCache())
            {
                MessageBox.Show("检测到缓存清理功能故障,无法继续进行添加操作。请暂时不要改变数据库内数据并与程序员联系!", "严重警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (SqlExecuter.记录开机事件(TableName))
            {
                MessageBox.Show("插入记录成功!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            this.显示后20条ToolStripMenuItem_Click(null, null);
        }
Ejemplo n.º 7
0
        public async Task Debe_Ejecutar_Consulta_SQL()
        {
            var totalRegistros = 5;

            //Preparar datos
            using (var context = new SqlExecuterTestDbContext())
            {
                var simpleDbContextProvider = new SimpleDbContextProvider <SqlExecuterTestDbContext>(context);
                var sqlExecuter             = new SqlExecuter(simpleDbContextProvider);

                //1. Eliminar todos los datos existentes
                var items = await context.Parametros.ToListAsync();

                context.Parametros.RemoveRange(items);

                //2. Agregar Datos.
                var list = FakeParametros(totalRegistros);
                foreach (var item in list)
                {
                    context.Parametros.Add(item);
                }
                context.SaveChanges();
            }

            //Ejecutar Test
            using (var context = new SqlExecuterTestDbContext())
            {
                var simpleDbContextProvider = new SimpleDbContextProvider <SqlExecuterTestDbContext>(context);
                var sqlExecuter             = new SqlExecuter(simpleDbContextProvider);


                //3. Consultar datos
                var valorCambiar         = "new.value.foo";
                var registrosModificados = sqlExecuter.Execute("UPDATE ParametroSistemas SET valor = @value", new SqlParameter("@value", valorCambiar));
                registrosModificados.ShouldBe(totalRegistros);


                //4. Verificar
                foreach (var parametro in context.Parametros)
                {
                    parametro.Valor.ShouldBe(valorCambiar);
                }
            }
        }
Ejemplo n.º 8
0
        public async Task <ISqlDatabase> RecreateToAsync([NotNull] SqlConnection connection, [NotNull] string databaseName)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            if (databaseName == null)
            {
                throw new ArgumentNullException(nameof(databaseName));
            }

            var sqlProject = _sqlProjectReader.ReadProject(databaseName);

            _modifiers.Modify(sqlProject);

            var executer = new SqlExecuter(connection);
            await executer.ExecuteAsync(sqlProject).ConfigureAwait(false);

            return(new SqlDatabase(executer, sqlProject.GetDatabaseName()));
        }
Ejemplo n.º 9
0
        public async Task Debe_Recuperar_Valor_Consulta_SQL()
        {
            var totalRegistros = 3;

            //Preparar datos
            using (var context = new SqlExecuterTestDbContext())
            {
                var simpleDbContextProvider = new SimpleDbContextProvider <SqlExecuterTestDbContext>(context);
                var sqlExecuter             = new SqlExecuter(simpleDbContextProvider);

                //1. Eliminar todos los datos existentes
                var items = await context.Parametros.ToListAsync();

                context.Parametros.RemoveRange(items);

                //2. Agregar Datos.
                var list = FakeParametros(totalRegistros);
                foreach (var item in list)
                {
                    context.Parametros.Add(item);
                }
                context.SaveChanges();
            }


            //Ejecutar Test
            using (var context = new SqlExecuterTestDbContext())
            {
                var simpleDbContextProvider = new SimpleDbContextProvider <SqlExecuterTestDbContext>(context);
                var sqlExecuter             = new SqlExecuter(simpleDbContextProvider);

                //2. Consultar datos
                var verificarTotalRegistros = await sqlExecuter.SqlQuery <int>("SELECT count(*) FROM ParametroSistemas");

                //3. Verificar
                //Los valores recuperados con consulta SQL debe ser iguales a los total de registros insertados
                verificarTotalRegistros.ShouldBe(totalRegistros);
            }
        }
Ejemplo n.º 10
0
 protected void AddCommandTimeout(SqlExecuter executor)
 {
     executor.CommandTimeout = CommandTimeout;
 }
Ejemplo n.º 11
0
        private void button确定_Click(object sender, EventArgs e)
        {
            try
            {
                float comboBoxTimeMinutes = float.Parse(this.comboBoxTime.Text);
                if (this.label设置倒计时.Text.Contains("小时"))
                {
                    comboBoxTimeMinutes *= 60;
                }

                if (this.记录关机时间checkBox.Checked && this.comboBoxMode.Text != "延缓")
                {
                    SqlExecuter.记录关机事件();
                }
                if (comboBoxTimeMinutes < 0) // 如果小于0,说明只是记录时间就可以推出
                {
                    return;
                }

                CancelShutdownCommand();
                try
                {
                    switch (this.comboBoxMode.Text)
                    {
                    case "关机":
                        float seconds = comboBoxTimeMinutes * 60;
                        RunShutdownCommand(Mode.关机, seconds);
                        break;

                    case "重启":
                        if (!this.记录关机时间checkBox.Checked)
                        {
                            File.CreateText(@"C:\Users\" + ProgramLauncher.SystemUserName + @"\DONOTWRITEDATA").Close();
                        }
                        RunShutdownCommand(Mode.重启, comboBoxTimeMinutes * 60);
                        break;

                    case "休眠":
                        Run休眠或睡眠("休眠", comboBoxTimeMinutes);
                        break;

                    case "延缓":
                        FastModeExecutor.ShutdownWithSeconds_DelayMode((int)(comboBoxTimeMinutes * 60));
                        break;

                    case "睡眠":
                        Run休眠或睡眠("睡眠", comboBoxTimeMinutes);
                        break;
                    }
                }
                catch (FormatException)
                {
                    MessageBox.Show("请输入正确的数据!", "错误警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.comboBoxTime.Text = "0";
                    return;
                }
            }
            catch (Exception ex)
            {
                ExceptionForm.ShowDialog(ex);
            }
        }
Ejemplo n.º 12
0
        public async Task Debe_Ejecutar_Consulta_SQL_Con_Bloque_Transaccion()
        {
            var totalRegistros = 5;

            //Preparar datos
            using (var context = new SqlExecuterTestDbContext())
            {
                var simpleDbContextProvider = new SimpleDbContextProvider <SqlExecuterTestDbContext>(context);
                var sqlExecuter             = new SqlExecuter(simpleDbContextProvider);

                //1. Eliminar todos los datos existentes
                var items = await context.Parametros.ToListAsync();

                context.Parametros.RemoveRange(items);

                //2. Agregar Datos.
                var list = FakeParametros(totalRegistros);
                foreach (var item in list)
                {
                    context.Parametros.Add(item);
                }
                context.SaveChanges();
            }

            var valorTransaccionComplementa = "new.value.bar";
            var valorTransaccionRollback    = "foo.rollback";

            var valorCambiar = valorTransaccionComplementa;

            using (var scope = new TransactionScope())
            {
                using (var context = new SqlExecuterTestDbContext())
                {
                    var simpleDbContextProvider = new SimpleDbContextProvider <SqlExecuterTestDbContext>(context);
                    var sqlExecuter             = new SqlExecuter(simpleDbContextProvider);

                    var registrosModificados = sqlExecuter.Execute("UPDATE ParametroSistemas SET valor = @value", new SqlParameter("@value", valorCambiar));
                    registrosModificados.ShouldBe(totalRegistros);
                }

                //transctional code…
                scope.Complete();
            }

            //Realizar otra actualizacion. Rollback
            valorCambiar = valorTransaccionRollback;
            try
            {
                using (var scope = new TransactionScope())
                {
                    using (var context = new SqlExecuterTestDbContext())
                    {
                        var simpleDbContextProvider = new SimpleDbContextProvider <SqlExecuterTestDbContext>(context);
                        var sqlExecuter             = new SqlExecuter(simpleDbContextProvider);

                        var registrosModificados = sqlExecuter.Execute("UPDATE ParametroSistemas SET valor = @value", new SqlParameter("@value", valorCambiar));
                        registrosModificados.ShouldBe(totalRegistros);
                    }

                    //transctional rollback…
                    throw new Exception("RollBack..");
                }
            }
            catch (Exception ex)
            {
                output.WriteLine(ex.Message);
            }

            using (var context = new SqlExecuterTestDbContext())
            {
                var simpleDbContextProvider = new SimpleDbContextProvider <SqlExecuterTestDbContext>(context);
                var sqlExecuter             = new SqlExecuter(simpleDbContextProvider);

                //4. Verificar
                foreach (var parametro in context.Parametros)
                {
                    parametro.Valor.ShouldBe(valorTransaccionComplementa);
                }
            }
        }