using AIRS.usercontrol;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.SQLite;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace AIRS
{
///
/// HistoryGrade.xaml 的交互逻辑
///
public partial class HistoryGrade : Window
{
private int m_Pyte = 0;//打开窗体类型 0历史评级 1检查报告
#region 分页变量
///
/// 当前页码
///
private int m_Page = 1;
///
/// 总条数
///
private int m_Total = 0;
///
/// 总页数
///
private int m_Count = 1;
///
/// 每页条数
///
private int m_Page_Count = 15;
#endregion
///
/// 数据库
///
SQLiteConnection conn = null;
SQLiteConnectionStringBuilder connstr = null;
///
/// 程序工作目录
///
private string path = Directory.GetCurrentDirectory();
///
/// 构造方法
///
/// 0历史评级 1检查报告
public HistoryGrade(int type)
{
m_Pyte = type;
InitializeComponent();
}
///
/// 关闭窗体事件
///
///
///
private void btnCancel_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
}
///
/// 窗体加载完成后执行事件
///
///
///
private void Window_ContentRendered(object sender, EventArgs e)
{
if (m_Pyte == 1)
{
//切换到检查报告
this.HisorReport.Content = "检查报告";
this.HisGrad.Visibility = Visibility.Collapsed;//隐藏历史评级
this.CheckReport.Visibility = Visibility.Visible;//显示检查报告
this.CheckBtnSave.Visibility = Visibility.Visible;//显示报告另存按钮
this.btn_Query.Visibility = Visibility.Collapsed;//隐藏查询按钮
this.lable1.Visibility = Visibility.Collapsed;//隐藏lable
this.startdatePickerCtl.Visibility = Visibility.Collapsed;//隐藏开始时间
this.enddatePickerCtl.Visibility = Visibility.Collapsed;//隐藏结束时间
//#region 隐藏分页按钮
//this.first_btn.Visibility = Visibility.Collapsed;
//this.last_btn.Visibility = Visibility.Collapsed;
//this.next_btn.Visibility = Visibility.Collapsed;
//this.pro_btn.Visibility = Visibility.Collapsed;
//#endregion
}
else if (m_Pyte == 0)
{
//切换到历史评级
this.HisorReport.Content = "历史评级";
this.HisGrad.Visibility = Visibility.Visible;//显示历史评级
this.CheckReport.Visibility = Visibility.Collapsed;//隐藏检查报告
this.CheckBtnSave.Visibility = Visibility.Collapsed;//隐藏报告另存按钮
this.btn_Query.Visibility = Visibility.Visible;//显示查询按钮
this.lable1.Visibility = Visibility.Visible;//显示lable
this.startdatePickerCtl.Visibility = Visibility.Visible;//显示开始时间
this.enddatePickerCtl.Visibility = Visibility.Visible;//显示结束时间
//#region 显示分页按钮
//this.first_btn.Visibility = Visibility.Visible;
//this.last_btn.Visibility = Visibility.Visible;
//this.next_btn.Visibility = Visibility.Visible;
//this.pro_btn.Visibility = Visibility.Visible;
//#endregion
GetGrade();
}
}
///
/// 根据路径获取报告
///
///
private void GetReport(string path)
{
try
{
string strSql = "SELECT * FROM t_grade where \"图像目录\"=='" + path + "'";
conn = new SQLiteConnection();
connstr = new SQLiteConnectionStringBuilder();
connstr.DataSource = path + "\\datas.db";
conn.ConnectionString = connstr.ToString();
conn.Open();
SQLiteDataAdapter da = new SQLiteDataAdapter(strSql, conn);
DataTable ds = new DataTable();
da.Fill(ds);
if (ds.Rows.Count > 0)
{
}
else
{
MessageBox.Show("没有该图像路径的检查结果!");
}
}
catch (Exception ex)
{
}
finally
{
}
}
///
/// 获取历史评级数据
///
///
private void GetGrade()
{
try
{
string startTime = "";
string endTime = "";
try
{
startTime = DateTime.Parse(startdatePickerCtl.Text.Trim()).ToString("yyyy-MM-dd 00:00:00");
endTime = DateTime.Parse(enddatePickerCtl.Text.Trim()).ToString("yyyy-MM-dd 23:59:59");
}
catch
{
MessageBox.Show("时间格式不正确,请重新填写!");
return;
}
string strSql = "SELECT * FROM t_grade where 1=1";
string strcountsql = "SELECT count(*) as count FROM t_grade where 1=1";
if (startTime.Length > 0)
{
strSql += " and \"评级时间\">'" + startTime + "'";
strcountsql += " and \"评级时间\">'" + startTime + "'";
}
if (endTime.Length > 0)
{
strSql += " and \"评级时间\"<'" + endTime + "'";
strcountsql += " and \"评级时间\"<'" + endTime + "'";
}//desc
strSql += "order by \"评级时间\" desc limit " + ((m_Page - 1) * m_Page_Count) + ","+ m_Page_Count + "";
conn = new SQLiteConnection();
connstr = new SQLiteConnectionStringBuilder();
connstr.DataSource = path + "\\datas.db";
conn.ConnectionString = connstr.ToString();
conn.Open();
SQLiteDataAdapter da = new SQLiteDataAdapter(strSql, conn);
DataTable ds = new DataTable();
da.Fill(ds);
da = new SQLiteDataAdapter(strcountsql, conn);
DataTable dsCount = new DataTable();
da.Fill(dsCount);
m_Total = Convert.ToInt32(dsCount.Rows[0][0]);//总条数
m_Count = (int)Math.Ceiling(((double)m_Total / (double)m_Page_Count));
ObservableCollection list = new ObservableCollection();
for (int i = 0; i < ds.Rows.Count; i++)
{
HisData data = new HisData();
//data.num = (i + 1);
data.gradeproject = ds.Rows[i]["评级项目"] == null ? "" : ds.Rows[i]["评级项目"].ToString();
data.gradetime = ds.Rows[i]["评级时间"] == null ? "" : ds.Rows[i]["评级时间"].ToString(); // ds.Rows[i]["评级时间"].ToString();
data.operation = ds.Rows[i]["操作员"] == null ? "" : ds.Rows[i]["操作员"].ToString(); //ds.Rows[i]["操作员"].ToString();
data.checke = ds.Rows[i]["复合员"] == null ? "" : ds.Rows[i]["复合员"].ToString(); //ds.Rows[i]["复合员"].ToString();
data.imgurl = ds.Rows[i]["图像目录"] == null ? "" : ds.Rows[i]["图像目录"].ToString();
data.catagory = ds.Rows[i]["catagory"] == null ? "" : ds.Rows[i]["catagory"].ToString();//类别
data.gangzhong = ds.Rows[i]["钢种"] == null ? "" : ds.Rows[i]["钢种"].ToString();//钢种
data.imgcount = ds.Rows[i]["图像数量"] == null ? "" : ds.Rows[i]["图像数量"].ToString();//图像数量
data.pingji = ds.Rows[i]["评级标准"] == null ? "" : ds.Rows[i]["评级标准"].ToString();//评级标准
data.instrument = ds.Rows[i]["检测仪器"] == null ? "" : ds.Rows[i]["检测仪器"].ToString();//图像数量
list.Add(data);
}
date_grid.DataContext = list;
//this.pageuser.FontSize = 36;
this.pageuser.Page = m_Page;
//this.pageuser.PageCount = m_Count;
this.pageuser.PageSize = m_Page_Count;
this.pageuser.RecordCount = m_Total;
}
catch (Exception ex)
{
}
finally
{
try
{
conn.Close();
}
catch
{
}
}
}
///
/// 序号列
///
///
///
private void date_grid_LoadingRow(object sender, DataGridRowEventArgs e)
{
e.Row.Header = e.Row.GetIndex() + 1;
}
///
/// 生成/查看报告单击事件(表格内按钮单击事件)
///
///
///
private void Button_Click(object sender, RoutedEventArgs e)
{
//MessageBox.Show(((Button)sender).Tag == null ? "" : ((Button)sender).Tag.ToString());
try
{
string imgUrl = ((Button)sender).Tag == null ? "" : ((Button)sender).Tag.ToString();
conn = new SQLiteConnection();
connstr = new SQLiteConnectionStringBuilder();
connstr.DataSource = path + "\\datas.db";
conn.ConnectionString = connstr.ToString();
conn.Open();
string strSql = "select * from t_grade where \"图像目录\"='" + imgUrl + "'";
SQLiteDataAdapter da = new SQLiteDataAdapter(strSql, conn);
DataTable ds = new DataTable();
da.Fill(ds);
if (ds.Rows.Count > 0)
{
string check_Project = "";// 评级项目/检测项目
string standard = "";//检测标准及技术文件
string device = "";//检测使用设备
string result = "";//结果
string check_user = "";//检查员
}
}
catch
{
}
finally
{
try
{
conn.Close();
}
catch
{
}
}
}
#region 分页事件
///
/// 上一页
///
///
///
private void pro_btn_Click(object sender, RoutedEventArgs e)
{
if (m_Page == 1)
{
MessageBox.Show("已经是第一页!");
return;
}
m_Page--;
GetGrade();
}
///
/// 首页
///
///
///
private void first_btn_Click(object sender, RoutedEventArgs e)
{
if (m_Page == 1)
{
MessageBox.Show("已经是第一页!");
return;
}
m_Page = 1;
GetGrade();
}
///
/// 下一页
///
///
///
private void next_btn_Click(object sender, RoutedEventArgs e)
{
if (m_Page >= m_Count)
{
MessageBox.Show("已经是最后一页!");
return;
}
m_Page++;
GetGrade();
}
///
/// 尾页
///
///
///
private void last_btn_Click(object sender, RoutedEventArgs e)
{
if (m_Page >= m_Count)
{
MessageBox.Show("已经是最后一页!");
return;
}
m_Page = m_Count;
GetGrade();
}
#endregion
///
/// 查询按钮
///
///
///
private void btn_Query_Click(object sender, RoutedEventArgs e)
{
m_Page = 1;
GetGrade();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.pageuser.PageChanged += new EventHandler(Eventpage);
}
///
/// 自定义分页事件
///
///
///
public void Eventpage(object sender, PageChangedEventArgs a)
{
m_Page = a.Page;
GetGrade();
}
}
#region 显示列类
///
/// 显示列类
///
public class HisData
{
//public int num { get; set; }
///
/// 评级项目
///
public string gradeproject { get; set; }
///
/// 评级时间
///
public string gradetime { get; set; }
///
/// 操作员
///
public string operation { get; set; }
///
/// 复核员
///
public string checke { get; set; }
///
/// 图像目录
///
public string imgurl { get; set; }
///
/// 类别
///
public string catagory { get; set; }
///
/// 钢种
///
public string gangzhong { get; set; }
///
/// 图片数量
///
public string imgcount { get; set; }
///
/// 评级标准
///
public string pingji { get; set; }
///
/// 检测仪器
///
public string instrument { get;set;}
//public string 查看报告 { get; set; }
}
#endregion
}