public void TopGridView(DataGridView dataGridView) { AoiModel aoiModel = DB.GetAoiModel(); Action <DataGridView> t = (control) => { lock (aoiModel) { string AllPcbNums = "(select count(*) from pcbs)"; string PassPcbNums = "(select count(*) from pcbs where is_misjudge = 0 and is_error = 0)"; string ErrorPcbNums = "(select count(*) from pcbs)"; string MisreportPcbNums = "(select count(*) from pcbs where is_misjudge = 1)"; string MisreportRate = MisreportPcbNums + "/" + AllPcbNums; string PassRate = PassPcbNums + "/" + AllPcbNums; string final = "select " + AllPcbNums + " as AllPcbNums, " + ErrorPcbNums + " as ErrorPcbNums, " + MisreportPcbNums + " as MisreportPcbNums, " + MisreportRate + " as MisreportRate, " + PassRate + "as PassRate"; var tables = aoiModel.Database.SqlQuery <SqlQueryData1>(final).ToList(); //.SqlQuery("select *from BlogMaster where UserId='3'"); this.BeginInvoke((Action)(() => { bindingSourceAll.DataSource = tables; control.DataSource = bindingSourceAll; })); aoiModel.Dispose(); } }; MySmartThreadPool.Instance().QueueWorkItem <DataGridView>(t, dataGridView); }
public void Tab1Ini(QueryPars q) { TopGridView(dgvAll2); AoiModel aoiModel = DB.GetAoiModel(); Action <QueryPars> t = (v) => { lock (aoiModel) { var tables = aoiModel.Database.SqlQuery <SqlQueryData2NG>("select ng_type as Type, count(*) as Nums from results where create_time between '" + v.startTime + "' and '" + v.endTime + "' GROUP BY ng_type").ToList(); //.SqlQuery("select *from BlogMaster where UserId='3'"); this.BeginInvoke((Action)(() => { bindingSourceTab1.DataSource = tables; })); var xData = aoiModel.Database.SqlQuery <string>("select ng_type as Type from results where create_time between '" + v.startTime + "' and '" + v.endTime + "' GROUP BY ng_type ORDER BY ng_type").ToList(); var yData = aoiModel.Database.SqlQuery <string>("select count(*) * 100 /(select count(*) from results where create_time between '" + v.startTime + "' and '" + v.endTime + "') as rate " + " from results where create_time between '" + v.startTime + "' and '" + v.endTime + "' GROUP BY ng_type ORDER BY ng_type").ToList(); this.BeginInvoke((Action)(() => { chartTab1.Series[0]["PieLabelStyle"] = "Outside"; //将文字移到外侧 chartTab1.Series[0]["PieLineColor"] = "Black"; //绘制黑色的连线。 chartTab1.Series[0].Points.DataBindXY(xData, yData); })); aoiModel.Dispose(); } }; MySmartThreadPool.Instance().QueueWorkItem <QueryPars>(t, q); }
private void QueryCriteria_Load(object sender, EventArgs e) { AoiModel aoiModel = DB.GetAoiModel(); Action t = () => { lock (aoiModel) { var tables = aoiModel.pcbNames.Select(s => new { s.Name }).ToList(); this.BeginInvoke((Action)(() => { combPcbName.DataSource = tables; combPcbName.ValueMember = "Name"; combPcbName.DisplayMember = "Name"; })); aoiModel.Dispose(); } }; MySmartThreadPool.Instance().QueueWorkItem(t); }
public void Tab0Ini(QueryPars q) { TopGridView(dgvAll); queryPars.nums = int.Parse(combPageNums.Text); queryPars.pages = int.Parse(tbNowPage.Text) - 1; #region 开启线程查询数据库 AoiModel aoiModel = DB.GetAoiModel(); Action <QueryPars> t = (v) => { lock (aoiModel) { var db = aoiModel.pcbs.Where(p => p.CreateTime >= queryPars.startTime && p.CreateTime <= queryPars.endTime); if (queryPars.pcbName != null && queryPars.pcbNumber == null) { db = aoiModel.pcbs.Where(p => p.CreateTime >= queryPars.startTime && p.CreateTime <= queryPars.endTime && p.PcbName == queryPars.pcbName); } else if (queryPars.pcbName == null && queryPars.pcbNumber != null) { if (queryPars.searchPcbNumberAccurate) { db = aoiModel.pcbs.Where(p => p.CreateTime >= queryPars.startTime && p.CreateTime <= queryPars.endTime && p.PcbNumber == queryPars.pcbNumber); } else { db = aoiModel.pcbs.Where(p => p.CreateTime >= queryPars.startTime && p.CreateTime <= queryPars.endTime && p.PcbNumber.Contains(queryPars.pcbNumber)); } } else if (queryPars.pcbName != null && queryPars.pcbNumber != null) { if (queryPars.searchPcbNumberAccurate) { db = aoiModel.pcbs.Where(p => p.CreateTime >= queryPars.startTime && p.CreateTime <= queryPars.endTime && p.PcbNumber == queryPars.pcbNumber && p.PcbName == queryPars.pcbName); } else { db = aoiModel.pcbs.Where(p => p.CreateTime >= queryPars.startTime && p.CreateTime <= queryPars.endTime && p.PcbNumber.Contains(queryPars.pcbNumber) && p.PcbName == queryPars.pcbName); } } var list = db.OrderByDescending(p => p.CreateTime) .Skip(queryPars.pages * queryPars.nums) .Take(queryPars.nums) .ToList(); //#region 最上面的报表 ///**select (select count(*) from pcbs) as AllPcbNums, // * (select count(*) from pcbs where is_error = 1) as ErrorPcbNums, // * (select count(*) from pcbs where is_misjudge = 1) as MisreportPcbNums, // * (select count(*) from pcbs where is_misjudge = 1)/(select count(*) from pcbs) as MisreportRate, // * (select count(*) from pcbs where is_misjudge = 0 and is_error = 0)/(select count(*) from pcbs) as PassRate; // * **/ //string AllPcbNums = "(select count(*) from pcbs)"; //string PassPcbNums = "(select count(*) from pcbs where is_misjudge = 0 and is_error = 0)"; //string ErrorPcbNums = "(select count(*) from pcbs)"; //string MisreportPcbNums = "(select count(*) from pcbs where is_misjudge = 1)"; //string MisreportRate = MisreportPcbNums + "/" + AllPcbNums; //string PassRate = PassPcbNums + "/" + AllPcbNums; //string final = "select " + AllPcbNums + " as AllPcbNums, " //+ ErrorPcbNums + " as ErrorPcbNums, " //+ MisreportPcbNums + " as MisreportPcbNums, " //+ MisreportRate + " as MisreportRate, " //+ PassRate + "as PassRate"; //var tables = aoiModel.Database.SqlQuery<SqlQueryData1>(final).ToList(); //.SqlQuery("select *from BlogMaster where UserId='3'"); //this.BeginInvoke((Action)(() => //{ // bindingSourceAll.DataSource = tables; // dgvAll.DataSource = bindingSourceAll; //})); //#endregion #region 更新底部页数据 int totalRows = totalRows = db.Count();//aoiModel.Database.SqlQuery<int>("select count(*) from pcbs").ToArray()[0]; int totalPage = 1; if (totalRows > queryPars.nums) { totalPage = (totalRows + v.nums - 1) / v.nums; } this.BeginInvoke((Action)(() => { lbTotalPages.Text = totalPage + ""; lbTotalRows.Text = totalRows + ""; })); #endregion aoiModel.Dispose(); this.BeginInvoke((Action)(() => { bindingSourcePcbs.DataSource = list; dgvOriginalData.DataSource = bindingSourcePcbs; })); } }; MySmartThreadPool.Instance().QueueWorkItem <QueryPars>(t, queryPars); #endregion }
/// <summary> /// ListView跳转到下一行 /// </summary> /// <param name="res"></param> public void lvListNextItemSelect(string res) { try { selectListView.Select(); int index = selectIndex; if (selectListView.SelectedItems.Count == 0) { index = 0; } if (res == "OK") { if (selectListView.Items[index].SubItems[9].Text == "未判定") { checkedNum++; // 只有在未判定更改状态后才+1 } selectListView.Items[index].BackColor = Color.Green; #region 更新数据库 try { AoiModel aoiModel = DB.GetAoiModel(); Result users = aoiModel.results.Find(selectListView.Items[index].SubItems[5].Text); users.IsMisjudge = 1; Pcb pcb = aoiModel.pcbs.Find(users.PcbId); pcb.IsMisjudge = 1; int result = aoiModel.SaveChanges(); aoiModel.Dispose(); } catch (Exception err) { } #endregion } else if (res == "NG") { if (selectListView.Items[index].SubItems[9].Text == "未判定") { checkedNum++; // 只有在未判定更改状态后才+1 } selectListView.Items[index].BackColor = Color.Yellow; } else { return; } selectListView.Items[index].SubItems[9].Text = res; // 判断是否到最后一行 if (index + 1 >= selectListView.Items.Count) // 是最后一行 { #region 查询是否存在未校验的数据 if (!hasListViewUncheck()) // 数据校验完毕 { //main.doLeisure(true); // 主要应用于,客户手动选了行,造成前面有些未验证 if (checkedNum >= needCheckNumAll) { main.doLeisure(true); bitmapFront.Dispose(); bitmapBack.Dispose(); } else { if (tabListView.SelectedIndex == 0) { tabListView.SelectedIndex = 1; } else if (tabListView.SelectedIndex == 1) { tabListView.SelectedIndex = 0; } } return; } else // 未校验完毕,返回第一行从新开始 { selectListView.SelectedIndices.Remove(index); index = 0; selectListView.SelectedIndices.Add(index); //由于光标不会跟着移动,需要手动设置 selectListView.FocusedItem = selectListView.Items[index]; } #endregion } else { selectListView.SelectedIndices.Remove(index); selectListView.SelectedIndices.Add(++index); //由于光标不会跟着移动,需要手动设置 selectListView.FocusedItem = selectListView.Items[index]; } if (checkedNum >= needCheckNumAll) { main.doLeisure(true); bitmapFront.Dispose(); bitmapBack.Dispose(); } } catch (Exception err) { LogHelper.WriteLog("update result", err); } }