Exemple #1
0
        private int LoadLogs(string logtype = null)
        {
            List <string> logTypes = WriteLog.GetLogTypes();

            comboBox1.Items.Clear();
            comboBox1.Items.Add("--不限--");
            foreach (string logT in logTypes)
            {
                comboBox1.Items.Add(logT);
            }
            loadOver = false;
            if (logtype == null)
            {
                comboBox1.SelectedIndex = 0;
            }
            else
            {
                comboBox1.SelectedIndex = comboBox1.Items.IndexOf(logtype);
            }
            loadOver = true;
            string logType = null;

            if (comboBox1.SelectedItem.ToString() != "--不限--")
            {
                logType = comboBox1.SelectedItem.ToString();
            }
            dataGridView1.DataSource = WriteLog.GetLogs(index, size, logType, out allCount);
            pageCount = allCount / size;
            int R = allCount % size;

            if (R > 0)
            {
                pageCount++;
            }
            int begin = size * index;

            if (pageCount == 0)
            {
                textBox1.Text = "0/0";
            }
            else
            {
                int r = begin + size;
                if (pageCount == 1)
                {
                    r = begin + R;
                }
                else if (pageCount > 1 && index == pageCount - 1)
                {
                    if (R == 0)
                    {
                        r = begin + size;
                    }
                    else
                    {
                        r = begin + R;
                    }
                }
                textBox1.Text = Convert.ToString(begin + 1) + "-" + r + "/" + allCount + " 当前第" + (index + 1) + "页,共" + pageCount + "页(每页" + size + "条记录)";
            }
            return(pageCount);
        }
Exemple #2
0
        /// <summary>
        /// 执行Sql和Oracle滴混合事务
        /// </summary>
        /// <param name="list">SQL命令行列表</param>
        /// <param name="oracleCmdSqlList">Oracle命令行列表</param>
        /// <returns>执行结果 0-由于SQL造成事务失败 -1 由于Oracle造成事务失败 1-整体事务执行成功</returns>
        public int ExecuteSqlTran(List <CommandInfo> list, List <CommandInfo> oracleCmdSqlList, bool backupDB = false)
        {
            lock (lockObj)
            {
                using (SqlConnection conn = HelpConnection.GetConnection(backupDB))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = conn;
                    SqlTransaction tx = conn.BeginTransaction();
                    cmd.Transaction = tx;
                    try
                    {
                        foreach (CommandInfo myDE in list)
                        {
                            string         cmdText  = myDE.CommandText;
                            SqlParameter[] cmdParms = (SqlParameter[])myDE.Parameters;
                            PrepareCommand(cmd, conn, tx, cmdText, cmdParms);
                            if (myDE.EffentNextType == EffentNextType.SolicitationEvent)
                            {
                                if (myDE.CommandText.ToLower().IndexOf("count(") == -1)
                                {
                                    tx.Rollback();
                                    MessageBox.Show("数据库操作失败:违背要求" + myDE.CommandText + "必须符合select count(..的格式");
                                    return(-1);
                                }

                                object obj    = cmd.ExecuteScalar();
                                bool   isHave = false;
                                if (obj == null && obj == DBNull.Value)
                                {
                                    isHave = false;
                                }
                                isHave = Convert.ToInt32(obj) > 0;
                                if (isHave)
                                {
                                    //引发事件
                                    myDE.OnSolicitationEvent();
                                }
                            }
                            if (myDE.EffentNextType == EffentNextType.WhenHaveContine || myDE.EffentNextType == EffentNextType.WhenNoHaveContine)
                            {
                                if (myDE.CommandText.ToLower().IndexOf("count(") == -1)
                                {
                                    tx.Rollback();
                                    MessageBox.Show("数据库操作失败:违背要求" + myDE.CommandText + "必须符合select count(..的格式");
                                    return(-1);
                                }

                                object obj    = cmd.ExecuteScalar();
                                bool   isHave = false;
                                if (obj == null && obj == DBNull.Value)
                                {
                                    isHave = false;
                                }
                                isHave = Convert.ToInt32(obj) > 0;

                                if (myDE.EffentNextType == EffentNextType.WhenHaveContine && !isHave)
                                {
                                    tx.Rollback();
                                    MessageBox.Show("数据库操作失败:违背要求" + myDE.CommandText + "返回值必须大于0");
                                    return(-1);
                                }
                                if (myDE.EffentNextType == EffentNextType.WhenNoHaveContine && isHave)
                                {
                                    tx.Rollback();
                                    MessageBox.Show("数据库操作失败:违背要求" + myDE.CommandText + "返回值必须等于0");
                                    return(-1);
                                }
                                continue;
                            }
                            int val = cmd.ExecuteNonQuery();
                            if (myDE.EffentNextType == EffentNextType.ExcuteEffectRows && val == 0)
                            {
                                tx.Rollback();
                                MessageBox.Show("数据库操作失败:违背要求" + myDE.CommandText + "必须有影响行");
                                return(-1);
                            }
                            cmd.Parameters.Clear();
                        }
                        return(1);
                    }
                    catch (System.Data.SqlClient.SqlException e)
                    {
                        tx.Rollback();
                        WriteLog.CreateLog("数据库操作日志", "DbHelperSQL类(ExecuteSqlTran函数):", "error", e.Message);
                        MessageBox.Show("数据库操作失败:" + e.Message);
                        return(-1);
                    }
                    catch (Exception e)
                    {
                        tx.Rollback();
                        WriteLog.CreateLog("数据库操作日志", "DbHelperSQL类(ExecuteSqlTran函数):", "error", e.Message);
                        MessageBox.Show("数据库操作失败:" + e.Message);
                        return(-1);
                    }
                }
            }
        }
Exemple #3
0
 private void 锁定ToolStripMenuItem1_Click(object sender, EventArgs e)
 {
     WriteLog.CreateLog(this.User.Username, "MainForm.锁定ToolStripMenuItem1", "log", "用户:" + this.User.Username);
     LockSystem();
 }