2160 lines
		
	
	
		
			83 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			2160 lines
		
	
	
		
			83 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using HelperDB;
 | ||
| using AIMSExtension;
 | ||
| using System;
 | ||
| using System.Collections.Generic;
 | ||
| using System.Data;
 | ||
| using System.Drawing;
 | ||
| using System.Linq;
 | ||
| using System.Text;
 | ||
| using System.Windows.Forms;
 | ||
| using DCSoftDotfuscate;
 | ||
| 
 | ||
| namespace AIMS.OperationFront.UI
 | ||
| {
 | ||
|     public partial class frmPersonSchedul : Form
 | ||
|     {
 | ||
|         public frmPersonSchedul()
 | ||
|         {
 | ||
|             InitializeComponent();
 | ||
|         }
 | ||
| 
 | ||
|         private int operatorId = 1;
 | ||
|         private string conditionMonth = "0";
 | ||
|         private string conditionRole = "Doctor"; //Doctor|Nurse 
 | ||
|         private DataTable dtSchedulingType = null;
 | ||
|         private DataTable dtScheduleSetup = null;
 | ||
|         private DataTable dtDoctors = null;
 | ||
|         private DataTable dtNurses = null;
 | ||
|         private DataTable dtOperationRoom = null;
 | ||
|         private DataTable dtSchedulingNew = null;
 | ||
|         private DataTable dtSchedulingNurseToOperationRoom = null;
 | ||
|         private DataTable dtMainTable = null;
 | ||
| 
 | ||
|         private Dictionary<int, string> dicDoctors = new Dictionary<int, string>();
 | ||
|         private Dictionary<int, string> dicNurses = new Dictionary<int, string>();
 | ||
|         private Dictionary<string, int> dicOperationRoomNameId = new Dictionary<string, int>();
 | ||
|         private Dictionary<int, string> dicOperationRoomIdName = new Dictionary<int, string>();
 | ||
| 
 | ||
|         private Dictionary<string, int> dicSchedulingTypeNameId = new Dictionary<string, int>();
 | ||
|         private Dictionary<int, string> dicSchedulingTypeIdName = new Dictionary<int, string>();
 | ||
|         private string[] validSchedulingTypes = null;
 | ||
|         private string[] doctorRoles = new string[1] { "医生" };
 | ||
|         private string[] nurseRoles = new string[3] { " ", "洗手", "巡回" };
 | ||
|         private List<string> listHeaderChinese;
 | ||
|         private List<string> listHeaderWeek;
 | ||
|         private List<string> listHeaderDays;
 | ||
| 
 | ||
|         private DataView dvSchedulingType = null;
 | ||
|         private GPDbHelper dbHelper = new GPDbHelper();
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 数据添加空值
 | ||
|         /// </summary>
 | ||
|         /// <param name="items">字符串数组</param>
 | ||
|         /// <returns></returns>
 | ||
|         private string[] ArrayAddEmptyValue(string[] items)
 | ||
|         {
 | ||
|             int n = items.Length;
 | ||
|             string[] items2 = new string[n + 1];
 | ||
|             items2[0] = "";
 | ||
|             Array.Copy(items, 0, items2, 1, n);
 | ||
|             return items2;
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 刷新排班计划中的下拉列表数据
 | ||
|         /// </summary>
 | ||
|         private void FreshDicSchedulingType()
 | ||
|         {
 | ||
|             bool isHasInvalid = chxHasInvaild.Checked;
 | ||
|             DataView dv = dtSchedulingType.DefaultView;
 | ||
|             if (!isHasInvalid)
 | ||
|             {
 | ||
|                 dv.RowFilter = "IsValid=1";
 | ||
|             }
 | ||
|             else
 | ||
|             {
 | ||
|                 dv.RowFilter = "";
 | ||
|             }
 | ||
| 
 | ||
|             Dictionary<string, int> dicValidType = new Dictionary<string, int>();
 | ||
|             dicSchedulingTypeNameId.Clear();
 | ||
|             dicSchedulingTypeIdName.Clear();
 | ||
|             foreach (DataRow dr in dtSchedulingType.Rows)
 | ||
|             {
 | ||
|                 try
 | ||
|                 {
 | ||
|                     int id = (int)dr["Id"];
 | ||
|                     string name = dr["Name"].ToString();
 | ||
|                     int isValid = int.Parse(dr["IsValid"].ToString());
 | ||
|                     dicSchedulingTypeNameId[name] = id;
 | ||
|                     dicSchedulingTypeIdName[id] = name;
 | ||
|                     if (isValid == 1)
 | ||
|                     {
 | ||
|                         dicValidType[name] = id;
 | ||
|                     }
 | ||
|                 }
 | ||
|                 catch (Exception)
 | ||
|                 {
 | ||
|                 }
 | ||
|             }
 | ||
| 
 | ||
|             string[] items;
 | ||
|             DataGridView dgv;
 | ||
|             DataGridViewComboBoxColumn cbxColumn;
 | ||
| 
 | ||
|             items = ArrayAddEmptyValue(dicValidType.Keys.ToArray());
 | ||
|             Array.Sort(items);
 | ||
|             validSchedulingTypes = items;
 | ||
| 
 | ||
|             dgv = this.dgvShiftPlan;
 | ||
|             for (int i = 1; i < 14; i++)
 | ||
|             {
 | ||
|                 string columnName = string.Format("Day{0}", i);
 | ||
|                 cbxColumn = (DataGridViewComboBoxColumn)dgv.Columns[columnName];
 | ||
|                 cbxColumn.Items.Clear();
 | ||
|                 cbxColumn.Items.AddRange(items);
 | ||
|             }
 | ||
|             dgv.Update();
 | ||
| 
 | ||
|             dgv = this.dataGridView1;
 | ||
|             if (!chxModified.Checked)
 | ||
|             {
 | ||
|                 items = ArrayAddEmptyValue(dicSchedulingTypeNameId.Keys.ToArray());
 | ||
|                 Array.Sort(items);
 | ||
|             }
 | ||
|             for (int i = 1; i <= 31; i++)
 | ||
|             {
 | ||
|                 string columnName = string.Format("Date{0}", i);
 | ||
|                 cbxColumn = (DataGridViewComboBoxColumn)dgv.Columns[columnName];
 | ||
|                 cbxColumn.Items.Clear();
 | ||
|                 cbxColumn.Items.AddRange(items);
 | ||
|             }
 | ||
|             dgv.Update();
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 由班次Id获取班次名称,为了兼容原来是名称的数据,所以判断是否是数字,如果不是数字,则直接返加
 | ||
|         /// </summary>
 | ||
|         /// <param name="id">班次Id</param>
 | ||
|         /// <returns></returns>
 | ||
|         private string getSchedulingTypeName(string id)
 | ||
|         {
 | ||
|             int _id = int.Parse(id);
 | ||
|             if (_id == 0)
 | ||
|             {
 | ||
|                 return id;
 | ||
|             }
 | ||
| 
 | ||
|             if (dicSchedulingTypeIdName.ContainsKey(_id))
 | ||
|             {
 | ||
|                 return dicSchedulingTypeIdName[_id];
 | ||
|             }
 | ||
|             return "";
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 由班次Id获取班次名称
 | ||
|         /// </summary>
 | ||
|         /// <param name="id">班次Id</param>
 | ||
|         /// <returns></returns>
 | ||
|         private string getSchedulingTypeName(int id)
 | ||
|         {
 | ||
|             if (dicSchedulingTypeIdName.ContainsKey(id))
 | ||
|             {
 | ||
|                 return dicSchedulingTypeIdName[id];
 | ||
|             }
 | ||
|             return "";
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 根据班次名称读取班次Id
 | ||
|         /// </summary>
 | ||
|         /// <param name="name"></param>
 | ||
|         /// <returns></returns>
 | ||
|         private int getSchedulingTypeId(string name)
 | ||
|         {
 | ||
|             if (dicSchedulingTypeNameId.ContainsKey(name))
 | ||
|             {
 | ||
|                 return dicSchedulingTypeNameId[name];
 | ||
|             }
 | ||
|             return 0;
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 由手术室Id获取手术室名称
 | ||
|         /// </summary>
 | ||
|         /// <param name="operationRoomId">手术室Id</param>
 | ||
|         /// <returns></returns>
 | ||
|         private string getOperationRoomName(int operationRoomId)
 | ||
|         {
 | ||
|             if (dicOperationRoomIdName.ContainsKey(operationRoomId))
 | ||
|             {
 | ||
|                 return dicOperationRoomIdName[operationRoomId];
 | ||
|             }
 | ||
|             return "";
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 由手术室名称获取手术室Id
 | ||
|         /// </summary>
 | ||
|         /// <param name="operationRoomName">手术室名称</param>
 | ||
|         /// <returns></returns>
 | ||
|         private int GetOperationRoomId(string operationRoomName)
 | ||
|         {
 | ||
|             if (dicOperationRoomNameId.ContainsKey(operationRoomName))
 | ||
|             {
 | ||
|                 return dicOperationRoomNameId[operationRoomName];
 | ||
|             }
 | ||
|             return 0;
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 读取班次数据*
 | ||
|         /// </summary>
 | ||
|         private void GetDataTableSchedulingType()
 | ||
|         {
 | ||
|             string sql = "select Id, [Name], BeginTime, EndTime, IsValid, OperatorId, OperatorTime from SchedulingType";
 | ||
|             dtSchedulingType = dbHelper.GetDataTable(sql);
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 结构时间(小时 分钟)
 | ||
|         /// </summary>
 | ||
|         struct MyHourMinute
 | ||
|         {
 | ||
|             public int hour;
 | ||
|             public int minute;
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 上下班时间
 | ||
|         /// </summary>
 | ||
|         struct MySxbTime
 | ||
|         {
 | ||
|             public DateTime sbTime;
 | ||
|             public DateTime xbTime;
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 由时间字符串解析出结构时间
 | ||
|         /// </summary>
 | ||
|         /// <param name="time">时间字符串</param>
 | ||
|         /// <returns></returns>
 | ||
|         private MyHourMinute GetMyHourMinute(string time)
 | ||
|         {
 | ||
|             MyHourMinute hm;
 | ||
|             hm.hour = -1;   /*不正确的时间表示*/
 | ||
|             hm.minute = 0;
 | ||
|             if (string.IsNullOrEmpty(time.Trim())) return hm;
 | ||
|             if (time.Contains(':')) time = time.Replace(':', ':');
 | ||
|             string[] arr = time.Split(':');
 | ||
|             if (arr.Length == 2)
 | ||
|             {
 | ||
|                 hm.minute = int.Parse(arr[1]);
 | ||
|             }
 | ||
|             hm.hour = int.Parse(arr[0]);
 | ||
|             return hm;
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 由上下班时间字符串解析出上下班时间
 | ||
|         /// </summary>
 | ||
|         /// <param name="beginTime">上班时间字符</param>
 | ||
|         /// <param name="endTime">下班时间字符</param>
 | ||
|         /// <returns></returns>
 | ||
|         private MySxbTime GetMySxbTime(string beginTime, string endTime, DateTime dateTime)
 | ||
|         {
 | ||
|             /*获取上下班时间, 如果下班时间早于上班时间,则无效*/
 | ||
|             MyHourMinute hm;
 | ||
|             MySxbTime sxbTime;
 | ||
|             if (string.IsNullOrEmpty(beginTime) || string.IsNullOrEmpty(endTime))
 | ||
|             {
 | ||
|                 sxbTime.sbTime = dateTime;
 | ||
|                 sxbTime.xbTime = dateTime.AddDays(-1);
 | ||
|                 return sxbTime;
 | ||
|             }
 | ||
| 
 | ||
|             hm = GetMyHourMinute(beginTime);
 | ||
|             sxbTime.sbTime = dateTime.AddHours(hm.hour).AddMinutes(hm.minute);
 | ||
|             hm = GetMyHourMinute(endTime);
 | ||
|             sxbTime.xbTime = dateTime.AddHours(hm.hour).AddMinutes(hm.minute);
 | ||
|             if (sxbTime.xbTime.CompareTo(sxbTime.sbTime) <= 0)
 | ||
|             {
 | ||
|                 sxbTime.xbTime = sxbTime.xbTime.AddDays(1);
 | ||
|             }
 | ||
|             return sxbTime;
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 读取班次上班时间, 为了刷新dvSchedulingType,循环调用前,请置dvSchedulingType=null
 | ||
|         /// </summary>
 | ||
|         /// <param name="schedulingTypeId">班次Id</param>
 | ||
|         /// <param name="dateTime">工作日期</param>
 | ||
|         /// <returns>上下班时间</returns>
 | ||
|         private MySxbTime GetSchedulingTypeSxbsj(int schedulingTypeId, DateTime dateTime)
 | ||
|         {
 | ||
|             MySxbTime sxbTime;
 | ||
|             if (dvSchedulingType == null)
 | ||
|             {
 | ||
|                 dvSchedulingType = new DataView(dtSchedulingType);
 | ||
|             }
 | ||
|             dvSchedulingType.RowFilter = "Id=" + schedulingTypeId.ToString();
 | ||
|             if (dvSchedulingType.Count > 0)
 | ||
|             {
 | ||
|                 string beginTime = dvSchedulingType[0]["BeginTime"].ToString();
 | ||
|                 string endTime = dvSchedulingType[0]["EndTime"].ToString();
 | ||
|                 sxbTime = GetMySxbTime(beginTime, endTime, dateTime);
 | ||
|             }
 | ||
|             else
 | ||
|             {
 | ||
|                 sxbTime.sbTime = dateTime;
 | ||
|                 sxbTime.xbTime = dateTime;
 | ||
|             }
 | ||
|             return sxbTime;
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 读取手术麻醉科医生 护士 手术间信息
 | ||
|         /// </summary>
 | ||
|         private void GetDataTableDoctorsNursesRoom()
 | ||
|         {
 | ||
|             /*读取手术麻醉科医生信息 WorkersType=2*/
 | ||
|             string sql;
 | ||
|             //if (PublicMethod.hospitals.Name== "山西省心血管病医院")
 | ||
|             sql = "select  w.Id, w.[Name], w.[HelpCode] HCode, w.[PersonOrder] Orderby from Person as w where w.PersonType='麻醉医生' and w.IsValid=1   order by w.[PersonOrder]  ";
 | ||
|             dtDoctors = dbHelper.GetDataTable(sql);
 | ||
| 
 | ||
|             /*读取手术麻醉科护士信息 WorkersType=1*/
 | ||
|             sql = "select  w.Id, w.[Name], w.[HelpCode] HCode, w.[PersonOrder] Orderby from Person as w where w.PersonType='手术室护士' and w.IsValid=1   order by w.[PersonOrder] ";
 | ||
|             dtNurses = dbHelper.GetDataTable(sql);
 | ||
| 
 | ||
|             /*读取手术间信息*/
 | ||
|             sql = "select id, [Name] from OperationRoom where IsValid=1 order by [RoomOrder]";
 | ||
|             dtOperationRoom = dbHelper.GetDataTable(sql);
 | ||
| 
 | ||
|             dicDoctors.Clear();
 | ||
|             foreach (DataRow dr in dtDoctors.Rows)
 | ||
|             {
 | ||
|                 dicDoctors.Add((int)dr["Id"], dr["Name"].ToString());
 | ||
|             }
 | ||
| 
 | ||
|             dicNurses.Clear();
 | ||
|             foreach (DataRow dr in dtNurses.Rows)
 | ||
|             {
 | ||
|                 dicNurses.Add((int)dr["Id"], dr["Name"].ToString());
 | ||
|             }
 | ||
| 
 | ||
|             dicOperationRoomNameId.Clear();
 | ||
|             dicOperationRoomIdName.Clear();
 | ||
|             foreach (DataRow dr in dtOperationRoom.Rows)
 | ||
|             {
 | ||
|                 string name = dr["Name"].ToString();
 | ||
|                 int id = (int)dr["Id"];
 | ||
|                 if (!dicOperationRoomNameId.ContainsKey(name))
 | ||
|                 {
 | ||
|                     dicOperationRoomNameId.Add(name, id);
 | ||
|                     dicOperationRoomIdName.Add(id, name);
 | ||
|                 }
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 从数据库中读取排班计划到页面中
 | ||
|         /// </summary>
 | ||
|         private void GetDataTableShiftPlan()
 | ||
|         {
 | ||
|             /*从数据库中读取排班计划到页面中*/
 | ||
|             string sql = "select id,ScheduleName, ScheduleTypeId, RoundDays, isValid, OperatorNo, OperatorTime from ScheduleSetup";
 | ||
|             DataTable dataTable = dbHelper.GetDataTable(sql);
 | ||
|             dtScheduleSetup = dataTable;
 | ||
| 
 | ||
|             for (int i = 1; i < 14; i++)
 | ||
|             {
 | ||
|                 dataTable.Columns.Add("Day" + i.ToString(), typeof(string));
 | ||
|             }
 | ||
| 
 | ||
|             int n = dataTable.Rows.Count;
 | ||
|             //删除空行
 | ||
|             for (int i = n - 1; i >= 0; i--)
 | ||
|             {
 | ||
|                 DataRow dr = dataTable.Rows[i];
 | ||
|                 if (string.IsNullOrEmpty(dr["ScheduleTypeId"].ToString()))
 | ||
|                 {
 | ||
|                     dr.Delete();
 | ||
|                 }
 | ||
|             }
 | ||
| 
 | ||
|             n = dataTable.Rows.Count;
 | ||
|             for (int i = 0; i < n; i++)
 | ||
|             {
 | ||
|                 DataRow dr = dataTable.Rows[i];
 | ||
|                 string strTypeId = dr["ScheduleTypeId"].ToString();
 | ||
|                 string[] ids = strTypeId.Split('|');
 | ||
|                 int m = ids.Length;
 | ||
|                 for (int j = 1; j <= m; j++)
 | ||
|                 {
 | ||
|                     dr["Day" + j.ToString()] = getSchedulingTypeName(ids[j - 1]);
 | ||
|                 }
 | ||
|                 dr["RoundDays"] = m;
 | ||
|             }
 | ||
| 
 | ||
|             DataGridView dgv = this.dgvShiftPlan;
 | ||
|             dgv.AutoGenerateColumns = false;
 | ||
|             dgv.DataSource = dataTable.DefaultView;
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 读取排班数据
 | ||
|         /// </summary>
 | ||
|         private void GetDataTableSchedulingNew()
 | ||
|         {
 | ||
|             if (dtMainTable != null)
 | ||
|             {
 | ||
|                 if (GetDataTableChangedCount(dtMainTable) > 0)
 | ||
|                 {
 | ||
|                     if (MessageBox.Show("数据没有保存,是否需要保存", "提示信息", MessageBoxButtons.YesNo) == DialogResult.Yes)
 | ||
|                     {
 | ||
|                         btnSave_Click(null, null);
 | ||
|                     }
 | ||
|                 }
 | ||
|             }
 | ||
| 
 | ||
|             string radioType;
 | ||
|             bool isNurse = radioNurse.Checked;
 | ||
|             if (isNurse)
 | ||
|             {
 | ||
|                 radioType = "Nurse";
 | ||
|             }
 | ||
|             else
 | ||
|             {
 | ||
|                 radioType = "Doctor";
 | ||
|             }
 | ||
|             string strMonth = dateTimePicker1.Value.ToString("yyyyMM");
 | ||
|             if (conditionMonth != strMonth || conditionRole != radioType)
 | ||
|             {
 | ||
|                 /*与上次获取条件不一致,则重新取数据*/
 | ||
|                 string sql = string.Format("select id, workerId, WorkersType, ScheduleMonth, ScheduleDay, SchedulingType, SchedulingDate, OperatorId, OperatorTime, sbsj, xbsj from SchedulingNew where ScheduleMonth={0}", strMonth);
 | ||
|                 dtSchedulingNew = dbHelper.GetDataTable(sql);
 | ||
|                 if (isNurse)
 | ||
|                 {
 | ||
|                     sql = string.Format("select Id, WorkerId, OperationRoomId, nurseType, beginTime, endTime, ScheduleMonth, Remark from SchedulingNurseToOperationRoom where ScheduleMonth={0}", strMonth);
 | ||
|                     dtSchedulingNurseToOperationRoom = dbHelper.GetDataTable(sql);
 | ||
|                 }
 | ||
| 
 | ||
|                 this.dataGridView1.DataSource = GetMainDataTable();
 | ||
| 
 | ||
|                 /*记录获取条件*/
 | ||
|                 conditionMonth = strMonth;
 | ||
|                 conditionRole = radioType;
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 生成DataTable dtMainTable
 | ||
|         /// </summary>
 | ||
|         /// <returns></returns>
 | ||
|         private DataTable GetMainDataTable()
 | ||
|         {
 | ||
|             DateTime dateTime = this.dateTimePicker1.Value;
 | ||
|             int year = dateTime.Year;
 | ||
|             int month = dateTime.Month;
 | ||
|             int dayMax = (new DateTime(year, month, 1)).AddMonths(1).AddDays(-1).Day;
 | ||
| 
 | ||
|             List<string> listHeaderChinese = new List<string>();
 | ||
|             List<string> listHeaderWeek = new List<string>();
 | ||
|             List<string> listHeaderDays = new List<string>();
 | ||
| 
 | ||
|             ChineseCalendar cCalendar;
 | ||
|             for (int i = 1; i <= dayMax; i++)
 | ||
|             {
 | ||
|                 DateTime date = new DateTime(year, month, i);
 | ||
|                 cCalendar = new ChineseCalendar(date);
 | ||
|                 string chineseDay = cCalendar.ChineseTwentyFourDay != "" ? cCalendar.ChineseTwentyFourDay : cCalendar.ChineseDateString;
 | ||
|                 if (chineseDay.StartsWith("十一月"))
 | ||
|                 {
 | ||
|                     chineseDay = chineseDay.Replace("十一月", "11月");
 | ||
|                 }
 | ||
|                 listHeaderChinese.Add(chineseDay);
 | ||
|                 listHeaderWeek.Add(cCalendar.WeekDayStr);
 | ||
|                 listHeaderDays.Add(date.ToString("MM-dd"));
 | ||
|             }
 | ||
| 
 | ||
|             this.listHeaderChinese = listHeaderChinese;
 | ||
|             this.listHeaderWeek = listHeaderWeek;
 | ||
|             this.listHeaderDays = listHeaderDays;
 | ||
| 
 | ||
|             DataTable dataTable = new DataTable();
 | ||
|             dataTable.Columns.Add("ColChecked", typeof(int));
 | ||
|             dataTable.Columns.Add("WorkerId", typeof(int));
 | ||
|             dataTable.Columns.Add("Name", typeof(string));
 | ||
|             dataTable.Columns.Add("HCode", typeof(string));
 | ||
|             dataTable.Columns.Add("Role", typeof(string));
 | ||
|             dataTable.Columns.Add("xh", typeof(int));
 | ||
| 
 | ||
|             /*护士: 添加手术室,值班时间和备注*/
 | ||
|             bool isNurse = radioNurse.Checked;
 | ||
|             if (isNurse)
 | ||
|             {
 | ||
|                 dataTable.Columns.Add("OperationRoom", typeof(string));
 | ||
|                 dataTable.Columns.Add("BeginDate", typeof(DateTime));
 | ||
|                 dataTable.Columns.Add("EndDate", typeof(DateTime));
 | ||
|                 dataTable.Columns.Add("Remark", typeof(string));
 | ||
|             }
 | ||
| 
 | ||
|             /*添加当天各天的字段*/
 | ||
|             for (int i = 1; i <= dayMax; i++)
 | ||
|             {
 | ||
|                 string fieldname = string.Format("Date{0}", i.ToString());
 | ||
|                 dataTable.Columns.Add(fieldname, typeof(string));
 | ||
|             }
 | ||
| 
 | ||
|             /*设置列标题*/
 | ||
|             string newLine = System.Environment.NewLine;
 | ||
|             DataGridView dgv = this.dataGridView1;
 | ||
|             DataGridViewComboBoxColumn column;
 | ||
| 
 | ||
|             dgv.Columns["Date29"].Visible = false;
 | ||
|             dgv.Columns["Date30"].Visible = false;
 | ||
|             dgv.Columns["Date31"].Visible = false;
 | ||
|             for (int i = 0; i < dayMax; i++)
 | ||
|             {
 | ||
|                 string columnName = string.Format("Date{0}", (i + 1).ToString());
 | ||
|                 column = (DataGridViewComboBoxColumn)dgv.Columns[columnName];
 | ||
|                 string WeekDayStr = listHeaderWeek[i];
 | ||
| 
 | ||
|                 column.HeaderText = string.Format("{0}{1}{2}{3}{4}", listHeaderDays[i], newLine, WeekDayStr, newLine, listHeaderChinese[i]);
 | ||
|                 if (i >= 28) column.Visible = true;
 | ||
|                 if (WeekDayStr == "周六" || WeekDayStr == "周日")
 | ||
|                 {
 | ||
|                     column.HeaderCell.Style.ForeColor = Color.Red;
 | ||
|                 }
 | ||
|                 else
 | ||
|                 {
 | ||
|                     column.HeaderCell.Style.ForeColor = Color.Black;
 | ||
|                 }
 | ||
|             }
 | ||
| 
 | ||
|             /*给手术室和角色添加数据源*/
 | ||
|             column = (DataGridViewComboBoxColumn)dgv.Columns["Role"];
 | ||
|             if (isNurse)
 | ||
|             {
 | ||
|                 column.ReadOnly = false;
 | ||
|                 column.Items.Clear();
 | ||
|                 column.Items.AddRange(nurseRoles);
 | ||
|                 column = (DataGridViewComboBoxColumn)dgv.Columns["OperationRoom"];
 | ||
|                 column.Items.Clear();
 | ||
|                 column.Items.Add("");
 | ||
|                 column.Items.AddRange(dicOperationRoomNameId.Keys.ToArray());
 | ||
|                 column.ReadOnly = false;
 | ||
|                 dgv.Columns["OperationRoom"].Visible = true;
 | ||
|                 dgv.Columns["BeginDate"].Visible = true;
 | ||
|                 dgv.Columns["EndDate"].Visible = true;
 | ||
|                 dgv.Columns["Remark"].Visible = true;
 | ||
|             }
 | ||
|             else
 | ||
|             {
 | ||
|                 column.ReadOnly = true;
 | ||
|                 column.Items.Clear();
 | ||
|                 column.Items.AddRange(doctorRoles);
 | ||
|                 dgv.Columns["OperationRoom"].Visible = false;
 | ||
|                 dgv.Columns["BeginDate"].Visible = false;
 | ||
|                 dgv.Columns["EndDate"].Visible = false;
 | ||
|                 dgv.Columns["Remark"].Visible = false;
 | ||
|             }
 | ||
| 
 | ||
|             /*填充相数据*/
 | ||
|             DataTable duTable;
 | ||
|             if (isNurse)
 | ||
|             {
 | ||
|                 duTable = dtNurses;
 | ||
|             }
 | ||
|             else
 | ||
|             {
 | ||
|                 duTable = dtDoctors;
 | ||
|             }
 | ||
| 
 | ||
|             Dictionary<int, int> dicUsedWorkers = new Dictionary<int, int>();
 | ||
|             DataView dv1, dv2;
 | ||
|             dv1 = new DataView(dtSchedulingNew);
 | ||
|             if (isNurse)
 | ||
|             {
 | ||
|                 dv2 = new DataView(dtSchedulingNurseToOperationRoom);
 | ||
|             }
 | ||
|             else
 | ||
|             {
 | ||
|                 dv2 = new DataView();
 | ||
|             }
 | ||
|             string strMonth = (year * 100 + month).ToString();
 | ||
|             DateTime beginTime = new DateTime(year, month, 1);
 | ||
|             DateTime endTime = new DateTime(year, month, dayMax);
 | ||
|             int xh = 0;
 | ||
|             foreach (DataRow dr in duTable.Rows)
 | ||
|             {
 | ||
|                 int workerId = (int)dr["Id"];
 | ||
|                 DataRow dr2 = dataTable.NewRow();
 | ||
|                 dr2["ColChecked"] = 0;
 | ||
|                 dr2["WorkerId"] = (int)dr["Id"];
 | ||
|                 dr2["Name"] = dr["Name"].ToString();
 | ||
|                 dr2["HCode"] = dr["HCode"].ToString();
 | ||
|                 dr2["xh"] = ++xh;
 | ||
|                 if (!isNurse)
 | ||
|                 {
 | ||
|                     dr2["Role"] = "医生";
 | ||
|                 }
 | ||
|                 else
 | ||
|                 {
 | ||
|                     dv2.RowFilter = string.Format("ScheduleMonth={0} and WorkerId={1}", strMonth, workerId);
 | ||
|                     if (dv2.Count > 0)
 | ||
|                     {
 | ||
|                         dr2["OperationRoom"] = getOperationRoomName((int)dv2[0]["OperationRoomId"]);
 | ||
|                         dr2["Role"] = dv2[0]["nurseType"];
 | ||
|                         dr2["BeginDate"] = dv2[0]["BeginTime"];
 | ||
|                         dr2["EndDate"] = dv2[0]["EndTime"];
 | ||
|                     }
 | ||
|                     else
 | ||
|                     {
 | ||
|                         //dr2["OperationRoom"] = "";// getOperationRoomName(int.Parse(dr["OperationRoomId"].ToString()));
 | ||
|                         //dr2["Role"] = dr["NurseRole"].ToString();
 | ||
|                         //dr2["BeginDate"] = beginTime;
 | ||
|                         //dr2["EndDate"] = endTime;
 | ||
|                     }
 | ||
|                 }
 | ||
|                 dv1.RowFilter = string.Format("ScheduleMonth={0} and WorkerId={1}", strMonth, workerId);
 | ||
|                 int n = dv1.Count;
 | ||
|                 for (int i = 0; i < n; i++)
 | ||
|                 {
 | ||
|                     int day = (int)dv1[i]["ScheduleDay"];
 | ||
|                     if (day >= 1 && day <= dayMax)
 | ||
|                     {
 | ||
|                         dr2["Date" + day.ToString()] = getSchedulingTypeName((int)dv1[i]["SchedulingType"]);
 | ||
|                     }
 | ||
|                 }
 | ||
|                 dataTable.Rows.Add(dr2);
 | ||
|             }
 | ||
|             dtMainTable = dataTable;
 | ||
|             dataTable.DefaultView.Sort = "xh";
 | ||
|             dataTable.AcceptChanges();
 | ||
|             return dataTable;
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         private void FrmScheduling2_Load(object sender, EventArgs e)
 | ||
|         {
 | ||
|             DataGridView dgv = this.dataGridView1;
 | ||
|             dgv.EditMode = DataGridViewEditMode.EditOnEnter;
 | ||
| 
 | ||
|             //冻结姓名列
 | ||
|             dgv.Columns["ColName"].Frozen = true;
 | ||
|             dgv.AutoGenerateColumns = false;
 | ||
| 
 | ||
|             //dgv.RowPostPaint += GPControls.DataGridView_RowPostPaint;
 | ||
|             //dgvSchedulingType.RowPostPaint += GPControls.DataGridView_RowPostPaint;
 | ||
|             //dgvShiftPlan.RowPostPaint += GPControls.DataGridView_RowPostPaint;
 | ||
| 
 | ||
|             operatorId = AIMSExtension.PublicMethod.OperatorId;
 | ||
| 
 | ||
|             GetDataTableSchedulingType();
 | ||
|             FreshDicSchedulingType();
 | ||
| 
 | ||
|             dgv = this.dgvSchedulingType;
 | ||
|             dgv.EditMode = DataGridViewEditMode.EditOnEnter;
 | ||
| 
 | ||
|             dgv.AutoGenerateColumns = false;
 | ||
|             dgv.DataSource = dtSchedulingType;
 | ||
| 
 | ||
|             this.dgvShiftPlan.EditMode = DataGridViewEditMode.EditOnEnter;
 | ||
|             GetDataTableShiftPlan();
 | ||
| 
 | ||
|             GetDataTableDoctorsNursesRoom();
 | ||
| 
 | ||
|             this.WindowState = FormWindowState.Maximized;
 | ||
|             dateTimePicker1.Value = DateTime.Now.Date; 
 | ||
| 
 | ||
|             radioDoctor.Focus();
 | ||
|             if (PublicMethod.RoleId == 6 || PublicMethod.RoleId == 8 || PublicMethod.RoleId == 10)
 | ||
|             {
 | ||
|                 radioNurse.Checked = true;
 | ||
|                 radioNurse.Focus();
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         private void ChxSelectAllRows_CheckedChanged(object sender, EventArgs e)
 | ||
|         {
 | ||
|             DataGridView dgv = this.dataGridView1;
 | ||
|             int n = dgv.Rows.Count;
 | ||
|             int isChecked = ((System.Windows.Forms.CheckBox)sender).Checked ? 1 : 0;
 | ||
|             for (int i = 0; i < n; i++)
 | ||
|             {
 | ||
|                 dgv.Rows[i].Cells["colChecked"].Value = isChecked;
 | ||
|             }
 | ||
|             dgv.EndEdit();
 | ||
|         }
 | ||
| 
 | ||
|         private void radioNurse_CheckedChanged(object sender, EventArgs e)
 | ||
|         {
 | ||
|             if (radioNurse.Checked)
 | ||
|             {
 | ||
|                 labelTitle.Text = "护士排班管理";
 | ||
|                 labelDoctorNurse.Text = "选择护士";
 | ||
|                 labelScheduling.Text = "护士排班计划";
 | ||
|                 GetDataTableSchedulingNew();
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         private void radioDoctor_CheckedChanged(object sender, EventArgs e)
 | ||
|         {
 | ||
|             if (radioDoctor.Checked)
 | ||
|             {
 | ||
|                 labelTitle.Text = "麻醉医生排班管理";
 | ||
|                 labelDoctorNurse.Text = "选择麻醉医生";
 | ||
|                 labelScheduling.Text = "麻醉医生排班计划";
 | ||
|                 GetDataTableSchedulingNew();
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         private void btnSave_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             /*保存排班数据*/
 | ||
|             this.dataGridView1.EndEdit();
 | ||
|             //SaveWorkersInfo();
 | ||
|             if (!radioNurse.Checked)
 | ||
|             {
 | ||
|                 SaveDoctorSchedulingNew();
 | ||
|             }
 | ||
|             else
 | ||
|             {
 | ||
|                 SaveNurseSchedulingNew();
 | ||
|             }
 | ||
| 
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 保存员工信息
 | ||
|         /// </summary>
 | ||
|         private void SaveWorkersInfo()
 | ||
|         {
 | ||
|             /*OrderBy, OperationRoom, NurseRole */
 | ||
|             DataGridView dgv = this.dataGridView1;
 | ||
|             bool isNurse = dgv.Columns["OperationRoom"].Visible;
 | ||
|             int n = dgv.Rows.Count;
 | ||
|             List<string> list = new List<string>();
 | ||
|             for (int i = 0; i < n; i++)
 | ||
|             {
 | ||
|                 DataGridViewRow dvr = dgv.Rows[i];
 | ||
|                 int id = int.Parse(dvr.Cells["WorkerId"].Value.ToString());
 | ||
|                 int OrderBy = int.Parse(dvr.Cells["ColXh"].Value.ToString());
 | ||
|                 int operationRoomId;
 | ||
|                 string nurseRole;
 | ||
|                 if (!isNurse)
 | ||
|                 {
 | ||
|                     list.Add(string.Format("SELECT {0} AS ID, {1} AS OrderBy", id, OrderBy));
 | ||
|                 }
 | ||
|                 else
 | ||
|                 {
 | ||
|                     operationRoomId = GetOperationRoomId(dvr.Cells["OperationRoom"].Value.ToString());
 | ||
|                     nurseRole = dvr.Cells["Role"].Value.ToString();
 | ||
|                     list.Add(string.Format("SELECT {0} AS ID, {1} AS OrderBy, {2} AS OperationRoomId,  '{3}' AS NurseRole", id, OrderBy, operationRoomId, nurseRole));
 | ||
|                 }
 | ||
|             }
 | ||
|             if (list.Count == 0) return;
 | ||
|             string sql;
 | ||
|             if (!isNurse)
 | ||
|             {
 | ||
|                 sql = string.Format("Update Person SET OrderBy = a.OrderBy FROM ({0}) a WHERE Person.Id = a.Id", string.Join(" UNION ALL ", list.ToArray()));
 | ||
|             }
 | ||
|             else
 | ||
|             {
 | ||
|                 sql = string.Format("Update Person SET OrderBy = a.OrderBy, OperationRoomId=a.OperationRoomId, NurseRole=a.NurseRole FROM ({0}) a WHERE Person.Id = a.Id", string.Join(" UNION ALL ", list.ToArray()));
 | ||
|             }
 | ||
| 
 | ||
|             n = dbHelper.Execute(sql);
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 保存医生排班数据
 | ||
|         /// </summary>
 | ||
|         private void SaveDoctorSchedulingNew()
 | ||
|         {
 | ||
|             /*select id, workerId, WorkersType, ScheduleMonth, ScheduleDay, SchedulingType, SchedulingDate, OperatorId, OperatorTime, sbsj, xbsj from SchedulingNew*/
 | ||
|             DataTable dataTable = dtSchedulingNew.Clone();
 | ||
|             DataView dvMain = new DataView(dtMainTable);
 | ||
| 
 | ||
|             DateTime dateTime = this.dateTimePicker1.Value;
 | ||
|             int year = dateTime.Year;
 | ||
|             int month = dateTime.Month;
 | ||
|             int dayMax = (new DateTime(year, month, 1)).AddMonths(1).AddDays(-1).Day;
 | ||
|             StringBuilder sb = new StringBuilder();
 | ||
|             sb.Append("len(Date1) >0");
 | ||
|             for (int i = 2; i <= dayMax; i++)
 | ||
|             {
 | ||
|                 sb.Append(string.Format(" or len(Date{0})>0", i.ToString()));
 | ||
|             }
 | ||
|             dvMain.RowFilter = sb.ToString();
 | ||
|             int scheduleMonth = year * 100 + month;
 | ||
|             dvSchedulingType = null;
 | ||
|             for (int i = 0, n = dvMain.Count; i < n; i++)
 | ||
|             {
 | ||
|                 DataRowView drv = dvMain[i];
 | ||
|                 DataRow dr;
 | ||
|                 for (int j = 1; j <= dayMax; j++)
 | ||
|                 {
 | ||
|                     int schedulingTypeId;
 | ||
|                     DateTime zbrq;    /* 值班日期 */
 | ||
|                     MySxbTime sxbsj;  /* 上下班时间 */
 | ||
|                     string fieldName = string.Format("Date{0}", j.ToString());
 | ||
|                     string fieldValue = drv[fieldName].ToString();
 | ||
|                     if (!string.IsNullOrEmpty(fieldValue))
 | ||
|                     {
 | ||
|                         schedulingTypeId = getSchedulingTypeId(fieldValue);
 | ||
|                         if (schedulingTypeId > 0)
 | ||
|                         {
 | ||
|                             dr = dataTable.NewRow();
 | ||
|                             dr["WorkerId"] = (int)drv["WorkerId"];
 | ||
|                             dr["WorkersType"] = 2;
 | ||
|                             dr["ScheduleMonth"] = scheduleMonth;
 | ||
|                             dr["ScheduleDay"] = j;
 | ||
|                             dr["SchedulingType"] = schedulingTypeId;
 | ||
| 
 | ||
|                             zbrq = new DateTime(year, month, j);
 | ||
|                             sxbsj = GetSchedulingTypeSxbsj(schedulingTypeId, zbrq);
 | ||
|                             dr["SchedulingDate"] = zbrq;
 | ||
|                             if (sxbsj.sbTime.CompareTo(sxbsj.xbTime) < 0)
 | ||
|                             {
 | ||
|                                 dr["sbsj"] = sxbsj.sbTime;
 | ||
|                                 dr["xbsj"] = sxbsj.xbTime;
 | ||
|                             }
 | ||
|                             else
 | ||
|                             {
 | ||
|                                 dr["sbsj"] = DBNull.Value;
 | ||
|                                 dr["xbsj"] = DBNull.Value;
 | ||
|                             }
 | ||
|                             dataTable.Rows.Add(dr);
 | ||
|                         }
 | ||
|                     }
 | ||
|                 }
 | ||
|             }
 | ||
| 
 | ||
|             if (dataTable.Rows.Count == 0)
 | ||
|             {
 | ||
|                 MessageBox.Show("没有需要保存的数据", "提示信息");
 | ||
|                 return;
 | ||
|             }
 | ||
|             SetOperatorId(dataTable, operatorId);
 | ||
| 
 | ||
|             try
 | ||
|             {
 | ||
|                 foreach (DataGridViewRow item in dataGridView1.Rows)
 | ||
|                 {
 | ||
|                     dbHelper.BeginTransaction();
 | ||
|                     dbHelper.Execute(string.Format("update Person set PersonOrder={0} where Id={1}", item.Cells["ColXh"].Value, item.Cells["WorkerId"].Value));
 | ||
|                     dbHelper.Commit();
 | ||
|                 }
 | ||
|                 dbHelper.BeginTransaction();
 | ||
|                 int workersType = int.Parse(dataTable.Rows[0]["workersType"].ToString());
 | ||
|                 dbHelper.Execute(string.Format("delete SchedulingNew where ScheduleMonth={0} and WorkersType={1}", scheduleMonth, workersType));
 | ||
|                 int n = dbHelper.DataTableSave(dataTable, "select id, workerId, WorkersType, ScheduleMonth, ScheduleDay, SchedulingType, SchedulingDate, OperatorId, OperatorTime, sbsj, xbsj from SchedulingNew");
 | ||
|                 dbHelper.Commit();
 | ||
|                 dtMainTable.AcceptChanges();
 | ||
|                 MessageBox.Show("保存成功。", "提示信息");
 | ||
|             }
 | ||
|             catch (Exception ex)
 | ||
|             {
 | ||
|                 dbHelper.RollBack();
 | ||
|                 MessageBox.Show("保存失败:" + ex.Message, "提示信息");
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 保存护士排班数据
 | ||
|         /// </summary>
 | ||
|         private void SaveNurseSchedulingNew()
 | ||
|         {
 | ||
|             /*select id, workerId, WorkersType, ScheduleMonth, ScheduleDay, SchedulingType, SchedulingDate, OperatorId, OperatorTime, sbsj, xbsj from SchedulingNew */
 | ||
|             DataTable dataTable = dtSchedulingNew.Clone();
 | ||
|             DataView dvMain = new DataView(dtMainTable);
 | ||
| 
 | ||
|             DateTime dateTime = this.dateTimePicker1.Value;
 | ||
|             int year = dateTime.Year;
 | ||
|             int month = dateTime.Month;
 | ||
|             DateTime monthFirstDay = new DateTime(year, month, 1);
 | ||
|             DateTime monthLastDay = monthFirstDay.AddMonths(1).AddDays(-1);
 | ||
|             int dayMax = monthLastDay.Day;
 | ||
| 
 | ||
|             StringBuilder sb = new StringBuilder();
 | ||
|             sb.Append("len(Date1) >0");
 | ||
|             for (int i = 2; i <= dayMax; i++)
 | ||
|             {
 | ||
|                 sb.Append(string.Format(" or len(Date{0})>0", i.ToString()));
 | ||
|             }
 | ||
|             dvMain.RowFilter = sb.ToString();
 | ||
|             int scheduleMonth = year * 100 + month;
 | ||
|             dvSchedulingType = null;
 | ||
|             /*转换排班数据*/
 | ||
|             for (int i = 0, n = dvMain.Count; i < n; i++)
 | ||
|             {
 | ||
|                 DataRowView drv = dvMain[i];
 | ||
|                 DataRow dr;
 | ||
|                 for (int j = 1; j < dayMax; j++)
 | ||
|                 {
 | ||
|                     int schedulingTypeId;
 | ||
|                     DateTime zbrq;    /* 值班日期 */
 | ||
|                     MySxbTime sxbsj;  /* 上下班时间 */
 | ||
|                     string fieldName = string.Format("Date{0}", j.ToString());
 | ||
|                     string fieldValue = drv[fieldName].ToString();
 | ||
|                     if (!string.IsNullOrEmpty(fieldValue))
 | ||
|                     {
 | ||
|                         schedulingTypeId = getSchedulingTypeId(fieldValue);
 | ||
|                         if (schedulingTypeId > 0)
 | ||
|                         {
 | ||
|                             dr = dataTable.NewRow();
 | ||
|                             dr["WorkerId"] = (int)drv["WorkerId"];
 | ||
|                             dr["WorkersType"] = 1;
 | ||
|                             dr["ScheduleMonth"] = scheduleMonth;
 | ||
|                             dr["ScheduleDay"] = j;
 | ||
|                             dr["SchedulingType"] = schedulingTypeId;
 | ||
| 
 | ||
|                             zbrq = new DateTime(year, month, j);
 | ||
|                             sxbsj = GetSchedulingTypeSxbsj(schedulingTypeId, zbrq);
 | ||
|                             dr["SchedulingDate"] = zbrq;
 | ||
|                             if (sxbsj.sbTime.CompareTo(sxbsj.xbTime) < 0)
 | ||
|                             {
 | ||
|                                 dr["sbsj"] = sxbsj.sbTime;
 | ||
|                                 dr["xbsj"] = sxbsj.xbTime;
 | ||
|                             }
 | ||
|                             else
 | ||
|                             {
 | ||
|                                 dr["sbsj"] = DBNull.Value;
 | ||
|                                 dr["xbsj"] = DBNull.Value;
 | ||
|                             }
 | ||
|                             dataTable.Rows.Add(dr);
 | ||
|                         }
 | ||
|                     }
 | ||
|                 }
 | ||
|             }
 | ||
| 
 | ||
|             if (dataTable.Rows.Count == 0)
 | ||
|             {
 | ||
|                 MessageBox.Show("没有需要保存的数据", "提示信息");
 | ||
|                 return;
 | ||
|             }
 | ||
|             SetOperatorId(dataTable, operatorId);
 | ||
| 
 | ||
|             /*转换护士值班数据*/
 | ||
|             /*SELECT Id, WorkerId, OperationRoomId, nurseType, beginTime, endTime, ScheduleMonth, Remark FROM SchedulingNurseToOperationRoom*/
 | ||
|             DataTable dataTable2 = dtSchedulingNurseToOperationRoom.Clone();
 | ||
|             for (int i = 0, n = dvMain.Count; i < n; i++)
 | ||
|             {
 | ||
|                 DataRowView drv = dvMain[i];
 | ||
|                 DataRow dr;
 | ||
|                 int OperationRoomId;
 | ||
|                 DateTime beginTime, endTime;
 | ||
|                 OperationRoomId = GetOperationRoomId(drv["OperationRoom"].ToString());
 | ||
|                 if (OperationRoomId > 0)
 | ||
|                 {
 | ||
|                     beginTime = Convert.ToDateTime(drv["BeginDate"]);
 | ||
|                     endTime = Convert.ToDateTime(drv["EndDate"]);
 | ||
|                     if (beginTime.Year < year) beginTime = monthFirstDay;
 | ||
|                     if (endTime.Year < year) endTime = monthLastDay;
 | ||
| 
 | ||
|                     dr = dataTable2.NewRow();
 | ||
|                     dr["WorkerId"] = (int)drv["WorkerId"];
 | ||
|                     dr["OperationRoomId"] = OperationRoomId;
 | ||
|                     dr["ScheduleMonth"] = scheduleMonth;
 | ||
|                     dr["nurseType"] = drv["Role"].ToString();
 | ||
|                     dr["beginTime"] = beginTime;
 | ||
|                     dr["endTime"] = endTime;
 | ||
|                     dr["Remark"] = drv["Remark"].ToString();
 | ||
|                     dataTable2.Rows.Add(dr);
 | ||
|                 }
 | ||
|             }
 | ||
| 
 | ||
|             try
 | ||
|             {
 | ||
|                 foreach (DataGridViewRow item in dataGridView1.Rows)
 | ||
|                 {
 | ||
|                     dbHelper.BeginTransaction();
 | ||
|                     dbHelper.Execute(string.Format("update Person set PersonOrder={0} where Id={1}", item.Cells["ColXh"].Value, item.Cells["WorkerId"].Value));
 | ||
|                     dbHelper.Commit();
 | ||
|                 }
 | ||
|                 dbHelper.BeginTransaction();
 | ||
|                 dbHelper.Execute(string.Format("delete SchedulingNew where ScheduleMonth={0} and WorkersType=1", scheduleMonth));
 | ||
|                 dbHelper.Execute(string.Format("delete SchedulingNurseToOperationRoom where ScheduleMonth={0}", scheduleMonth));
 | ||
|                 int n = dbHelper.DataTableSave(dataTable, "select id, workerId, WorkersType, ScheduleMonth, ScheduleDay, SchedulingType, SchedulingDate, OperatorId, OperatorTime, sbsj, xbsj from SchedulingNew");
 | ||
|                 n = dbHelper.DataTableSave(dataTable2, "SELECT Id, WorkerId, OperationRoomId, nurseType, beginTime, endTime, ScheduleMonth, Remark FROM SchedulingNurseToOperationRoom");
 | ||
|                 dbHelper.Commit();
 | ||
|                 dtMainTable.AcceptChanges();
 | ||
|                 MessageBox.Show("保存成功。", "提示信息");
 | ||
|             }
 | ||
|             catch (Exception ex)
 | ||
|             {
 | ||
|                 dbHelper.RollBack();
 | ||
|                 MessageBox.Show("保存失败:" + ex.Message, "提示信息");
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         private void btnExit_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             this.Close();
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 是否是时间格式, 格式为h或者h:m
 | ||
|         /// </summary>
 | ||
|         /// <param name="time"></param>
 | ||
|         /// <returns></returns>
 | ||
|         private bool isTimeString(string time)
 | ||
|         {
 | ||
|             time = time.Trim();
 | ||
|             if (string.IsNullOrEmpty(time)) return true;
 | ||
|             time = time.Replace(":", ":");
 | ||
|             //int hour, minute;
 | ||
|             //if (!GPFunctions.IsAllNumber(time.Replace(":", "")))
 | ||
|             //{
 | ||
|             //    MessageBox.Show(string.Format("时间应当为数字,{0}不是正确的时间表示", time), "提示信息");
 | ||
|             //    return false;
 | ||
|             //}
 | ||
| 
 | ||
|             //int[] arr = StringToIntArray(time, ':');
 | ||
|             //int n = arr.Length;
 | ||
|             //if (n > 2)
 | ||
|             //{
 | ||
|             //    MessageBox.Show("时间格式为:hh:mm,  如10:19", "提示信息");
 | ||
|             //    return false;
 | ||
|             //}
 | ||
|             //if (arr.Length == 1)
 | ||
|             //{
 | ||
|             //    hour = arr[0];
 | ||
|             //    if (hour < 0 || hour > 23)
 | ||
|             //    {
 | ||
|             //        return false;
 | ||
|             //    }
 | ||
|             //}
 | ||
|             //else
 | ||
|             //{
 | ||
|             //    hour = arr[0];
 | ||
|             //    if (hour < 0 || hour > 23)
 | ||
|             //    {
 | ||
|             //        return false;
 | ||
|             //    }
 | ||
|             //    minute = arr[1];
 | ||
|             //    if (minute < 0 || minute > 59)
 | ||
|             //    {
 | ||
|             //        return false;
 | ||
|             //    }
 | ||
|             //}
 | ||
|             return true;
 | ||
|         }
 | ||
| 
 | ||
|         private void dgvSchedulingType_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 | ||
|         {
 | ||
|             int rowIndex = e.RowIndex;
 | ||
|             int columnIndex = e.ColumnIndex;
 | ||
|             DataGridView dgv = this.dgvSchedulingType;
 | ||
|             string columnName = dgv.Columns[columnIndex].Name;
 | ||
|             if (columnName == "BeginTime" || columnName == "EndTime")
 | ||
|             {
 | ||
|                 string val = dgv.Rows[rowIndex].Cells[columnIndex].Value.ToString();
 | ||
|                 isTimeString(val);
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         private void btnShiftFresh_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             GetDataTableSchedulingType();
 | ||
|             this.dgvSchedulingType.DataSource = dtSchedulingType;
 | ||
|         }
 | ||
| 
 | ||
|         private void btnShiftDelete_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             /*班次删除*/
 | ||
|             DataGridView dgv = this.dgvSchedulingType;
 | ||
|             DataGridViewSelectedRowCollection rows = dgv.SelectedRows;
 | ||
|             if (rows.Count == 0) return;
 | ||
| 
 | ||
|             for (int i = rows.Count - 1; i >= 0; i--)
 | ||
|             {
 | ||
|                 DataGridViewRow row = rows[i];
 | ||
|                 int id = int.Parse(row.Cells["TypeId"].Value.ToString());
 | ||
|                 dgv.Rows.Remove(row);
 | ||
|                 dgv.EndEdit();
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         private void btnShiftSave_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             /*班次保存*/
 | ||
|             if (!CheckSchedulingTypeData()) return;
 | ||
|             if (!SchedulingTypeExistsSameName()) return;
 | ||
|             DataTable dataTable = dtSchedulingType;
 | ||
|             SetOperatorId(dataTable, operatorId);
 | ||
| 
 | ||
|             int n;
 | ||
|             try
 | ||
|             {
 | ||
|                 dbHelper.BeginTransaction();
 | ||
|                 n = dbHelper.DataTableSave(dataTable, "select Id, [Name], BeginTime, EndTime, IsValid, OperatorId, OperatorTime from SchedulingType");
 | ||
|                 dbHelper.Commit();
 | ||
|                 dataTable.AcceptChanges();
 | ||
|                 MessageBox.Show("保存成功。", "提示信息");
 | ||
|             }
 | ||
|             catch (Exception ex)
 | ||
|             {
 | ||
|                 dbHelper.RollBack();
 | ||
|                 MessageBox.Show("保存失败:" + ex.Message, "提示信息");
 | ||
|             }
 | ||
| 
 | ||
|             GetDataTableSchedulingType();
 | ||
|             FreshDicSchedulingType();
 | ||
| 
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 设置操作员Id
 | ||
|         /// </summary>
 | ||
|         /// <param name="dataTable"></param>
 | ||
|         /// <param name="operatorId"></param>
 | ||
|         private void SetOperatorId(DataTable dataTable, int operatorId)
 | ||
|         {
 | ||
|             /*设置修改的操作员信息*/
 | ||
|             if (dataTable == null) return;
 | ||
|             DateTime dateTime = DateTime.Now;
 | ||
|             foreach (DataRow dr in dataTable.Rows)
 | ||
|             {
 | ||
|                 if (dr.RowState != DataRowState.Unchanged && dr.RowState != DataRowState.Deleted)
 | ||
|                 {
 | ||
|                     dr["operatorId"] = operatorId;
 | ||
|                     dr["OperatorTime"] = dateTime;
 | ||
|                 }
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 设置操作员代码
 | ||
|         /// </summary>
 | ||
|         /// <param name="dataTable">DataTable</param>
 | ||
|         /// <param name="operatorNo">操作员Id</param>
 | ||
|         private void SetOperatorNo(DataTable dataTable, string operatorNo)
 | ||
|         {
 | ||
|             /*设置修改的操作员信息*/
 | ||
|             if (dataTable == null) return;
 | ||
|             DateTime dateTime = DateTime.Now;
 | ||
|             foreach (DataRow dr in dataTable.Rows)
 | ||
|             {
 | ||
|                 if (dr.RowState != DataRowState.Unchanged && dr.RowState != DataRowState.Deleted)
 | ||
|                 {
 | ||
|                     dr["operatorNo"] = operatorNo;
 | ||
|                     dr["OperatorTime"] = dateTime;
 | ||
|                 }
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 检查班次数据信息的输入时间 是否正确
 | ||
|         /// </summary>
 | ||
|         /// <returns></returns>
 | ||
|         private bool CheckSchedulingTypeData()
 | ||
|         {
 | ||
|             string strVal;
 | ||
|             DataTable dataTable = dtSchedulingType;
 | ||
|             int n = dataTable.Rows.Count;
 | ||
|             DataGridView dgv = this.dgvSchedulingType;
 | ||
|             bool isok = true;
 | ||
|             for (int i = 0; i < n; i++)
 | ||
|             {
 | ||
|                 DataRow dr = dataTable.Rows[i];
 | ||
|                 if (dr.RowState != DataRowState.Unchanged && dr.RowState != DataRowState.Deleted)
 | ||
|                 {
 | ||
|                     strVal = dr["BeginTime"].ToString().Trim();
 | ||
|                     if (!isTimeString(strVal))
 | ||
|                     {
 | ||
|                         dgv.CurrentCell = dgv.Rows[i].Cells["BeginTime"];
 | ||
|                         isok = false;
 | ||
|                         break;
 | ||
|                     }
 | ||
|                     else
 | ||
|                     {
 | ||
|                         if (string.IsNullOrEmpty(strVal))
 | ||
|                         {
 | ||
|                             dr["BeginTime"] = DBNull.Value;
 | ||
|                         }
 | ||
|                     }
 | ||
|                     strVal = dr["EndTime"].ToString().Trim();
 | ||
|                     if (!isTimeString(strVal))
 | ||
|                     {
 | ||
|                         dgv.CurrentCell = dgv.Rows[i].Cells["EndTime"];
 | ||
|                         isok = false;
 | ||
|                         break;
 | ||
|                     }
 | ||
|                     else
 | ||
|                     {
 | ||
|                         if (string.IsNullOrEmpty(strVal))
 | ||
|                         {
 | ||
|                             dr["EndTime"] = DBNull.Value;
 | ||
|                         }
 | ||
|                     }
 | ||
|                 }
 | ||
|             }
 | ||
|             return isok;
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 判断班次中是否存在相同的名称
 | ||
|         /// </summary>
 | ||
|         /// <returns></returns>
 | ||
|         private bool SchedulingTypeExistsSameName()
 | ||
|         {
 | ||
|             int n = dgvSchedulingType.Rows.Count;
 | ||
|             bool isok = true;
 | ||
|             Dictionary<string, int> dic = new Dictionary<string, int>();
 | ||
|             for (int i = n - 1; i >= 0; i--)
 | ||
|             {
 | ||
|                 DataGridViewRow drr = dgvSchedulingType.Rows[i];
 | ||
|                 if (drr.Cells[1].Value == null) continue;
 | ||
|                 string name = drr.Cells[1].Value.ToString();
 | ||
|                 if (!string.IsNullOrEmpty(name))
 | ||
|                 {
 | ||
|                     if (!dic.ContainsKey(name))
 | ||
|                     {
 | ||
|                         dic.Add(name, i + 1);
 | ||
|                     }
 | ||
|                     else
 | ||
|                     {
 | ||
|                         MessageBox.Show(string.Format("班次名称:{0}在{1}行和{2}出现重复。", name, dic[name], i + 1), "提示信息");
 | ||
|                         dgvSchedulingType.CurrentCell = dgvSchedulingType.Rows[i].Cells["ShiftName"];
 | ||
|                         isok = false;
 | ||
|                         break;
 | ||
|                     }
 | ||
|                 }
 | ||
|             }
 | ||
|             return isok;
 | ||
|         }
 | ||
| 
 | ||
|         private void btnShiftPlanDelete_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             DataGridView dgv = this.dgvShiftPlan;
 | ||
|             DataGridViewSelectedRowCollection rows = dgv.SelectedRows;
 | ||
|             if (rows.Count == 0) return;
 | ||
|             for (int i = rows.Count - 1; i >= 0; i--)
 | ||
|             {
 | ||
|                 DataGridViewRow row = rows[i];
 | ||
|                 int id = int.Parse(row.Cells["Id"].Value.ToString());
 | ||
|                 dgv.Rows.Remove(row);
 | ||
|                 dgv.EndEdit();
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         private void btnShiptPlanSave_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             /*排班计划保存*/
 | ||
|             DataTable dataTable = dtScheduleSetup;
 | ||
|             int n = dataTable.Rows.Count;
 | ||
| 
 | ||
|             //生成ScheduleTypeId字段值
 | ||
|             List<int> list = new List<int>();
 | ||
|             for (int i = 0; i < n; i++)
 | ||
|             {
 | ||
|                 DataRow dr = dataTable.Rows[i];
 | ||
|                 if (dr.RowState != DataRowState.Deleted)
 | ||
|                 {
 | ||
|                     list.Clear();
 | ||
|                     for (int j = 1; j < 14; j++)
 | ||
|                     {
 | ||
|                         //var str = dgvShiftPlan.Rows[i].Cells["Day" + j.ToString()].Value;
 | ||
|                         //if (str != null && str.ToString() != "")
 | ||
|                         //{
 | ||
|                         //    int id = getSchedulingTypeId(str.ToString());
 | ||
|                         //    if (id > 0)
 | ||
|                         //    {
 | ||
|                         //        dr["Day" + j.ToString()] = id;
 | ||
|                         //        list.Add(id);
 | ||
|                         //    }
 | ||
|                         //}
 | ||
|                         int id = getSchedulingTypeId(dr["Day" + j.ToString()].ToString());
 | ||
|                         if (id > 0)
 | ||
|                         {
 | ||
|                             list.Add(id);
 | ||
|                         }
 | ||
|                         else
 | ||
|                         {
 | ||
|                             break;
 | ||
|                         }
 | ||
|                     }
 | ||
|                     string strTypeId = "";
 | ||
|                     if (list.Count > 0)
 | ||
|                     {
 | ||
|                         strTypeId = string.Join("|", list);
 | ||
|                     }
 | ||
|                     dr["ScheduleTypeId"] = strTypeId;
 | ||
|                     dr["RoundDays"] = list.Count;
 | ||
|                     dr["IsValid"] = 1;
 | ||
|                 }
 | ||
|             }
 | ||
| 
 | ||
|             //除去无数据空行
 | ||
|             for (int i = n - 1; i >= 0; i--)
 | ||
|             {
 | ||
|                 DataRow dr = dataTable.Rows[i];
 | ||
|                 if (dr.RowState != DataRowState.Deleted)
 | ||
|                 {
 | ||
|                     if (string.IsNullOrEmpty(dr["ScheduleTypeId"].ToString()))
 | ||
|                     {
 | ||
|                         dr.Delete();
 | ||
|                     }
 | ||
|                 }
 | ||
|             }
 | ||
| 
 | ||
|             SetOperatorNo(dataTable, operatorId.ToString());
 | ||
|             try
 | ||
|             {
 | ||
|                 dbHelper.BeginTransaction();
 | ||
|                 n = dbHelper.DataTableSave(dataTable, "select id, ScheduleName, ScheduleTypeId, RoundDays, IsValid, OperatorNo, OperatorTime from ScheduleSetup");
 | ||
|                 dbHelper.Commit();
 | ||
|                 dataTable.AcceptChanges();
 | ||
|                 MessageBox.Show("保存成功。", "提示信息");
 | ||
|             }
 | ||
|             catch (Exception ex)
 | ||
|             {
 | ||
|                 dbHelper.RollBack();
 | ||
|                 MessageBox.Show("保存失败:" + ex.Message, "提示信息");
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         private void btnShiftPlanFresh_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             /*刷新排班计划*/
 | ||
|             GetDataTableShiftPlan();
 | ||
|         }
 | ||
| 
 | ||
|         private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
 | ||
|         {
 | ||
| 
 | ||
|             /*改变月份*/
 | ||
|             GetDataTableSchedulingNew();
 | ||
|         }
 | ||
| 
 | ||
|         private frmPersonSchedulOption formOption = new frmPersonSchedulOption();
 | ||
|         private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
 | ||
|         {
 | ||
|             /*在主排班表格的日期格上点鼠标右键, 进行排班设置*/
 | ||
|             if (e.Button == MouseButtons.Right)
 | ||
|             {
 | ||
|                 DataGridView dgv = this.dataGridView1;
 | ||
|                 string columnName = dgv.Columns[e.ColumnIndex].Name;
 | ||
|                 if (columnName.StartsWith("Date"))
 | ||
|                 {
 | ||
|                     int rowIndex = e.RowIndex;
 | ||
|                     DataGridViewSelectedRowCollection rows = this.dgvShiftPlan.SelectedRows;
 | ||
|                     if (rows.Count == 0)
 | ||
|                     {
 | ||
|                         MessageBox.Show("请选中排班计划行", "提示信息");
 | ||
|                         return;
 | ||
|                     }
 | ||
| 
 | ||
|                     /*读取排班计划班次名称数组*/
 | ||
|                     List<string> list = new List<string>();
 | ||
|                     DataGridViewRow dr = rows[0];
 | ||
|                     int i = 1;
 | ||
|                     while (i <= 13)
 | ||
|                     {
 | ||
|                         string shiftName = dr.Cells["Day" + i.ToString()].Value.ToString();
 | ||
|                         if (!string.IsNullOrEmpty(shiftName))
 | ||
|                         {
 | ||
|                             list.Add(shiftName);
 | ||
|                             i++;
 | ||
|                         }
 | ||
|                         else
 | ||
|                         {
 | ||
|                             break;
 | ||
|                         }
 | ||
|                     }
 | ||
| 
 | ||
|                     if (list.Count == 0)
 | ||
|                     {
 | ||
|                         MessageBox.Show("请选中排班计划行班次数据不正确。", "提示信息");
 | ||
|                         return;
 | ||
|                     }
 | ||
| 
 | ||
|                     DateTime dateTime = this.dateTimePicker1.Value;
 | ||
|                     formOption.month = dateTime.Month;
 | ||
|                     int dayMax = (new DateTime(dateTime.Year, dateTime.Month, 1)).AddMonths(1).AddDays(-1).Day;
 | ||
|                     formOption.dayMax = dayMax;
 | ||
|                     formOption.shiftPlan = list.ToArray();
 | ||
|                     formOption.shiftPlanRow = dr.Index;
 | ||
|                     formOption.selectedDay1 = Convert.ToInt32(columnName.Substring(4));
 | ||
|                     formOption.ShowDialog();
 | ||
|                     if (formOption.DialogResult == System.Windows.Forms.DialogResult.OK)
 | ||
|                     {
 | ||
|                         /*对选中行进行排班*/
 | ||
|                         int selectDay1 = formOption.selectedDay1;
 | ||
|                         int selectDay2 = formOption.selectedDay2;
 | ||
|                         bool clearOthers = formOption.clearOthers;
 | ||
| 
 | ||
|                         int columnIndex = formOption.shiftPlanColumn;
 | ||
|                         int shiftLen = list.Count;
 | ||
|                         dr = dgv.CurrentRow;
 | ||
| 
 | ||
|                         /*设置值*/
 | ||
|                         int cIndex;
 | ||
|                         for (int x = 0, n = dgv.Rows.Count; x < n; x++)
 | ||
|                         {
 | ||
|                             dr = dgv.Rows[x];
 | ||
|                             if (int.Parse(dr.Cells["colChecked"].Value.ToString()) == 1)
 | ||
|                             {
 | ||
|                                 /*设置值*/
 | ||
|                                 cIndex = (columnIndex - 1) % shiftLen;
 | ||
|                                 for (int j = selectDay1; j <= selectDay2; j++)
 | ||
|                                 {
 | ||
|                                     int index = (cIndex++) % shiftLen;
 | ||
|                                     dr.Cells["Date" + j.ToString()].Value = list[index];
 | ||
|                                 }
 | ||
| 
 | ||
|                                 /*是否清空其它项*/
 | ||
|                                 if (clearOthers)
 | ||
|                                 {
 | ||
|                                     for (int j = 1; j < selectDay1; j++)
 | ||
|                                     {
 | ||
|                                         dr.Cells["Date" + j.ToString()].Value = "";
 | ||
|                                     }
 | ||
|                                     for (int j = selectDay2 + 1; j <= dayMax; j++)
 | ||
|                                     {
 | ||
|                                         dr.Cells["Date" + j.ToString()].Value = "";
 | ||
|                                     }
 | ||
|                                 }
 | ||
|                             }
 | ||
|                             dgv.EndEdit();
 | ||
|                         }
 | ||
|                     }
 | ||
|                 }
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         private void btnDelete_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             /*清除选中行和当前行的数据*/
 | ||
|             DataGridView dgv = this.dataGridView1;
 | ||
|             DateTime dateTime = this.dateTimePicker1.Value;
 | ||
|             int dayMax = (new DateTime(dateTime.Year, dateTime.Month, 1)).AddMonths(1).AddDays(-1).Day;
 | ||
| 
 | ||
|             for (int x = 0, n = dgv.Rows.Count; x < n; x++)
 | ||
|             {
 | ||
|                 DataGridViewRow dr = dgv.Rows[x];
 | ||
|                 if (int.Parse(dr.Cells["colChecked"].Value.ToString()) == 1)
 | ||
|                 {
 | ||
|                     for (int j = 1; j <= dayMax; j++)
 | ||
|                     {
 | ||
|                         dr.Cells["Date" + j.ToString()].Value = "";
 | ||
|                     }
 | ||
|                 }
 | ||
|                 dgv.EndEdit();
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         private void textFind_TextChanged(object sender, EventArgs e)
 | ||
|         {
 | ||
|             /*过滤姓名*/
 | ||
|             string text = textFind.Text.Trim();
 | ||
|             DataView dv = dtMainTable.DefaultView;
 | ||
|             dv.RowFilter = string.Format("Name like '%{0}%' or HCode like '%{0}%'", text);
 | ||
|         }
 | ||
| 
 | ||
|         private void chxOnlyShiftPlan_CheckedChanged(object sender, EventArgs e)
 | ||
|         {
 | ||
|             /*只显示有数据部分*/
 | ||
|             if (!chxOnlyShiftPlan.Checked)
 | ||
|             {
 | ||
|                 dtMainTable.DefaultView.RowFilter = "";
 | ||
|                 return;
 | ||
|             }
 | ||
| 
 | ||
|             DateTime dateTime = this.dateTimePicker1.Value;
 | ||
|             int year = dateTime.Year;
 | ||
|             int month = dateTime.Month;
 | ||
|             int dayMax = (new DateTime(year, month, 1)).AddMonths(1).AddDays(-1).Day;
 | ||
| 
 | ||
|             StringBuilder sb = new StringBuilder();
 | ||
|             sb.Append("len(Date1) >0");
 | ||
|             for (int i = 2; i <= dayMax; i++)
 | ||
|             {
 | ||
|                 sb.Append(string.Format(" or len(Date{0})>0", i.ToString()));
 | ||
|             }
 | ||
|             dtMainTable.DefaultView.RowFilter = sb.ToString();
 | ||
|         }
 | ||
| 
 | ||
|         private void dataGridView1_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
 | ||
|         {
 | ||
|             /*全选和全非选之间进行切换*/
 | ||
|             if (e.ColumnIndex == 0)
 | ||
|             {
 | ||
|                 DataGridView dgv = this.dataGridView1;
 | ||
|                 string colname = dgv.Columns[0].Name;
 | ||
|                 int n = dgv.Rows.Count;
 | ||
|                 if (n > 0)
 | ||
|                 {
 | ||
|                     bool isChecked = ((int)dgv.Rows[0].Cells[0].Value == 1);
 | ||
|                     int v = (isChecked ? 0 : 1);
 | ||
|                     for (int i = 0; i < n; i++)
 | ||
|                     {
 | ||
|                         dgv.Rows[i].Cells[0].Value = v;
 | ||
|                     }
 | ||
|                     dgv.EndEdit();
 | ||
|                 }
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         private void btnExcel_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             /*排班表导出Excel*/
 | ||
|             //GPControls.ExportToExcel(this.labelScheduling.Text + "表", this.dataGridView1, new int[] { 0, 1 });
 | ||
|         }
 | ||
| 
 | ||
|         private void btnAttendance_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             frmPersonSchedulKeep form = new frmPersonSchedulKeep();
 | ||
|             form.Show();
 | ||
|         }
 | ||
|         private void btnPrint_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             try
 | ||
|             {
 | ||
|                 /*打印排班表*/
 | ||
|                 bool oldChecked = chxOnlyShiftPlan.Checked;
 | ||
|                 chxOnlyShiftPlan.Checked = true;
 | ||
| 
 | ||
|                 DateTime dateTime = this.dateTimePicker1.Value;
 | ||
|                 int year = dateTime.Year;
 | ||
|                 int month = dateTime.Month;
 | ||
|                 DateTime monthFirstDay = new DateTime(year, month, 1);
 | ||
|                 DateTime monthLastDay = (new DateTime(year, month, 1)).AddMonths(1).AddDays(-1);
 | ||
|                 int dayMax = monthLastDay.Day;
 | ||
| 
 | ||
|                 DataGridView dgv = this.dataGridView1;
 | ||
|                 int rowsCount = dgv.Rows.Count;
 | ||
|                 string filepath = string.Format("{0}\\Template\\排班按月.xlt", AppDomain.CurrentDomain.BaseDirectory);
 | ||
| 
 | ||
|                 GoldPrinter.ExcelAccess excel = new GoldPrinter.ExcelAccess();
 | ||
|                 excel.IsVisibledExcel = false;
 | ||
|                 excel.Open(filepath);
 | ||
|                 Microsoft.Office.Interop.Excel.Worksheet xlSheet = (Microsoft.Office.Interop.Excel.Worksheet)excel.Workbooks.ActiveSheet;
 | ||
|                 string strTitle;
 | ||
|                 strTitle = PublicMethod.HospitalName;
 | ||
|                 excel.SetCellText(1, "A", strTitle);
 | ||
| 
 | ||
|                 /*标题*/
 | ||
|                 strTitle = (radioDoctor.Checked) ? "麻醉医生" : "护士";
 | ||
|                 excel.SetCellText(2, "A", string.Format("{0}年{1}月 {2}", year, month, strTitle));
 | ||
|                 Microsoft.Office.Interop.Excel.Range range;
 | ||
|                 DataGridViewRow drv;
 | ||
| 
 | ||
|                 /*填写16-31日的姓名标题,合并姓名单元格*/
 | ||
|                 range = xlSheet.Range[xlSheet.Cells[6 + rowsCount, 1], xlSheet.Cells[8 + rowsCount, 1]];
 | ||
|                 range.Merge(System.Reflection.Missing.Value);
 | ||
| 
 | ||
|                 range.Font.Color = Color.Red;    //红色
 | ||
|                 xlSheet.Cells[6 + rowsCount, 1] = "姓名";
 | ||
|                 xlSheet.Cells[6 + rowsCount, 2] = "阴历";
 | ||
|                 xlSheet.Cells[7 + rowsCount, 2] = "阳历";
 | ||
|                 xlSheet.Cells[8 + rowsCount, 2] = "星期";
 | ||
| 
 | ||
|                 /*设置标题栏红色*/
 | ||
|                 range = xlSheet.Range[xlSheet.Cells[3, 2], xlSheet.Cells[5, 20]];
 | ||
|                 range.Font.Color = Color.Red;    //红色
 | ||
|                 range = xlSheet.Range[xlSheet.Cells[6 + rowsCount, 2], xlSheet.Cells[8 + rowsCount, 20]];
 | ||
|                 range.Font.Color = Color.Red;    //红色
 | ||
| 
 | ||
|                 /*填写姓名*/
 | ||
|                 for (int j = 0; j < rowsCount; j++)
 | ||
|                 {
 | ||
|                     drv = dgv.Rows[j];
 | ||
|                     string name = drv.Cells["colName"].FormattedValue.ToString();
 | ||
|                     range = xlSheet.Range[xlSheet.Cells[j + 6, 1], xlSheet.Cells[j + 6, 2]];
 | ||
|                     range.Merge(System.Reflection.Missing.Value);
 | ||
|                     xlSheet.Cells[j + 6, 1] = name;
 | ||
| 
 | ||
|                     range = xlSheet.Range[xlSheet.Cells[j + 9 + rowsCount, 1], xlSheet.Cells[j + 9 + rowsCount, 2]];
 | ||
|                     range.Merge(System.Reflection.Missing.Value);
 | ||
|                     xlSheet.Cells[j + 9 + rowsCount, 1] = name;
 | ||
|                 }
 | ||
| 
 | ||
|                 /*填写日期中的班次*/
 | ||
|                 for (int i = 1; i <= dayMax; i++)
 | ||
|                 {
 | ||
|                     int colIndex;
 | ||
|                     if (i <= 16)
 | ||
|                     {
 | ||
|                         colIndex = i + 2;
 | ||
|                         /*填充日期表头*/
 | ||
|                         xlSheet.Cells[3, colIndex] = listHeaderDays[i - 1];
 | ||
|                         xlSheet.Cells[4, colIndex] = listHeaderChinese[i - 1];
 | ||
|                         xlSheet.Cells[5, colIndex] = listHeaderWeek[i - 1];
 | ||
|                         for (int j = 0; j < rowsCount; j++)
 | ||
|                         {
 | ||
|                             xlSheet.Cells[j + 6, colIndex] = dgv.Rows[j].Cells["Date" + i.ToString()].FormattedValue.ToString();
 | ||
|                         }
 | ||
|                     }
 | ||
|                     else
 | ||
|                     {
 | ||
|                         colIndex = i - 14;
 | ||
|                         xlSheet.Cells[6 + rowsCount, colIndex] = listHeaderDays[i - 1];
 | ||
|                         xlSheet.Cells[7 + rowsCount, colIndex] = listHeaderChinese[i - 1];
 | ||
|                         xlSheet.Cells[8 + rowsCount, colIndex] = listHeaderWeek[i - 1];
 | ||
|                         for (int j = 0; j < rowsCount; j++)
 | ||
|                         {
 | ||
|                             xlSheet.Cells[j + 9 + rowsCount, colIndex] = dgv.Rows[j].Cells["Date" + i.ToString()].FormattedValue;
 | ||
|                         }
 | ||
|                     }
 | ||
|                     Application.DoEvents();
 | ||
|                 }
 | ||
| 
 | ||
|                 ///*删除模板中多余的整行*/
 | ||
|                 string rowstr = string.Format("{0}:500", rowsCount * 2 + 9);
 | ||
|                 range = (Microsoft.Office.Interop.Excel.Range)xlSheet.Rows[rowstr, Type.Missing];
 | ||
|                 range.Rows.Delete(Microsoft.Office.Interop.Excel.XlDeleteShiftDirection.xlShiftUp);
 | ||
| 
 | ||
|                 /*设置打印为1页宽*/
 | ||
|                 xlSheet.PageSetup.FitToPagesWide = 1;
 | ||
|                 excel.PrintPreview();
 | ||
|                 excel.Close();
 | ||
|                 chxOnlyShiftPlan.Checked = oldChecked;
 | ||
|             }
 | ||
|             catch (Exception exp)
 | ||
|             {
 | ||
|                 MessageBox.Show(exp.Message);
 | ||
|                 PublicMethod.WriteLog(exp, "");
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         private void btnPrintAttendance_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             /*打印出缺勤表*/
 | ||
|             DateTime dateTime = this.dateTimePicker1.Value;
 | ||
|             int year = dateTime.Year;
 | ||
|             int month = dateTime.Month;
 | ||
|             DateTime monthFirstDay = new DateTime(year, month, 1);
 | ||
|             DateTime nextMonthFirstDay = monthFirstDay.AddMonths(1);
 | ||
|             int dayMax = nextMonthFirstDay.AddDays(-1).Day;
 | ||
| 
 | ||
|             string sql = string.Format("SELECT a.WorkerId, w.[Name], Day(a.SchedulingDate) as [Day], a.WorkersType, a.OverHours, a.LackHours FROM ScheduleOverLackHours a inner join Person w on a.WorkerId = w.id WHERE SchedulingDate >= '{0}' AND SchedulingDate<'{1}' order by WorkersType desc, w.PersonOrder, [Day]", GPFunctions.DateStr(monthFirstDay), GPFunctions.DateStr(nextMonthFirstDay));
 | ||
|             System.Data.DataTable dataTable = dbHelper.GetDataTable(sql);
 | ||
| 
 | ||
| 
 | ||
|             GoldPrinter.ExcelAccess excel = new GoldPrinter.ExcelAccess();
 | ||
|             excel.IsVisibledExcel = false;
 | ||
|             string filepath = string.Format("{0}\\Template\\职工出缺勤表.xlt", Application.StartupPath);
 | ||
|             excel.Open(filepath);
 | ||
|             Microsoft.Office.Interop.Excel.Worksheet xlSheet = (Microsoft.Office.Interop.Excel.Worksheet)excel.Workbooks.ActiveSheet;
 | ||
|             string strTitle = "职工出(缺)勤表";
 | ||
|             excel.SetCellText(1, "A", strTitle);
 | ||
|             excel.SetCellText(2, "E", string.Format("{0} 年 {1} 月", year, month));
 | ||
|             int rowsCount = dataTable.Rows.Count;
 | ||
|             decimal sumOverHours = 0, sumLackHours = 0;
 | ||
|             int prewWorkId = 0;
 | ||
|             int workerNumber = 0;
 | ||
|             int rowsNumber = 0;
 | ||
|             Microsoft.Office.Interop.Excel.Range range;
 | ||
|             switch (dayMax)
 | ||
|             {
 | ||
|                 case 30:
 | ||
|                     ((Microsoft.Office.Interop.Excel.Range)xlSheet.Cells[1, 33]).EntireColumn.ColumnWidth = 0;
 | ||
|                     break;
 | ||
|                 case 29:
 | ||
|                     ((Microsoft.Office.Interop.Excel.Range)xlSheet.Cells[1, 33]).EntireColumn.ColumnWidth = 0;
 | ||
|                     ((Microsoft.Office.Interop.Excel.Range)xlSheet.Cells[1, 32]).EntireColumn.ColumnWidth = 0;
 | ||
|                     break;
 | ||
|                 case 28:
 | ||
|                     ((Microsoft.Office.Interop.Excel.Range)xlSheet.Cells[1, 33]).EntireColumn.ColumnWidth = 0;
 | ||
|                     ((Microsoft.Office.Interop.Excel.Range)xlSheet.Cells[1, 32]).EntireColumn.ColumnWidth = 0;
 | ||
|                     ((Microsoft.Office.Interop.Excel.Range)xlSheet.Cells[1, 31]).EntireColumn.ColumnWidth = 0;
 | ||
|                     break;
 | ||
|                 default:
 | ||
|                     break;
 | ||
|             }
 | ||
| 
 | ||
|             for (int i = 0; i < rowsCount; i++)
 | ||
|             {
 | ||
|                 decimal overHours, lackHours;
 | ||
|                 DataRow dr = dataTable.Rows[i];
 | ||
| 
 | ||
|                 int workerId = Convert.ToInt32(dr["WorkerId"]);
 | ||
|                 int day = Convert.ToInt32(dr["Day"]);
 | ||
|                 overHours = GPFunctions.CDecimal(dr["OverHours"]);
 | ||
|                 lackHours = GPFunctions.CDecimal(dr["LackHours"]);
 | ||
| 
 | ||
|                 if (workerId == prewWorkId)
 | ||
|                 {
 | ||
|                     sumOverHours += overHours;
 | ||
|                     sumLackHours += lackHours;
 | ||
|                 }
 | ||
|                 else
 | ||
|                 {
 | ||
|                     /*合并姓名单元格, 填入名称*/
 | ||
|                     workerNumber++;
 | ||
|                     rowsNumber = 4 + (workerNumber - 1) * 2;
 | ||
|                     range = xlSheet.Range[xlSheet.Cells[rowsNumber, 1], xlSheet.Cells[rowsNumber + 1, 1]];
 | ||
|                     range.Merge(System.Reflection.Missing.Value);
 | ||
|                     xlSheet.Cells[rowsNumber, 1] = dr["Name"].ToString();
 | ||
| 
 | ||
|                     xlSheet.Cells[rowsNumber, 2] = "加班";
 | ||
|                     xlSheet.Cells[rowsNumber + 1, 2] = "缺勤";
 | ||
| 
 | ||
|                     range = xlSheet.Range[xlSheet.Cells[rowsNumber, "AI"], xlSheet.Cells[rowsNumber + 1, "AI"]];
 | ||
|                     range.Merge(System.Reflection.Missing.Value);
 | ||
| 
 | ||
|                     /*设置缺勤行字体颜色*/
 | ||
|                     rowsNumber = rowsNumber + 1;
 | ||
|                     range = xlSheet.Range[xlSheet.Cells[rowsNumber, 2], xlSheet.Cells[rowsNumber, 34]];
 | ||
|                     range.Font.Color = Color.Red;    //红色
 | ||
| 
 | ||
|                     if (workerNumber > 1)
 | ||
|                     {
 | ||
|                         /*填写上一个职工行的合计数*/
 | ||
|                         rowsNumber = 4 + (workerNumber - 2) * 2;
 | ||
|                         if (sumOverHours > 0) xlSheet.Cells[rowsNumber, "AH"] = sumOverHours;
 | ||
|                         if (sumLackHours > 0) xlSheet.Cells[rowsNumber + 1, "AH"] = sumLackHours;
 | ||
| 
 | ||
|                         /*合并累计单元格*/
 | ||
|                         xlSheet.Cells[rowsNumber, "AI"] = sumOverHours - sumLackHours;
 | ||
|                         if (sumOverHours - sumLackHours < 0)
 | ||
|                         {
 | ||
|                             /*累计小于0,红色显示*/
 | ||
|                             range.Font.Color = Color.Red;    //红色
 | ||
|                         }
 | ||
|                     }
 | ||
|                     sumOverHours = overHours;
 | ||
|                     sumLackHours = lackHours;
 | ||
| 
 | ||
|                     prewWorkId = workerId;
 | ||
|                 }
 | ||
|                 /*填入加班和缺勤缺勤小时数*/
 | ||
|                 rowsNumber = 4 + (workerNumber - 1) * 2;
 | ||
|                 if (overHours > 0) xlSheet.Cells[rowsNumber, 2 + day] = overHours;
 | ||
|                 if (lackHours > 0) xlSheet.Cells[rowsNumber + 1, 2 + day] = lackHours;
 | ||
| 
 | ||
|                 Application.DoEvents();
 | ||
|             }
 | ||
| 
 | ||
|             if (workerNumber > 0)
 | ||
|             {
 | ||
|                 /*填写最后一个职工行的合计数*/
 | ||
|                 rowsNumber = 4 + (workerNumber - 1) * 2;
 | ||
|                 if (sumOverHours > 0) xlSheet.Cells[rowsNumber, "AH"] = sumOverHours;
 | ||
|                 if (sumLackHours > 0) xlSheet.Cells[rowsNumber + 1, "AH"] = sumLackHours;
 | ||
|                 xlSheet.Cells[rowsNumber, "AI"] = sumOverHours - sumLackHours;
 | ||
|                 if (sumOverHours - sumLackHours < 0)
 | ||
|                 {
 | ||
|                     /*累计小于0,红色显示*/
 | ||
|                     range = xlSheet.Range[xlSheet.Cells[rowsNumber, "AI"], xlSheet.Cells[rowsNumber, "AI"]];
 | ||
|                     range.Font.Color = Color.Red;    //红色
 | ||
|                 }
 | ||
|             }
 | ||
|             excel.PrintPreview();
 | ||
|             excel.Close();
 | ||
|         }
 | ||
| 
 | ||
|         private void btnUp_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             /*对选中行向上移动*/
 | ||
|             DataTable dataTable = dtMainTable;
 | ||
|             if (dataTable == null) return;
 | ||
|             int rowsCount = dataTable.Rows.Count;
 | ||
| 
 | ||
|             int workId, xh, xh2;
 | ||
|             Dictionary<int, int> dic = new Dictionary<int, int>();
 | ||
| 
 | ||
|             bool ischecked = false;
 | ||
|             for (int i = 0; i < rowsCount; i++)
 | ||
|             {
 | ||
|                 DataRow dr = dataTable.Rows[i];
 | ||
|                 if (!ischecked)
 | ||
|                 {
 | ||
|                     ischecked = (int.Parse(dr["ColChecked"].ToString()) == 1);
 | ||
|                 }
 | ||
|                 workId = Convert.ToInt32(dr["WorkerId"]);
 | ||
|                 xh = Convert.ToInt32(dr["xh"]);
 | ||
|                 dic[workId] = xh;
 | ||
|             }
 | ||
|             if (!ischecked) return;
 | ||
| 
 | ||
| 
 | ||
|             DataGridView dgv = this.dataGridView1;
 | ||
|             int dgvCount = dgv.Rows.Count;
 | ||
|             int p = FindNextUncheckedCheckIndex(dgv, 0);
 | ||
|             if (p < 0) return;
 | ||
|             int p2 = 0;
 | ||
|             while (p >= 0)
 | ||
|             {
 | ||
|                 p2 = FindNextUncheckedIndex(dgv, p + 1);
 | ||
|                 if (p2 < p)
 | ||
|                 {
 | ||
|                     p2 = dgvCount;
 | ||
|                 }
 | ||
|                 workId = Convert.ToInt32(dgv.Rows[p].Cells["WorkerId"].Value);
 | ||
|                 xh = Convert.ToInt32(dgv.Rows[p2 - 1].Cells["ColXh"].Value);
 | ||
|                 dic[workId] = xh;
 | ||
|                 for (int j = p + 1; j < p2; j++)
 | ||
|                 {
 | ||
|                     workId = Convert.ToInt32(dgv.Rows[j].Cells["WorkerId"].Value);
 | ||
|                     xh = Convert.ToInt32(dgv.Rows[j - 1].Cells["ColXh"].Value);
 | ||
|                     dic[workId] = xh;
 | ||
|                 }
 | ||
| 
 | ||
|                 if (p2 < p) break;
 | ||
| 
 | ||
|                 p = FindNextUncheckedCheckIndex(dgv, p2);
 | ||
|             }
 | ||
| 
 | ||
|             for (int i = 0; i < rowsCount; i++)
 | ||
|             {
 | ||
|                 DataRow dr = dataTable.Rows[i];
 | ||
|                 workId = Convert.ToInt32(dr["WorkerId"]);
 | ||
|                 xh = Convert.ToInt32(dr["xh"]);
 | ||
|                 xh2 = dic[workId];
 | ||
|                 if (xh != xh2) dr["xh"] = xh2;
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 找出下一个:本行没有选中而下一行是选中的行的index
 | ||
|         /// </summary>
 | ||
|         /// <param name="dgv"></param>
 | ||
|         /// <param name="start"></param>
 | ||
|         /// <returns></returns>
 | ||
|         private int FindNextUncheckedCheckIndex(DataGridView dgv, int start)
 | ||
|         {
 | ||
|             int index = -1;
 | ||
|             if (start < 0) return -1;
 | ||
|             int n = dgv.Rows.Count - 1;
 | ||
|             if (start >= n) return -1;
 | ||
| 
 | ||
|             for (int i = start; i < n; i++)
 | ||
|             {
 | ||
|                 if (int.Parse(dgv.Rows[i].Cells["ColChecked"].Value.ToString()) == 0 && int.Parse(dgv.Rows[i + 1].Cells["ColChecked"].Value.ToString()) == 1)
 | ||
|                 {
 | ||
|                     index = i;
 | ||
|                     break;
 | ||
|                 }
 | ||
|             }
 | ||
|             return index;
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 找出下一个:没有选中的行的index
 | ||
|         /// </summary>
 | ||
|         /// <param name="dgv"></param>
 | ||
|         /// <param name="start"></param>
 | ||
|         /// <returns></returns>
 | ||
|         private int FindNextUncheckedIndex(DataGridView dgv, int start)
 | ||
|         {
 | ||
|             int index = -1;
 | ||
|             if (start < 0) return -1;
 | ||
|             int n = dgv.Rows.Count - 1;
 | ||
| 
 | ||
|             for (int i = start; i < n; i++)
 | ||
|             {
 | ||
|                 if (int.Parse(dgv.Rows[i].Cells["ColChecked"].Value.ToString()) == 0)
 | ||
|                 {
 | ||
|                     index = i;
 | ||
|                     break;
 | ||
|                 }
 | ||
|             }
 | ||
|             return index;
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 对选中行向下移动
 | ||
|         /// </summary>
 | ||
|         /// <param name="sender"></param>
 | ||
|         /// <param name="e"></param>
 | ||
|         private void btnDown_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             DataTable dataTable = dtMainTable;
 | ||
|             if (dataTable == null) return;
 | ||
|             int rowsCount = dataTable.Rows.Count;
 | ||
| 
 | ||
|             int workId, xh, xh2;
 | ||
|             Dictionary<int, int> dic = new Dictionary<int, int>();
 | ||
| 
 | ||
|             bool ischecked = false;
 | ||
|             for (int i = 0; i < rowsCount; i++)
 | ||
|             {
 | ||
|                 DataRow dr = dataTable.Rows[i];
 | ||
|                 if (!ischecked)
 | ||
|                 {
 | ||
|                     ischecked = (int.Parse(dr["ColChecked"].ToString()) == 1);
 | ||
|                 }
 | ||
|                 workId = Convert.ToInt32(dr["WorkerId"]);
 | ||
|                 xh = Convert.ToInt32(dr["xh"]);
 | ||
|                 dic[workId] = xh;
 | ||
|             }
 | ||
|             if (!ischecked) return;
 | ||
| 
 | ||
| 
 | ||
|             DataGridView dgv = this.dataGridView1;
 | ||
|             int dgvCount = dgv.Rows.Count;
 | ||
|             int p = FindNextCheckedIndex(dgv, 0);
 | ||
|             int p2 = 0;
 | ||
|             while (p >= 0)
 | ||
|             {
 | ||
|                 if (p < 0) return;
 | ||
|                 p2 = FindNextCheckedUnCheckIndex(dgv, p);
 | ||
|                 if (p2 < p)
 | ||
|                 {
 | ||
|                     break;
 | ||
|                 }
 | ||
|                 workId = Convert.ToInt32(dgv.Rows[p2].Cells["WorkerId"].Value);
 | ||
|                 xh = Convert.ToInt32(dgv.Rows[p].Cells["ColXh"].Value);
 | ||
|                 dic[workId] = xh;
 | ||
|                 for (int j = p; j < p2; j++)
 | ||
|                 {
 | ||
|                     workId = Convert.ToInt32(dgv.Rows[j].Cells["WorkerId"].Value);
 | ||
|                     xh = Convert.ToInt32(dgv.Rows[j + 1].Cells["ColXh"].Value);
 | ||
|                     dic[workId] = xh;
 | ||
|                 }
 | ||
|                 p = FindNextUncheckedCheckIndex(dgv, p2);
 | ||
|             }
 | ||
| 
 | ||
|             for (int i = 0; i < rowsCount; i++)
 | ||
|             {
 | ||
|                 DataRow dr = dataTable.Rows[i];
 | ||
|                 workId = Convert.ToInt32(dr["WorkerId"]);
 | ||
|                 xh = Convert.ToInt32(dr["xh"]);
 | ||
|                 xh2 = dic[workId];
 | ||
|                 if (xh != xh2) dr["xh"] = xh2;
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 找出下一个:本行没有选中而上一行选中的行的index
 | ||
|         /// </summary>
 | ||
|         /// <param name="dgv"></param>
 | ||
|         /// <param name="start"></param>
 | ||
|         /// <returns></returns>
 | ||
|         private int FindNextCheckedUnCheckIndex(DataGridView dgv, int start)
 | ||
|         {
 | ||
|             int index = -1;
 | ||
|             if (start < 0) return -1;
 | ||
|             int n = dgv.Rows.Count - 1;
 | ||
|             if (start >= n) return -1;
 | ||
| 
 | ||
|             for (int i = start; i < n; i++)
 | ||
|             {
 | ||
|                 if (int.Parse(dgv.Rows[i].Cells["ColChecked"].Value.ToString()) == 1 && int.Parse(dgv.Rows[i + 1].Cells["ColChecked"].Value.ToString()) == 0)
 | ||
|                 {
 | ||
|                     index = i + 1;
 | ||
|                     break;
 | ||
|                 }
 | ||
|             }
 | ||
|             return index;
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 找出下一个:选中的行的index
 | ||
|         /// </summary>
 | ||
|         /// <param name="dgv"></param>
 | ||
|         /// <param name="start"></param>
 | ||
|         /// <returns></returns>
 | ||
|         private int FindNextCheckedIndex(DataGridView dgv, int start)
 | ||
|         {
 | ||
|             int index = -1;
 | ||
|             if (start < 0) return -1;
 | ||
|             int n = dgv.Rows.Count - 1;
 | ||
| 
 | ||
|             for (int i = start; i < n; i++)
 | ||
|             {
 | ||
|                 if (int.Parse(dgv.Rows[i].Cells["ColChecked"].Value.ToString()) == 1)
 | ||
|                 {
 | ||
|                     index = i;
 | ||
|                     break;
 | ||
|                 }
 | ||
|             }
 | ||
|             return index;
 | ||
|         }
 | ||
| 
 | ||
|         private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
 | ||
|         {
 | ||
|             /*修改排序值时事件*/
 | ||
|             DataGridView dgv = this.dataGridView1;
 | ||
|             int colIndex = e.ColumnIndex;
 | ||
|             string columnName = dgv.Columns[colIndex].Name;
 | ||
|             if (columnName == "ColXh")
 | ||
|             {
 | ||
|                 int rowIndex = e.RowIndex;
 | ||
|                 int editVal = int.Parse(dgv.Rows[rowIndex].Cells[colIndex].Value.ToString());
 | ||
|                 int editWorkerId = Convert.ToInt32(dgv.Rows[rowIndex].Cells["WorkerId"].Value);
 | ||
|                 DataTable dataTable = dtMainTable;
 | ||
|                 int rowsCount = dataTable.Rows.Count;
 | ||
|                 if (editVal < 1 || editVal > rowsCount)
 | ||
|                 {
 | ||
|                     if (editVal < 1) editVal = 1; else editVal = rowsCount;
 | ||
|                 }
 | ||
| 
 | ||
|                 Dictionary<int, int> dic = new Dictionary<int, int>();
 | ||
|                 int workerId, xh;
 | ||
|                 for (int i = 0; i < rowsCount; i++)
 | ||
|                 {
 | ||
|                     DataRow dr = dataTable.Rows[i];
 | ||
|                     workerId = Convert.ToInt32(dr["WorkerId"]);
 | ||
|                     xh = Convert.ToInt32(dr["xh"]);
 | ||
|                     if (workerId == editWorkerId)
 | ||
|                     {
 | ||
|                         xh = editVal;
 | ||
|                     }
 | ||
|                     else
 | ||
|                     {
 | ||
|                         if (xh >= editVal)
 | ||
|                         {
 | ||
|                             xh = xh + 1;
 | ||
|                         }
 | ||
|                     }
 | ||
|                     dic[workerId] = xh;
 | ||
|                 }
 | ||
| 
 | ||
|                 for (int i = 0; i < rowsCount; i++)
 | ||
|                 {
 | ||
|                     DataRow dr = dataTable.Rows[i];
 | ||
|                     workerId = Convert.ToInt32(dr["WorkerId"]);
 | ||
|                     xh = Convert.ToInt32(dr["xh"]);
 | ||
|                     int xh2 = dic[workerId];
 | ||
|                     if (xh != xh2) dr["xh"] = xh2;
 | ||
|                 }
 | ||
|                 dtMainTable.DefaultView.Sort = "xh";
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         private void btnFresh_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             /*不保存调出原来的数据*/
 | ||
|             GetDataTableSchedulingNew();
 | ||
|         }
 | ||
| 
 | ||
|         private void chxHasInvaild_CheckedChanged(object sender, EventArgs e)
 | ||
|         {
 | ||
|             FreshDicSchedulingType();
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 错误信息屏蔽
 | ||
|         /// </summary>
 | ||
|         /// <param name="sender"></param>
 | ||
|         /// <param name="e"></param>
 | ||
|         private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
 | ||
|         {
 | ||
|         }
 | ||
|         private void dgvShiftPlan_DataError(object sender, DataGridViewDataErrorEventArgs e)
 | ||
|         {
 | ||
|         }
 | ||
| 
 | ||
|         private void dgvSchedulingType_DataError(object sender, DataGridViewDataErrorEventArgs e)
 | ||
|         {
 | ||
|         }
 | ||
| 
 | ||
|         private void btnClearChecked_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             DataGridView dgv = this.dataGridView1;
 | ||
|             for (int i = 0, n = dgv.Rows.Count; i < n; i++)
 | ||
|             {
 | ||
|                 DataGridViewRow dr = dgv.Rows[i];
 | ||
|                 if (int.Parse(dr.Cells["colChecked"].Value.ToString()) == 1)
 | ||
|                 {
 | ||
|                     /*设置值*/
 | ||
|                     dr.Cells["colChecked"].Value = 0;
 | ||
|                 }
 | ||
|             }
 | ||
|             dgv.EndEdit();
 | ||
|         }
 | ||
| 
 | ||
|         private void FrmScheduling2_FormClosing(object sender, FormClosingEventArgs e)
 | ||
|         {
 | ||
|             /*退出前,判断是否保存, 提示用户是否退出?*/
 | ||
|             this.dataGridView1.EndEdit();
 | ||
|             int n = GetDataTableChangedCount(dtMainTable);
 | ||
|             if (n > 0)
 | ||
|             {
 | ||
|                 if (MessageBox.Show("数据修改后没有保存,是否继续退出?", "提示信息", MessageBoxButtons.YesNo) == DialogResult.No)
 | ||
|                 {
 | ||
|                     e.Cancel = true;
 | ||
|                 }
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         private void chxModified_CheckedChanged(object sender, EventArgs e)
 | ||
|         {
 | ||
|             DataGridView dgv = this.dataGridView1;
 | ||
|             string[] items;
 | ||
|             if (!chxModified.Checked)
 | ||
|             {
 | ||
|                 items = ArrayAddEmptyValue(dicSchedulingTypeNameId.Keys.ToArray());
 | ||
|                 Array.Sort(items);
 | ||
|             }
 | ||
|             else
 | ||
|             {
 | ||
|                 items = validSchedulingTypes;
 | ||
|             }
 | ||
|             for (int i = 1; i <= 31; i++)
 | ||
|             {
 | ||
|                 string columnName = string.Format("Date{0}", i);
 | ||
|                 DataGridViewComboBoxColumn cbxColumn = (DataGridViewComboBoxColumn)dgv.Columns[columnName];
 | ||
|                 cbxColumn.Items.Clear();
 | ||
|                 cbxColumn.Items.AddRange(items);
 | ||
|             }
 | ||
|             dgv.Update();
 | ||
|         }
 | ||
| 
 | ||
|         public static int GetDataTableChangedCount(DataTable dataTable)
 | ||
|         {
 | ||
|             int num = 0;
 | ||
|             bool flag = dataTable == null;
 | ||
|             int result;
 | ||
|             if (flag)
 | ||
|             {
 | ||
|                 result = 0;
 | ||
|             }
 | ||
|             else
 | ||
|             {
 | ||
|                 foreach (DataRow dataRow in dataTable.Rows)
 | ||
|                 {
 | ||
|                     bool flag2 = dataRow.RowState != DataRowState.Unchanged;
 | ||
|                     if (flag2)
 | ||
|                     {
 | ||
|                         num++;
 | ||
|                     }
 | ||
|                 }
 | ||
|                 result = num;
 | ||
|             }
 | ||
|             return result;
 | ||
|         }
 | ||
| 
 | ||
|         private void dgvShiftPlan_CellClick(object sender, DataGridViewCellEventArgs e)
 | ||
|         {
 | ||
|             if (e.ColumnIndex == -1 || e.RowIndex == -1) return;
 | ||
|             int x = dgvShiftPlan.CurrentCell.ColumnIndex;//获取鼠标的点击列
 | ||
|             if (x == 0)//点击第一列是单选。
 | ||
|             {
 | ||
|                 for (int i = 0; i < dgvShiftPlan.Rows.Count; i++)
 | ||
|                 {
 | ||
|                     DataGridViewCheckBoxCell checkcell = (DataGridViewCheckBoxCell)dgvShiftPlan.Rows[i].Cells[0];
 | ||
|                     checkcell.Value = false;
 | ||
|                 }
 | ||
|                 DataGridViewCheckBoxCell ifcheck = (DataGridViewCheckBoxCell)dgvShiftPlan.Rows[e.RowIndex].Cells[0];
 | ||
|                 ifcheck.Value = true;
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         private void btnupMonth_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             dateTimePicker1.Value = dateTimePicker1.Value.AddMonths(-1);
 | ||
|         }
 | ||
| 
 | ||
|         private void btnDownMonth_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             dateTimePicker1.Value = dateTimePicker1.Value.AddMonths(1);
 | ||
|         }
 | ||
|     }
 | ||
| }
 |