You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
6.5 KiB
C#
169 lines
6.5 KiB
C#
using DevExpress.XtraCharts;
|
|
using DevExpress.XtraEditors;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using ZJ_BYD.DB;
|
|
|
|
namespace ZJ_BYD
|
|
{
|
|
public partial class PassRateRpt : XtraForm
|
|
{
|
|
public PassRateRpt()
|
|
{
|
|
InitializeComponent();
|
|
|
|
Top = 0;
|
|
Left = 0;
|
|
Width = Screen.PrimaryScreen.WorkingArea.Width;
|
|
Height = Screen.PrimaryScreen.WorkingArea.Height;
|
|
chartControl1.CustomizeStackedBarTotalLabel += OnChartCustomizeStackedBarTotalLabel;
|
|
}
|
|
|
|
|
|
private void PassRateRpt_Load(object sender, EventArgs e)
|
|
{
|
|
var logoFileName = ConfigurationManager.AppSettings["logofilename"];
|
|
var imgPath = Path.Combine(Application.StartupPath, "image/" + logoFileName);
|
|
loginpic.Image = System.Drawing.Image.FromFile(imgPath);
|
|
beginDate.Text = DateTime.Now.ToString("yyyy/MM/dd") + " 00:00:00";
|
|
endDate.Text = DateTime.Now.ToString("yyyy/MM/dd") + " 23:59:59";
|
|
var datas= Data.GetData(DateTime.Parse(beginDate.Text), DateTime.Parse(endDate.Text));
|
|
this.chartControl1.DataSource = datas;
|
|
SetLblText(datas);
|
|
}
|
|
|
|
private void OnChartCustomizeStackedBarTotalLabel(object sender, CustomizeStackedBarTotalLabelEventArgs e)
|
|
{
|
|
var datas = Data.GetData(DateTime.Parse(beginDate.Text), DateTime.Parse(endDate.Text));
|
|
var aa = datas.FirstOrDefault(m => m.Date == e.Argument.ToString() && m.IStatus == 1);
|
|
if (aa!=null)
|
|
{
|
|
var tmpVal = aa.Count / (e.TotalValue * 1.0);
|
|
e.Text = $"{Math.Round(tmpVal, 2) * 100}%";
|
|
}
|
|
}
|
|
|
|
private void btnsearch_Click(object sender, EventArgs e)
|
|
{
|
|
splashScreenManager1.ShowWaitForm();
|
|
var datas = Data.GetData(DateTime.Parse(beginDate.Text), DateTime.Parse(endDate.Text));
|
|
this.chartControl1.DataSource = datas;
|
|
SetLblText(datas);
|
|
splashScreenManager1.CloseWaitForm();
|
|
}
|
|
|
|
private void SetLblText(List<Data> datas)
|
|
{
|
|
var okList = datas.Where(m => m.Status == "OK" && m.Count > 0).ToList();
|
|
var okCount = 0;
|
|
foreach (var item in okList)
|
|
{
|
|
okCount += item.Count;
|
|
}
|
|
var ngCount = 0;
|
|
var ngList = datas.Where(m => m.Status == "NG" && m.Count > 0).ToList();
|
|
foreach (var item in ngList)
|
|
{
|
|
ngCount += item.Count;
|
|
}
|
|
var totalCount = okCount + ngCount;
|
|
lblTotalCount.Text = totalCount.ToString();
|
|
lblOkCount.Text = okCount.ToString();
|
|
lblNgCount.Text = ngCount.ToString();
|
|
if (totalCount <= 0)
|
|
{
|
|
lblRate.Text = "0%";
|
|
}
|
|
else
|
|
{
|
|
var rate = okCount / (totalCount * 1.0);
|
|
lblRate.Text = $"{Math.Round(rate, 2) * 100}%";
|
|
}
|
|
}
|
|
|
|
private void lblClose_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private class Data
|
|
{
|
|
public string Date { get; set; }
|
|
public int Count { get; set; }
|
|
public int IStatus { get; set; }
|
|
public string Status { get; set; }
|
|
public Data(string date, int count, int iStatus, string status)
|
|
{
|
|
this.Date = date;
|
|
this.Count = count;
|
|
this.IStatus = iStatus;
|
|
this.Status = status;
|
|
}
|
|
|
|
public static List<Data> GetData(DateTime beginDate,DateTime endDate)
|
|
{
|
|
var dataList = new List<Data>();
|
|
// var result = ResultHelper.QueryResults();
|
|
|
|
var ngList = ResultHelper.QueryResults().Where(m => m.CreatedTime >= beginDate && m.CreatedTime <= endDate)
|
|
.Where(m => m.StationCode == Program.ActiveStatinCode && m.TotalStatus.ToLower() == "ng")
|
|
.GroupBy(m => m.CreatedTime.ToString("yyyy/MM/dd"))
|
|
.Select(m => new
|
|
{
|
|
CreatedTime = m.CreatedTime.ToString("yyyy/MM/dd"),
|
|
count = SqlFunc.AggregateCount(m.TotalStatus)
|
|
}).ToList();
|
|
|
|
var okList = ResultHelper.QueryResults().Where(m => m.CreatedTime >= beginDate && m.CreatedTime <= endDate)
|
|
.Where(m => m.StationCode == Program.ActiveStatinCode && m.TotalStatus.ToLower() == "ok")
|
|
.GroupBy(m => m.CreatedTime.ToString("yyyy/MM/dd"))
|
|
.Select(m => new
|
|
{
|
|
CreatedTime = m.CreatedTime.ToString("yyyy/MM/dd"),
|
|
count = SqlFunc.AggregateCount(m.TotalStatus)
|
|
}).ToList();
|
|
|
|
|
|
if (okList.Count > 0)
|
|
{
|
|
foreach (var item in okList)
|
|
{
|
|
dataList.Add(new Data(item.CreatedTime, item.count, 1, "OK"));
|
|
var ng = ngList.FirstOrDefault(m => m.CreatedTime == item.CreatedTime);
|
|
if (ng != null)
|
|
{
|
|
dataList.Add(new Data(ng.CreatedTime, ng.count, 0, "NG"));
|
|
}
|
|
else
|
|
{
|
|
dataList.Add(new Data(item.CreatedTime, 0, 0, "NG"));
|
|
}
|
|
}
|
|
}
|
|
else if (ngList.Count > 0)
|
|
{
|
|
foreach (var item in ngList)
|
|
{
|
|
dataList.Add(new Data(item.CreatedTime, item.count, 0, "NG"));
|
|
var ok = okList.FirstOrDefault(m => m.CreatedTime == item.CreatedTime);
|
|
if (ok != null)
|
|
{
|
|
dataList.Add(new Data(ok.CreatedTime, ok.count, 1, "OK"));
|
|
}
|
|
else
|
|
{
|
|
dataList.Add(new Data(item.CreatedTime, 0, 1, "OK"));
|
|
}
|
|
}
|
|
}
|
|
return dataList.OrderBy(m=>m.Date).ToList();
|
|
}
|
|
}
|
|
}
|
|
}
|