Esempio n. 1
0
 private void dgvData_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
     {
         if (dgvData.Columns[e.ColumnIndex].Name == "ColDelete")
         {
             Maticsoft.Model.SMT_WEEKEX_INFO info = (Maticsoft.Model.SMT_WEEKEX_INFO)dgvData.Rows[e.RowIndex].Tag;
             if (MessageBox.Show("确定删除该假期约束?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
             {
                 CtrlWaiting waiting = new CtrlWaiting(() =>
                 {
                     try
                     {
                         Maticsoft.BLL.SMT_WEEKEX_INFO wbll = new Maticsoft.BLL.SMT_WEEKEX_INFO();
                         wbll.Delete(info.ID);
                         SmtLog.InfoFormat("设置", "删除假期约束:{0},开始时间:{1},结束时间:{2},描述:{3}", info.WEEKEX_ON_DUTY ? "上班[允许开门]" : "假期[不能开门]", info.WEEKEX_START_DATE, info.WEEKEX_END_DATE, info.WEEKEX_DESC);
                         this.Invoke(new Action(() =>
                         {
                             dgvData.Rows.Remove(dgvData.Rows[e.RowIndex]);
                         }));
                     }
                     catch (System.Exception ex)
                     {
                         WinInfoHelper.ShowInfoWindow(this, "删除假期约束异常:" + ex.Message);
                         log.Error("删除假期约束异常:", ex);
                     }
                 });
                 waiting.Show(this);
             }
         }
     }
 }
Esempio n. 2
0
        private void FrmHolidaySetting_Load(object sender, EventArgs e)
        {
            cboHolidayType.SelectedIndex = 0;
            dtpEndDate.Value             = DateTime.Now.AddDays(1);
            CtrlWaiting waiting = new CtrlWaiting(() =>
            {
                Maticsoft.BLL.SMT_WEEKEX_INFO weekBll = new Maticsoft.BLL.SMT_WEEKEX_INFO();
                var models = weekBll.GetModelList("");
                this.Invoke(new Action(() =>
                {
                    foreach (var item in models)
                    {
                        AddToGrid(item);
                    }
                }));
            });

            waiting.Show(this);
        }
Esempio n. 3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            DateTime dtStart = DateTime.Parse(dtpStartDate.Value.ToString("yyyy-MM-dd HH:mm:00"));
            DateTime dtEnd   = DateTime.Parse(dtpEndDate.Value.ToString("yyyy-MM-dd HH:mm:00"));

            if (dtStart > dtEnd)
            {
                WinInfoHelper.ShowInfoWindow(this, "开始时间大于结束时间!");
                return;
            }
            Maticsoft.Model.SMT_WEEKEX_INFO info = new Maticsoft.Model.SMT_WEEKEX_INFO();
            info.WEEKEX_ON_DUTY    = cboHolidayType.SelectedIndex == 1;
            info.WEEKEX_START_DATE = dtStart;
            info.WEEKEX_END_DATE   = dtEnd;
            info.WEEKEX_DESC       = tbDesc.Text.Trim();
            CtrlWaiting waiting = new CtrlWaiting(() =>
            {
                try
                {
                    Maticsoft.BLL.SMT_WEEKEX_INFO wbll = new Maticsoft.BLL.SMT_WEEKEX_INFO();
                    info.ID = wbll.Add(info);
                    SmtLog.InfoFormat("设置", "添加假期约束:{0},开始时间:{1},结束时间:{2},描述:{3}", info.WEEKEX_ON_DUTY ? "上班[允许开门]" : "假期[不能开门]", info.WEEKEX_START_DATE, info.WEEKEX_END_DATE, info.WEEKEX_DESC);
                    this.Invoke(new Action(() =>
                    {
                        AddToGrid(info);
                    }));
                }
                catch (System.Exception ex)
                {
                    WinInfoHelper.ShowInfoWindow(this, "添加假期约束异常:" + ex.Message);
                    log.Error("添加假期约束异常:", ex);
                }
            });

            waiting.Show(this);
        }
Esempio n. 4
0
        private void DoUpload()
        {
            CtrlWaiting waiting = new CtrlWaiting(() =>
            {
                var ctrls = ControllerHelper.GetList("1=1");
                if (ctrls.Count == 0)
                {
                    WinInfoHelper.ShowInfoWindow(this, "没有控制器!");
                    return;
                }
                Maticsoft.BLL.SMT_TIMESCALE_INFO tsBll = new Maticsoft.BLL.SMT_TIMESCALE_INFO();
                var models = tsBll.GetModelList("");
                models     = models.OrderBy(m => m.TIME_NO).ToList();//时段升序
                Maticsoft.BLL.SMT_WEEKEX_INFO wbll = new Maticsoft.BLL.SMT_WEEKEX_INFO();
                var weekexs = wbll.GetModelList("");

                SmtLog.Info("设置", "上传时间段设置");
                FrmDetailInfo.Show(false);
                FrmDetailInfo.AddOneMsg(string.Format("开始上传控制器时段:控制器数={0},时段数={1} ...", ctrls.Count, models.Count));
                List <ManualResetEvent> eventList = new List <ManualResetEvent>();
                foreach (var item in ctrls)
                {
                    ManualResetEvent evt = new ManualResetEvent(false);
                    eventList.Add(evt);
                    ThreadPool.QueueUserWorkItem(new WaitCallback((o) =>
                    {
                        try
                        {
                            var ctrl = ControllerHelper.ToController(item);
                            using (IAccessCore acc = new WGAccess())
                            {
                                if (acc.ClearTimeScales(ctrl))
                                {
                                    FrmDetailInfo.AddOneMsg(string.Format("清除控制器时间段成功:SN={0},IP={1},开始上传控制器时间段...", ctrl.sn, ctrl.ip));
                                    foreach (var model in models)
                                    {
                                        var m    = TimeScaleHelper.ToTimeScale(model);
                                        bool ret = acc.SetTimeScales(ctrl, m);
                                        if (!ret)
                                        {
                                            FrmDetailInfo.AddOneMsg(string.Format("上传控制器时间段失败:时段号={0},控制器IP={1}", model.TIME_NO, ctrl.ip), isRed: true);
                                        }
                                        else
                                        {
                                            FrmDetailInfo.AddOneMsg(string.Format("上传控制器时间段成功:时段号={0},控制器IP={1}", model.TIME_NO, ctrl.ip));
                                        }
                                    }
                                }
                                else
                                {
                                    FrmDetailInfo.AddOneMsg(string.Format("清除控制器时间段失败:SN={0},IP={1},结束该控制器上传...", ctrl.sn, ctrl.ip), isRed: true);
                                }

                                if (acc.SetHoliday(ctrl, new HolidayPrm()
                                {
                                    IsClear = true,
                                    startDate = DateTime.Now,
                                    endDate = DateTime.Now.AddDays(1)
                                }))
                                {
                                    FrmDetailInfo.AddOneMsg(string.Format("清除控制器假期约束成功:SN={0},IP={1},开始上传假期约束...", ctrl.sn, ctrl.ip));
                                    foreach (var w in weekexs)
                                    {
                                        bool ret = acc.SetHoliday(ctrl, new HolidayPrm()
                                        {
                                            IsClear   = false,
                                            IsOnDuty  = w.WEEKEX_ON_DUTY,
                                            startDate = w.WEEKEX_START_DATE,
                                            endDate   = w.WEEKEX_END_DATE
                                        });
                                        if (!ret)
                                        {
                                            FrmDetailInfo.AddOneMsg(string.Format("上传控制器假期约束失败:约束={0},起止时间={1}~{2},控制器IP={3}", w.WEEKEX_ON_DUTY ? "上班" : "假期", w.WEEKEX_START_DATE, w.WEEKEX_END_DATE, ctrl.ip), isRed: true);
                                        }
                                        else
                                        {
                                            FrmDetailInfo.AddOneMsg(string.Format("上传控制器假期约束成功:约束={0},起止时间={1}~{2},控制器IP={3}", w.WEEKEX_ON_DUTY ? "上班" : "假期", w.WEEKEX_START_DATE, w.WEEKEX_END_DATE, ctrl.ip));
                                        }
                                    }
                                }
                                else
                                {
                                    FrmDetailInfo.AddOneMsg(string.Format("清除控制器假期约束失败:SN={0},IP={1}", ctrl.sn, ctrl.ip), isRed: true);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            FrmDetailInfo.AddOneMsg(string.Format("上传控制器时间段失败:SN={0},IP={1},异常信息:{2},结束该控制器上传...", item.SN_NO, item.IP, ex.Message), isRed: true);
                            log.Error("上传控制器时间段失败,", ex);
                            SmtLog.ErrorFormat("设置", "上传控制器时间段失败:SN={0},IP={1},异常信息:{2},结束该控制器上传...", item.SN_NO, item.IP, ex.Message);
                        }
                        finally
                        {
                            evt.Set();
                        }
                    }));
                }
                foreach (var item in eventList)
                {
                    item.WaitOne(60000);
                }
                FrmDetailInfo.AddOneMsg("结束控制器时段上传!");
            });

            waiting.Show(this);
        }