Ejemplo n.º 1
0
        //添加事件
        private void Submit_Click(object sender, RoutedEventArgs e)
        {
            IncidentBean bean = (IncidentBean)DataContext;

            bean.Title = bean.Title.Trim();
            if (bean.Title == string.Empty)
            {
                MessageBox.Show("标题不得为空", "提示", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            else
            {
                if (bean.Title.Length > 20)
                {
                    MessageBox.Show("标题不得超过20个字符", "提示", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }
                if (bean.Explain.Length > 500)
                {
                    MessageBox.Show("备注不得超过500个字符", "提示", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }
            }
            AddRecordService.AddIncident(bean);
        }
Ejemplo n.º 2
0
        public static IncidentBean GetBean()
        {
            IncidentBean bean = IncidentMapper.GetLastBean();

            if (bean == null)
            {
                bean = new IncidentBean();
            }
            bean.Title   = string.Empty;
            bean.Explain = string.Empty;
            return(bean);
        }
Ejemplo n.º 3
0
        //加载页面
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            IncidentBean bean = AddRecordService.GetBean();

            DataContext = bean;
            if (bean.CreateTime == DateTime.MinValue)
            {
                return;
            }
            TimeSpan time = DateTime.Now - bean.CreateTime;

            timeSpan.Text = "距离上一次记录:- 天".Replace(" - ", time.Days.ToString());
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 获取事件选择列表
 /// </summary>
 public static IncidentBean[] GetComboBoxResource()
 {
     IncidentBean[] beans = IncidentMapper.GetSuccessIncident();
     IncidentBean[] items = new IncidentBean[beans.Length + 1];
     items[0] = new IncidentBean
     {
         Id    = 0,
         Title = "请选择事件",
     };
     for (int i = 1; i < items.Length; i++)
     {
         items[i] = beans[i - 1];
     }
     return(items);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 添加记录
        /// </summary>
        /// <param name="bean">事件bean</param>
        public static void AddIncident(IncidentBean bean)
        {
            AddRecordAsyn addRecord = new AddRecordAsyn();

            Log.Info("开始添加记录");
            ProgramWindow window = new ProgramWindow();

            object[] objs = { window, bean };
            //建立异步线程来记录全盘文件
            addRecord.thread = new Thread(addRecord.AddOne)
            {
                Name = "addRecord"
            };
            addRecord.thread.Start(objs);
            window.ShowDialog();
        }
Ejemplo n.º 6
0
        //将表格结果改为bean
        private static IncidentBean[] GetBeanByTable(DataTable table)
        {
            int count = table.Rows.Count;

            IncidentBean[] beans = new IncidentBean[count];
            for (int i = 0; i < count; i++)
            {
                beans[i] = new IncidentBean()
                {
                    Id         = Convert.ToUInt32(table.Rows[i]["id"]),
                    CreateTime = (DateTime)table.Rows[i]["create_time"],
                    Title      = table.Rows[i]["title"] as string,
                    Explain    = table.Rows[i]["explain"] as string,
                    State      = Convert.ToSByte(table.Rows[i]["state"]),
                };
            }
            return(beans);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 添加一行数据
        /// </summary>
        /// <param name="bean">对应的bean</param>
        /// <returns>该行的id</returns>
        public static uint AddOne(IncidentBean bean)
        {
            using (SQLiteCommand cmd = new SQLiteCommand())
            {
                cmd.CommandText = "INSERT INTO " +
                                  "[incident] ([create_time],[title],[explain],[state]) " +
                                  "VALUES (@create_time,@title,@explain,@state);";
                cmd.Parameters.Add("create_time", DbType.DateTime).Value = bean.CreateTime;
                cmd.Parameters.Add("title", DbType.String).Value         = bean.Title;
                cmd.Parameters.Add("explain", DbType.String).Value       = bean.Explain;
                cmd.Parameters.Add("state", DbType.SByte).Value          = bean.State;
                SQLiteClient.Write(cmd);
            }
            uint id;

            using (SQLiteCommand cmd = new SQLiteCommand())
            {
                cmd.CommandText = "SELECT LAST_INSERT_ROWID();";
                DataTable table = SQLiteClient.Read(cmd);
                //查询id默认类型为ulong
                id = Convert.ToUInt32(table.Rows[0][0]);
            }
            return(id);
        }
Ejemplo n.º 8
0
        public void AddOne(object obj)
        {
            DateTime startTime = DateTime.Now;

            Thread.Sleep(1000);
            object[]      objs          = (object[])obj;
            ProgramWindow programWindow = (ProgramWindow)objs[0];
            IncidentBean  bean          = (IncidentBean)objs[1];

            programWindow.WriteLine("初始化...");
            try
            {
                //处理事件
                bean.CreateTime = DateTime.Now;
                bean.State      = 1;
                incidentId      = IncidentMapper.AddOne(bean);
                isFirst         = IncidentMapper.IsFirstRecord();
                //第一次记录必须保证索引表为空
                if (isFirst)
                {
                    DirIndexMapper.CleanAll();
                }
                //新建记录表
                Extend.BuildTable(incidentId, isFirst);
                programWindow.WriteLine("开始记录硬盘使用空间...");
                programWindow.WriteLine("(建议此时不要修改硬盘上的文件,以免影响最终的分析结果)");
                programWindow.Freeze();
                isRunning = true;
                Thread showProgress = new Thread(ShowProgress)
                {
                    Name = "showProgress"
                };
                showProgress.Start(programWindow);
                DriveInfo[] drives = DriveInfo.GetDrives();
                //遍历分区
                foreach (DriveInfo drive in drives)
                {
                    DirectoryInfo rootDir = new DirectoryInfo(drive.Name);
                    SeeDirectory(rootDir, 0);
                }
                isRunning = false;
                programWindow.WriteAll("记录完成,建立索引...\n");
                Extend.BuildIndex(incidentId);
                //收尾工作
                long count = RecordMapper.Count(incidentId);
                IncidentMapper.SetStateById(incidentId, 0);
                if (isFirst)
                {
                    //删除以前记录失败的作废表格
                    Extend.DeleteErrorTable(incidentId);
                }
                TimeSpan consumption = DateTime.Now - startTime;
                Log.Info(string.Format("数据记录完成, 记录:{0}({1}), 耗时:{2}", count, beanCount, consumption));
                programWindow.WriteLine(string.Format("数据记录完成,耗时:{0}小时{1}分。",
                                                      consumption.Days * 24 + consumption.Hours, consumption.Minutes));
                programWindow.RunOver();
            }
            catch (Exception e)
            {
                Log.Add(e);
                isRunning = false;
                programWindow.WriteLine("\n错误:");
                programWindow.WriteLine(e.Message);
                programWindow.RunOver();
                //throw e;
            }
        }