123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507 |
- using DevExpress.XtraSplashScreen;
- using GCAS.Actions;
- using GCAS.Code;
- using GCAS.Dto;
- using GCAS.Localization;
- using GCAS.Model;
- using GCAS.Reports;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Threading;
- using System.Windows.Forms;
- namespace GCAS
- {
- public partial class MainForm : DevExpress.XtraEditors.XtraForm
- {
- private List<EntranceModel> entranceModels;
- private EntranceRepository EntranceRepository;
- private List<DeviceModel> deviceModels;
- private DeviceRepository deviceRepository;
- private List<NameValue> L;
- public OperatorModel Operator;
- public MainForm()
- {
- InitializeComponent();
- L = LocalizationHelper.GetSource(Thread.CurrentThread.CurrentUICulture);
- mdiManager.ClosePageButtonShowMode = DevExpress.XtraTab.ClosePageButtonShowMode.InAllTabPagesAndTabControlHeader;
- helpProvider1.HelpNamespace = Application.StartupPath + $"/Sources/{Thread.CurrentThread.CurrentUICulture.Name}.chm";
- helpProvider1.SetShowHelp(this, true);
- deviceRepository = new DeviceRepository();
- EntranceRepository = new EntranceRepository();
- }
- private void MainForm_Load(object sender, EventArgs e)
- {
- bar_operator.Caption = L.GetString("operator") + Operator?.Name;
- mdiManager.MdiParent = this;
- timer_currentTime.Interval = 1000;
- timer_currentTime.Start();
- if (Operator.Role == 1)
- {
- nbg_user.Visible = false;
- nbg_actions.Visible = false;
- }
- ShowMessage();
- entranceModels = EntranceRepository.GetList();
- deviceModels = deviceRepository.GetList();
- if (deviceModels.Count > 1)
- {
- if (entranceModels.Count > 2)
- {
- RealTimeForm form = new RealTimeForm
- {
- currentUser = Operator,
- MdiParent = this
- };
- form.Show();
- }
- else
- {
- RealTimeTwoCarForm form = new RealTimeTwoCarForm
- {
- currentUser = Operator,
- MdiParent = this
- };
- form.Show();
- }
- }
- else
- {
- if (entranceModels.Count > 1)
- {
- RealTimeOneCarTwoEntanceForm form = new RealTimeOneCarTwoEntanceForm
- {
- currentUser = Operator,
- MdiParent = this
- };
- form.Show();
- }
- else
- {
- RealTimeOneCarForm form = new RealTimeOneCarForm
- {
- currentUser = Operator,
- MdiParent = this
- };
- form.Show();
- }
- }
-
- HideMessage();
- }
- public void theout(object source, System.Timers.ElapsedEventArgs e)
- {
- if (IsHandleCreated)
- {
- var forms = MdiChildren;
- if (forms.Length > 0)
- {
- Invoke(new EventHandler(delegate
- {
- Form form = forms[new Random().Next(0, forms.Length - 1)];
- if (form.Name == "RealTimeForm")
- {
- var realForm = form as RealTimeForm;
- realForm.BindTable(null);
- realForm.BindChart();
- }
- form.Activate();
- }));
- }
- }
- }
- public void chartRef(object source, System.Timers.ElapsedEventArgs e)
- {
- if (IsHandleCreated)
- {
- var form = MdiChildren.FirstOrDefault(c => c.Name == "RealTimeForm");
- if (form != null)
- {
- Invoke(new EventHandler(delegate
- {
- var realForm = form as RealTimeForm;
- realForm.BindChart();
- }));
- }
- }
- }
- private void timer_currentTime_Tick(object sender, EventArgs e)
- {
- bar_time.Caption = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- }
- private void btn_singout_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
- {
- DialogResult = DialogResult.Retry;
- Close();
- }
- private void nbi_device_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
- {
- if (!MdiChildren.Any(c => c.Name == "DeviceForm"))
- {
- DeviceForm form = new DeviceForm
- {
- currentUser = Operator,
- MdiParent = this
- };
- form.Show();
- }
- else
- {
- MdiChildren.First(c => c.Name == "DeviceForm").Activate();
- }
- }
- private void nbi_main_realtime_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
- {
-
- if (MdiChildren.Any(c => c.Name == "RealTimeForm"))
- {
- MdiChildren.First(c => c.Name == "RealTimeForm").Activate();
- }
- else if (MdiChildren.Any(c => c.Name == "RealTimeOneCarForm"))
- {
- MdiChildren.First(c => c.Name == "RealTimeOneCarForm").Activate();
- }
- else if (MdiChildren.Any(c => c.Name == "RealTimeTwoCarForm"))
- {
- MdiChildren.First(c => c.Name == "RealTimeTwoCarForm").Activate();
- }
- else if (MdiChildren.Any(c => c.Name == "RealTimeOneCarTwoEntanceForm"))
- {
- MdiChildren.First(c => c.Name == "RealTimeOneCarTwoEntanceForm").Activate();
- }
- else {
- ShowMessage();
- if (deviceModels.Count > 1)//两台车用两车的显示页面
- {
- if (entranceModels.Count>2)//两车两料口
- {
- RealTimeForm form = new RealTimeForm
- {
- currentUser = Operator,
- MdiParent = this
- };
- form.Show();
- }
- else//两车三料口
- {
- RealTimeOneCarForm form = new RealTimeOneCarForm
- {
- currentUser = Operator,
- MdiParent = this
- };
- form.Show();
- }
- }
- else
- {
- if (entranceModels.Count > 1)//一车两料口
- {
- RealTimeOneCarTwoEntanceForm form = new RealTimeOneCarTwoEntanceForm
- {
- currentUser = Operator,
- MdiParent = this
- };
- form.Show();
- }
- else//一车一料口
- {
- RealTimeOneCarForm form = new RealTimeOneCarForm
- {
- currentUser = Operator,
- MdiParent = this
- };
- form.Show();
- }
- }
- HideMessage();
- }
- }
- private void nbi_main_record_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
- {
- if (!MdiChildren.Any(c => c.Name == "RecordForm"))
- {
- RecordForm form = new RecordForm
- {
- currentUser = Operator,
- MdiParent = this
- };
- form.Show();
- }
- else
- {
- MdiChildren.First(c => c.Name == "RecordForm").Activate();
- }
- }
- private void btn_sysset_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
- {
- SystemSetForm form = new SystemSetForm
- {
- currentUser = Operator,
- };
- form.ShowDialog();
- }
- private void nbi_user_list_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
- {
- if (!MdiChildren.Any(c => c.Name == "OperatorForm"))
- {
- OperatorForm form = new OperatorForm
- {
- currentUser = Operator,
- MdiParent = this
- };
- form.Show();
- }
- else
- {
- MdiChildren.First(c => c.Name == "OperatorForm").Activate();
- }
- }
- private void btn_serverset_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
- {
- using (ServerSet form = new ServerSet())
- {
- form.currentUser = Operator;
- if (form.ShowDialog() == DialogResult.OK)
- {
- Application.Restart();
- }
- }
- }
- private void nbi_team_list_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
- {
- if (!MdiChildren.Any(c => c.Name == "TeamForm"))
- {
- TeamForm form = new TeamForm
- {
- currentUser = Operator,
- MdiParent = this
- };
- form.Show();
- }
- else
- {
- MdiChildren.First(c => c.Name == "TeamForm").Activate();
- }
- }
- private void btn_changePwd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
- {
- using (ChangePwd form = new ChangePwd())
- {
- form.currentOperator = Operator;
- if (form.ShowDialog() == DialogResult.OK)
- {
- }
- }
- }
- private void nbi_actions_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
- {
- if (!MdiChildren.Any(c => c.Name == "ActionsLog"))
- {
- ActionsLog form = new ActionsLog
- {
- MdiParent = this
- };
- form.Show();
- }
- else
- {
- MdiChildren.First(c => c.Name == "ActionsLog").Activate();
- }
- }
- private void nbi_chart_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
- {
- if (!MdiChildren.Any(c => c.Name == "ChartForm"))
- {
- ChartForm form = new ChartForm
- {
- MdiParent = this
- };
- form.Show();
- }
- else
- {
- MdiChildren.First(c => c.Name == "ChartForm").Activate();
- }
- }
- private void nbi_report_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
- {
- if (!MdiChildren.Any(c => c.Name == "ReportForm"))
- {
- ReportForm form = new ReportForm
- {
- MdiParent = this
- };
- form.Show();
- }
- else
- {
- MdiChildren.First(c => c.Name == "ReportForm").Activate();
- }
- }
- private void nbi_entrance_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
- {
- if (!MdiChildren.Any(c => c.Name == "EntranceForm"))
- {
- EntranceForm form = new EntranceForm
- {
- MdiParent = this,
- currentUser = Operator
- };
- form.Show();
- }
- else
- {
- MdiChildren.First(c => c.Name == "EntranceForm").Activate();
- }
- }
- private SplashScreenManager _loadForm;
- /// <summary>
- /// 等待窗体管理对象
- /// </summary>
- protected SplashScreenManager LoadForm
- {
- get
- {
- if (_loadForm == null)
- {
- _loadForm = new SplashScreenManager(this, typeof(FrmWaitForm), true, true)
- {
- ClosingDelay = 0
- };
- }
- return _loadForm;
- }
- }
- /// <summary>
- /// 显示等待窗体
- /// </summary>
- public void ShowMessage()
- {
- bool flag = !LoadForm.IsSplashFormVisible;
- if (flag)
- {
- LoadForm.ShowWaitForm();
- }
- }
- /// <summary>
- /// 关闭等待窗体
- /// </summary>
- public void HideMessage()
- {
- bool isSplashFormVisible = LoadForm.IsSplashFormVisible;
- if (isSplashFormVisible)
- {
- LoadForm.CloseWaitForm();
- }
- }
- private void btn_help_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
- {
- Help.ShowHelp(this, helpProvider1.HelpNamespace);
- }
- private void MainForm_Resize(object sender, EventArgs e)
- {
- if (WindowState != FormWindowState.Minimized)
- {
- if (Width <= 1024)
- {
- navBarControl1.Width = 177;
- }
- else
- {
- navBarControl1.Width = 241;
- }
- }
- }
- private void Exit_ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (MessageBox.Show("退出后将无法计量称重数据,是否确认退出程序?", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
- {
- DialogResult = DialogResult.Cancel;
- // 关闭所有的线程
- Dispose();
- Close();
- }
- }
- private void Main_ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- DialogResult = DialogResult.Ignore;
- ShowInTaskbar = true;
- //还原窗体显示
- WindowState = FormWindowState.Maximized;
- //激活窗体并给予它焦点
- Activate();
- }
- protected override void OnClosing(CancelEventArgs e)
- {
- if (DialogResult == DialogResult.Cancel)
- {
- e.Cancel = true;
- WindowState = FormWindowState.Minimized;
- ShowInTaskbar = false;
- notifyIcon1.Visible = true;
- }
- else
- {
- e.Cancel = true;
- }
- }
- private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- DialogResult = DialogResult.Ignore;
- ShowInTaskbar = true; notifyIcon1.Visible = false;
- //还原窗体显示
- WindowState = FormWindowState.Maximized;
- //激活窗体并给予它焦点
- Activate();
- }
- }
- }
- }
|