public CommandResult ShiftArrange(int staffID, DateTime dt, List<Shift> shifts)
 {
     IShiftArrangeProvider provider = ProviderFactory.Create<IShiftArrangeProvider>(_RepoUri);
     ShiftArrangeSearchCondition con = new ShiftArrangeSearchCondition();
     con.StaffID = staffID;
     con.ShiftDate = new DatetimeRange(dt, dt);
     List<ShiftArrange> items = provider.GetItems(con).QueryObjects;
     IUnitWork unitWork = ProviderFactory.Create<IUnitWork>(_RepoUri);
     foreach (ShiftArrange item in items)
     {
         provider.Delete(item, unitWork);
     }
     if (shifts != null && shifts.Count > 0)
     {
         foreach (Shift item in shifts)
         {
             ShiftArrange sa = new Model.ShiftArrange()
             {
                 StaffID = staffID,
                 ShiftID = item.ID,
                 ShiftDate = dt
             };
             provider.Insert(sa, unitWork);
         }
     }
     return unitWork.Commit();
 }
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (CheckInput())
            {
                ShiftArrangeBLL bll = new ShiftArrangeBLL(AppSettings.CurrentSetting.ConnectUri);
                ShiftArrangeSearchCondition con = new ShiftArrangeSearchCondition();
                con.StaffID = (txtStaff.Tag as Staff).ID;
                con.ShiftDate = new DatetimeRange(dtBegin.Value, dtEnd.Value);
                List<ShiftArrange> items = bll.GetItems(con).QueryObjects;
                List<Staff> copyees = departmentTreeview1.SelectedStaff;
                FrmProcessing frm = new FrmProcessing();

                Action action = delegate()
                {
                    decimal count = 0;
                    try
                    {
                        foreach (Staff staff in copyees)
                        {
                            List<ShiftArrange> sas = new List<ShiftArrange>();
                            if (items != null && items.Count > 0)
                            {
                                foreach (ShiftArrange sa in items)
                                {
                                    if (staff.HireDate.Date <= sa.ShiftDate.Date)
                                    {
                                        sa.StaffID = staff.ID;
                                        sas.Add(sa);
                                    }
                                }
                            }
                            count++;
                            frm.ShowProgress(string.Format("正在复制到 {0}...", staff.Name), count / copyees.Count);
                            if (sas.Count > 0)
                            {
                                CommandResult ret = bll.ShiftArrange(staff.ID, new DatetimeRange(dtBegin.Value, dtEnd.Value), sas);
                            }
                        }
                    }
                    catch (ThreadAbortException)
                    {
                    }
                };
                Thread t = new Thread(new ThreadStart(action));
                t.IsBackground = true;
                t.Start();
                if (frm.ShowDialog() != DialogResult.OK)
                {
                    t.Abort();
                }
                this.DialogResult = DialogResult.OK;
            }
        }
 public CommandResult ShiftArrange(int staffID, DatetimeRange range, List<ShiftArrange> arranges)
 {
     IShiftArrangeProvider provider = ProviderFactory.Create<IShiftArrangeProvider>(_RepoUri);
     ShiftArrangeSearchCondition con = new ShiftArrangeSearchCondition();
     con.StaffID = staffID;
     con.ShiftDate = range;
     List<ShiftArrange> items = provider.GetItems(con).QueryObjects;
     IUnitWork unitWork = ProviderFactory.Create<IUnitWork>(_RepoUri);
     foreach (ShiftArrange item in items)
     {
         provider.Delete(item, unitWork);
     }
     if (arranges != null && arranges.Count > 0)
     {
         foreach (ShiftArrange item in arranges)
         {
             provider.Insert(item, unitWork);
         }
     }
     return unitWork.Commit();
 }
        private bool CreateAttendanceResults(Staff staff, DatetimeRange dr, List<string> readers)
        {
            ShiftArrangeSearchCondition con1 = new ShiftArrangeSearchCondition();
            con1.StaffID = staff.ID;
            con1.ShiftDate = dr;
            List<ShiftArrange> sas = (new ShiftArrangeBLL(AppSettings.CurrentSetting.ConnectUri)).GetItems(con1).QueryObjects;

            TASheetSearchCondition con2 = new TASheetSearchCondition();
            con2.StaffID = staff.ID;
            List<TASheet> sheets = (new TASheetBLL(AppSettings.CurrentSetting.ConnectUri)).GetItems(con2).QueryObjects;

            AttendanceLogSearchCondition con3 = new AttendanceLogSearchCondition();
            con3.Staff = new List<int>();
            con3.Staff.Add(staff.ID);
            con3.Readers = readers;
            con3.ReadDateTime = dr;
            con3.ContainManualLogs = true;
            List<AttendanceLog> records = (new AttendanceLogBLL(AppSettings.CurrentSetting.ConnectUri)).GetItems(con3).QueryObjects;

            List<AttendanceResult> results = (new AttendanceAnalyst()).Analist(staff, sas, records, sheets, dr);
            CommandResult ret = (new AttendanceResultBLL(AppSettings.CurrentSetting.ConnectUri)).Add(staff.ID, dr, results);
            return ret.Result == ResultCode.Successful;
        }
 private void mnu_CopyToOtherDate_Click(object sender, EventArgs e)
 {
     if (GridView.SelectedCells != null && GridView.SelectedCells.Count == 1)
     {
         DataGridViewCell cell = GridView.SelectedCells[0];
         if (_DateColumns.Contains(GridView.Columns[cell.ColumnIndex]))
         {
             DateTime dt = Convert.ToDateTime(GridView.Columns[cell.ColumnIndex].Tag);
             Staff staff = GridView.Rows[cell.RowIndex].Tag as Staff;
             List<Shift> shifts = cell.Tag as List<Shift>;
             FrmCopyToDate frm = new FrmCopyToDate();
             frm.Staff = staff;
             frm.SourceDate = dt;
             frm.SourceShifts = shifts;
             if (frm.ShowDialog() == DialogResult.OK)
             {
                 ShiftArrangeSearchCondition con = new ShiftArrangeSearchCondition();
                 con.StaffID = staff.ID;
                 con.ShiftDate = new DatetimeRange(ucDateTimeInterval1.StartDateTime, ucDateTimeInterval1.EndDateTime);
                 List<ShiftArrange> items = (new ShiftArrangeBLL(AppSettings.CurrentSetting.ConnectUri)).GetItems(con).QueryObjects;
                 ShowUserShiftArrangesOnRow(staff, items, GridView.Rows[cell.RowIndex]);
             }
         }
     }
 }
        private void btnFresh_Click(object sender, EventArgs e)
        {
            GridView.Rows.Clear();
            InitGridColumns(ucDateTimeInterval1.StartDateTime, ucDateTimeInterval1.EndDateTime);

            List<Staff> users = departmentTreeview1.SelectedStaff;
            if (users != null && users.Count > 0)
            {
                ShiftArrangeSearchCondition con = new ShiftArrangeSearchCondition();
                con.ShiftDate = new DatetimeRange(ucDateTimeInterval1.StartDateTime, ucDateTimeInterval1.EndDateTime);
                List<ShiftArrange> arranges = (new ShiftArrangeBLL(AppSettings.CurrentSetting.ConnectUri)).GetItems(con).QueryObjects;
                foreach (Staff user in users)
                {
                    int row = GridView.Rows.Add();
                    List<ShiftArrange> items = arranges.Where(item => item.StaffID == user.ID).ToList();
                    ShowUserShiftArrangesOnRow(user, items, GridView.Rows[row]);
                    arranges.RemoveAll(item => item.StaffID == user.ID);
                }
            }
            this.toolStripStatusLabel1.Text = string.Format("总共 {0} 项", GridView.Rows.Count);
        }
 public CommandResult ClearShiftArrange(int staffID, DateTime dt)
 {
     IShiftArrangeProvider provider = ProviderFactory.Create<IShiftArrangeProvider>(_RepoUri);
     ShiftArrangeSearchCondition con = new ShiftArrangeSearchCondition();
     con.StaffID = staffID;
     con.ShiftDate = new DatetimeRange(dt, dt);
     List<ShiftArrange> items = provider.GetItems(con).QueryObjects;
     IUnitWork unitWork = ProviderFactory.Create<IUnitWork>(_RepoUri);
     foreach (ShiftArrange item in items)
     {
         provider.Delete(item, unitWork);
     }
     return unitWork.Commit();
 }