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;
            }
        }
 private void mnu_Clear_Click(object sender, EventArgs e)
 {
     List<ShiftArrange> sas = new List<ShiftArrange>();
     foreach (DataGridViewCell cell in GridView.SelectedCells)
     {
         if (cell.Tag is List<Shift>) //人员排班的单元格
         {
             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>;
             foreach (Shift shift in shifts)
             {
                 ShiftArrange sa = new ShiftArrange();
                 sa.StaffID = staff.ID;
                 sa.ShiftDate = dt;
                 sa.ShiftID = shift.ID;
                 sa.Shift = shift;
                 sas.Add(sa);
             }
         }
     }
     ShiftArrangeBLL bll = new ShiftArrangeBLL(AppSettings.CurrentSetting.ConnectUri);
     CommandResult ret = bll.Delete(sas);
     btnFresh_Click(btnFresh, EventArgs.Empty);
 }