123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- using DevExpress.XtraEditors;
- using DevExpress.XtraPrinting;
- using GCAS.Code;
- using GCAS.Dto;
- using GCAS.Localization;
- using GCAS.Model;
- using GCAS.Record;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Threading;
- using System.Windows.Forms;
- namespace GCAS
- {
- public partial class RecordForm : XtraForm
- {
- private List<NameValue> L;
- private RecordRepository recordRepository;
- private DeviceRepository deviceRepository;
- public OperatorModel currentUser;
- private EntranceRepository entranceRepository;
- private TeamRepository teamRepository;
- private ActionsRepository actionsRepository;
- public RecordForm()
- {
- InitializeComponent();
- L = LocalizationHelper.GetSource(Thread.CurrentThread.CurrentUICulture);
- }
- private void RecordForm_Load(object sender, EventArgs e)
- {
- //date_start.EditValue = DateTime.Today;
- //date_end.EditValue = DateTime.Today.AddDays(1).AddSeconds(-1);
- date_start.EditValue = DateTime.Now;
- date_end.EditValue = DateTime.Today.AddDays(1).AddSeconds(-1);
- recordRepository = new RecordRepository();
- deviceRepository = new DeviceRepository();
- actionsRepository = new ActionsRepository();
- entranceRepository = new EntranceRepository();
- teamRepository = new TeamRepository();
- BindDevice();
- BindEntrance();
- BindTeam();
- BindGrid();
- }
- private void btn_search_Click(object sender, EventArgs e)
- {
- BindGrid();
- }
- private void BindDevice()
- {
- var list = deviceRepository.GetList().Select(c => new KeyValuePair<int, string>(c.Id, c.Name)).ToList();
- list.Insert(0, new KeyValuePair<int, string>(0, L.GetString("All")));
- cb_device.Properties.DataSource = list;
- cb_device.Properties.DisplayMember = "Value";
- cb_device.Properties.ValueMember = "Key";
- cb_device.ItemIndex = 0;
- cb_device.Properties.ShowHeader = false;
- cb_device.Properties.ShowFooter = false;
- }
- private void BindEntrance()
- {
- var list = entranceRepository.GetList().Select(c => new KeyValuePair<int, string>(c.Id, c.Name)).ToList();
- list.Insert(0, new KeyValuePair<int, string>(0, L.GetString("All")));
- cb_entrance.Properties.DataSource = list;
- cb_entrance.Properties.DisplayMember = "Value";
- cb_entrance.Properties.ValueMember = "Key";
- cb_entrance.ItemIndex = 0;
- cb_entrance.Properties.ShowHeader = false;
- cb_entrance.Properties.ShowFooter = false;
- }
- private void BindTeam()
- {
- var list = teamRepository.GetList().Select(c => new KeyValuePair<int, string>(c.Id, c.Name)).ToList();
- list.Insert(0, new KeyValuePair<int, string>(0, L.GetString("All")));
- cb_team.Properties.DataSource = list;
- cb_team.Properties.DisplayMember = "Value";
- cb_team.Properties.ValueMember = "Key";
- cb_team.ItemIndex = 0;
- cb_team.Properties.ShowHeader = false;
- cb_team.Properties.ShowFooter = false;
- }
- private async void BindGrid()
- {
- gridView1.LoadingPanelVisible = true;
- var list = await recordRepository.GetList(
- text_key.Text,
- cb_device.EditValue == null ? 0 : (int)cb_device.EditValue,
- cb_entrance.EditValue == null ? 0 : (int)cb_entrance.EditValue,
- cb_team.EditValue == null ? 0 : (int)cb_team.EditValue,
- (DateTime)date_start.EditValue,
- (DateTime)date_end.EditValue);
- gridControl1.DataSource = list;
- gridView1.FocusedRowHandle = -1;
- gridView1.LoadingPanelVisible = false;
- }
- private void gridControl1_Load(object sender, EventArgs e)
- {
- if (File.Exists(Application.StartupPath + @"\" + Text + ".xml"))
- {
- gridView1.RestoreLayoutFromXml(Application.StartupPath + @"\" + Text + ".xml"); //加载布局
- }
- }
- private void gridView1_Layout(object sender, EventArgs e)
- {
- gridView1.SaveLayoutToXml(Application.StartupPath + @"\" + Text + ".xml");//保存布局
- }
- private void btn_export_Click(object sender, EventArgs e)
- {
- SaveFileDialog fileDialog = new SaveFileDialog
- {
- Title = "Export Excel",
- Filter = "Excel 97-2003 (*.xls)|*.xls|Excel (*.xlsx)|*.xlsx"
- };
- fileDialog.FileName = L.GetString("WeighingRecords") + ".xls";
- if (fileDialog.ShowDialog() == DialogResult.OK)
- {
- try
- {
- gridControl1.ExportToXls(fileDialog.FileName);
- XtraMessageBox.Show(L.GetString("ExportSucceeded"), L.GetString("notification"), MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- catch (Exception ex)
- {
- XtraMessageBox.Show(L.GetString("WeighingFailed") + " Info:" + ex.Message, L.GetString("notification"), MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- private void text_key_Click(object sender, EventArgs e)
- {
- SoftKeyboard.ActiveSoftKeyboard(sender);
- }
- private void gridView1_MouseDown(object sender, MouseEventArgs e)
- {
- }
- private void btn_print_Click(object sender, EventArgs e)
- {
- PrintableComponentLink link = new PrintableComponentLink(new PrintingSystem())
- {
- Component = gridControl1,
- Landscape = true,
- PaperKind = System.Drawing.Printing.PaperKind.A4,
- };
- link.CreateMarginalHeaderArea += new CreateAreaEventHandler(Link_CreateMarginalHeaderArea);
- link.CreateDocument();
- link.ShowPreview();
- }
- private void Link_CreateMarginalHeaderArea(object sender, CreateAreaEventArgs e)
- {
- PageInfoBrick brickTitle = e.Graph.DrawPageInfo(PageInfo.None, "称重记录", Color.Black, new RectangleF(0, 0, 100, 30), BorderSide.None);
- brickTitle.LineAlignment = BrickAlignment.Center;
- brickTitle.Alignment = BrickAlignment.Center;
- brickTitle.AutoWidth = true;
- brickTitle.Font = new Font("Tahoma", 16f, FontStyle.Bold);
- PageInfoBrick brickSubtitle = e.Graph.DrawPageInfo(PageInfo.None, L.GetString("dateRange") + date_start.Text + " 00:00 - " + date_end.Text + " 23:59", Color.Black, new RectangleF(0, 10, 100, 20), BorderSide.None);
- brickSubtitle.LineAlignment = BrickAlignment.Far;
- brickSubtitle.Alignment = BrickAlignment.Far;
- brickSubtitle.AutoWidth = true;
- brickSubtitle.Font = new Font("Tahoma", 9f, FontStyle.Regular);
- PageInfoBrick brickType = e.Graph.DrawPageInfo(PageInfo.None, "设备:" + cb_device.Text + " 料口:" + cb_entrance.Text + " 班组:" + cb_device.Text, Color.Black, new RectangleF(0, 0, 100, 20), BorderSide.None);
- brickType.LineAlignment = BrickAlignment.Near;
- brickType.Alignment = BrickAlignment.Near;
- brickType.AutoWidth = true;
- brickType.Font = new Font("Tahoma", 9f, FontStyle.Regular);
- }
- }
- }
|