示例#1
0
        private void DoSave(bool isupload = false)
        {
            if (dgvSelected.Rows.Count == 0)
            {
                WinInfoHelper.ShowInfoWindow(this, "请至少选一个待复制的人员!");
                return;
            }
            List <Maticsoft.Model.SMT_STAFF_INFO> staffInfos = new List <Maticsoft.Model.SMT_STAFF_INFO>();

            foreach (DataGridViewRow item in dgvSelected.Rows)
            {
                staffInfos.Add((Maticsoft.Model.SMT_STAFF_INFO)item.Tag);
            }
            CtrlWaiting waiting = new CtrlWaiting(() =>
            {
                Maticsoft.BLL.SMT_STAFF_DOOR sdbll = new Maticsoft.BLL.SMT_STAFF_DOOR();
                try
                {
                    foreach (var item in staffInfos)
                    {
                        var olddoors = sdbll.GetModelList("STAFF_ID=" + item.ID);
                        var notexist = olddoors.FindAll(m =>
                        {
                            return(!_staffDoors.Exists(n => n.DOOR_ID == m.DOOR_ID));
                        });
                        foreach (var old in notexist)
                        {
                            sdbll.Delete(old.STAFF_ID, old.DOOR_ID);
                            olddoors.Remove(old);
                        }
                        notexist = _staffDoors.FindAll(m =>
                        {
                            return(!olddoors.Exists(n => n.DOOR_ID == m.DOOR_ID));
                        });
                        foreach (var newdoor in notexist)
                        {
                            sdbll.Add(new Maticsoft.Model.SMT_STAFF_DOOR()
                            {
                                ADD_TIME    = DateTime.Now,
                                IS_UPLOAD   = false,
                                STAFF_ID    = item.ID,
                                UPLOAD_TIME = DateTime.Now,
                                DOOR_ID     = newdoor.DOOR_ID,
                                TIME_NUM    = newdoor.TIME_NUM
                            });
                        }
                    }
                }
                catch (Exception ex)
                {
                    WinInfoHelper.ShowInfoWindow(this, "保存异常:" + ex.Message);
                    log.Error("保存异常:", ex);
                    return;
                }
                if (isupload)
                {
                    string errMsg = "";
                    bool ret      = UploadPrivate.Upload(staffInfos, out errMsg);
                    if (!ret || !string.IsNullOrWhiteSpace(errMsg))
                    {
                        WinInfoHelper.ShowInfoWindow(this, "保存成功,部分权限上传异常:" + errMsg);
                    }
                }
                this.Invoke(new Action(() =>
                {
                    this.Close();
                }));
            });

            waiting.Show(this);
        }
示例#2
0
        private void DoSaveDoors(List <Maticsoft.Model.SMT_DOOR_INFO> doors, bool upload = false)
        {
            if (dtpStart.Value.Date > dtpEnd.Value.Date)
            {
                WinInfoHelper.ShowInfoWindow(this, "起始时间不能小于结束时间!");
                return;
            }
            int          timenum = 0;
            ComboBoxItem cbi     = (ComboBoxItem)cbTimeNum.SelectedItem;

            if (cbi.Tag is Maticsoft.Model.SMT_TIMESCALE_INFO)
            {
                Maticsoft.Model.SMT_TIMESCALE_INFO tsInfo = (Maticsoft.Model.SMT_TIMESCALE_INFO)cbi.Tag;
                timenum = tsInfo.TIME_NO;
            }
            else
            {
                timenum = 1;
            }

            CtrlWaiting ctrlWaiting = new CtrlWaiting("正在保存...", () =>
            {
                try
                {
                    Maticsoft.BLL.SMT_STAFF_DOOR sdBLL = new Maticsoft.BLL.SMT_STAFF_DOOR();
                    var sdList = sdBLL.GetModelList("STAFF_ID=" + staffInfo.ID);
                    List <Maticsoft.Model.SMT_DOOR_INFO> tempDoors = new List <Maticsoft.Model.SMT_DOOR_INFO>();
                    tempDoors.AddRange(doors);
                    foreach (var item in sdList)
                    {
                        var sc = doors.Find(m => m.ID == item.DOOR_ID);
                        if (sc == null)                                //权限删除
                        {
                            sdBLL.Delete(item.STAFF_ID, item.DOOR_ID); //删除权限
                        }
                        else
                        {
                            item.TIME_NUM  = timenum;
                            item.IS_UPLOAD = false;
                            sdBLL.Update(item);
                            tempDoors.Remove(sc);
                        }
                    }
                    foreach (var item in tempDoors) //添加的权限
                    {
                        Maticsoft.Model.SMT_STAFF_DOOR newSd = new Maticsoft.Model.SMT_STAFF_DOOR();
                        newSd.ADD_TIME    = DateTime.Now;
                        newSd.DOOR_ID     = item.ID;
                        newSd.IS_UPLOAD   = false;
                        newSd.UPLOAD_TIME = DateTime.Now;
                        newSd.STAFF_ID    = staffInfo.ID;
                        newSd.TIME_NUM    = timenum;

                        sdBLL.Add(newSd);
                    }
                    if (staffInfo.VALID_STARTTIME != dtpStart.Value || staffInfo.VALID_ENDTIME != dtpEnd.Value)
                    {
                        Maticsoft.BLL.SMT_STAFF_INFO staffBll = new Maticsoft.BLL.SMT_STAFF_INFO();
                        staffInfo.VALID_STARTTIME             = dtpStart.Value.Date;
                        staffInfo.VALID_ENDTIME = dtpEnd.Value.Date + new TimeSpan(23, 59, 59);
                        staffBll.Update(staffInfo);
                    }

                    if (upload)
                    {
                        string errMsg;
                        bool ret = UploadPrivate.Upload(staffInfo, out errMsg);
                        if (ret && errMsg != "")
                        {
                            WinInfoHelper.ShowInfoWindow(this, "上传权限存在异常:" + errMsg);
                            log.Warn("上传权限存在异常:" + errMsg);
                            return;
                        }
                        else if (!ret)
                        {
                            return;
                        }
                        else
                        {
                            WinInfoHelper.ShowInfoWindow(null, "上传权限结束!");
                        }
                    }
                    this.Invoke(new Action(() =>
                    {
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }));
                }
                catch (System.Exception ex)
                {
                    log.Error("保存异常:", ex);
                    WinInfoHelper.ShowInfoWindow(this, "保存异常:" + ex.Message);
                }
            });

            ctrlWaiting.Show(this);
        }
示例#3
0
        private void DoSave(bool isupload = false)
        {
            if (dgvSelected.Rows.Count == 0)
            {
                WinInfoHelper.ShowInfoWindow(this, "请至少选一个人员!");
                return;
            }
            if (cbIsValidValid.Checked &&
                (
                    (dtValidStart.LockUpdateChecked && dtValidStart.IsEmpty) ||
                    (dtValidEnd.LockUpdateChecked && dtValidEnd.IsEmpty)
                )
                )
            {
                WinInfoHelper.ShowInfoWindow(this, "请设置选择有效的开始或结束时间!");
                return;
            }
            bool isvaliddatechanged = false;

            if (cbIsValidValid.Checked &&
                (
                    (dtValidStart.LockUpdateChecked && !dtValidStart.IsEmpty) || (dtValidEnd.LockUpdateChecked && !dtValidEnd.IsEmpty)
                )
                )
            {
                isvaliddatechanged = true;
            }
            if (isvaliddatechanged)
            {
                if (cbIsValidValid.Checked && dtValidStart.LockUpdateChecked && dtValidEnd.LockUpdateChecked && dtValidStart.Value > dtValidEnd.Value)
                {
                    WinInfoHelper.ShowInfoWindow(this, "结束时间不能小于开始时间!");
                    return;
                }
            }
            if (!isvaliddatechanged && !cbisForbidden.Checked)
            {
                WinInfoHelper.ShowInfoWindow(this, "请选择要修改的信息!");
                return;
            }

            List <Maticsoft.Model.SMT_STAFF_INFO> staffInfos = new List <Maticsoft.Model.SMT_STAFF_INFO>();

            foreach (DataGridViewRow item in dgvSelected.Rows)
            {
                staffInfos.Add((Maticsoft.Model.SMT_STAFF_INFO)item.Tag);
            }
            CtrlWaiting waiting = new CtrlWaiting(() =>
            {
                Maticsoft.BLL.SMT_STAFF_INFO staffBll = new Maticsoft.BLL.SMT_STAFF_INFO();
                try
                {
                    foreach (var item in staffInfos)
                    {
                        if (isvaliddatechanged)
                        {
                            if (dtValidStart.LockUpdateChecked && !dtValidStart.IsEmpty)
                            {
                                item.VALID_STARTTIME = dtValidStart.Value.Date;
                            }
                            if (dtValidEnd.LockUpdateChecked && !dtValidEnd.IsEmpty)
                            {
                                item.VALID_ENDTIME = dtValidEnd.Value.Date + new TimeSpan(23, 59, 59);
                            }
                        }
                        if (cbisForbidden.Checked)
                        {
                            item.IS_FORBIDDEN = !cbNormal.Checked;
                        }
                        staffBll.Update(item);
                    }
                }
                catch (Exception ex)
                {
                    WinInfoHelper.ShowInfoWindow(this, "保存异常:" + ex.Message);
                    log.Error("保存异常:", ex);
                    return;
                }
                if (isupload)
                {
                    string errMsg = "";
                    bool ret      = UploadPrivate.Upload(staffInfos, out errMsg);
                    if (!ret || !string.IsNullOrWhiteSpace(errMsg))
                    {
                        WinInfoHelper.ShowInfoWindow(this, "保存成功,部分权限上传异常:" + errMsg);
                    }
                }
                this.Invoke(new Action(() =>
                {
                    this.Close();
                }));
            });

            waiting.Show(this);
        }