frmTimeMain.cs 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using System.IO;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using System.Data.OleDb;
  10. using System.Drawing;
  11. using LYFZ.ComponentLibrary;
  12. using System.Collections;
  13. namespace LYFZ.Software.MainBusiness.TimeAndAttendance
  14. {
  15. public class frmTimeMain : LYFZ.Software.UI.TimeAndAttendance.frmTimeMain
  16. {
  17. LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
  18. LYFZ.BLL.BLL_Loninbansets lbsetbll = new BLL.BLL_Loninbansets();
  19. public frmTimeMain()
  20. {
  21. this.Load += frmTimeMain_Load;
  22. this.btnLastWeek.Click += btnLastWeek_Click;
  23. this.btnNextWeek.Click += btnNextWeek_Click;
  24. this.btnEmployeeSchedule.Click += btnEmployeeSchedule_Click;
  25. this.btnSaveModule.Click += btnSaveModule_Click;
  26. this.btnGetModule.Click += btnGetModule_Click;
  27. this.btnSaveed.Click += btnSaveed_Click;
  28. this.btnTimeSet.Click += btnTimeSet_Click;
  29. this.btnSigned.Click += btnSigned_Click;
  30. this.btnSignedRecords.Click += btnSignedRecords_Click;
  31. this.btnClose.Click += btnClose_Click;
  32. this.dtpYearMonth.ClickChengedValue += dtpYearMonth_ClickChengedValue;
  33. this.chkWeekMode.Click += chkzhouyue_Click;
  34. this.cmbtreev.Leave += cmbtreev_Leave;
  35. this.dgvData.CellDoubleClick += dgvData_CellDoubleClick;
  36. this.dgvData.CellMouseDown += dgvData_CellMouseDown;
  37. this.dgvData.DataGridViewConMenu_ItemClicked += dgvData_DataGridViewConMenu_ItemClicked;
  38. this.dgvData.Scroll += dgvData_Scroll;
  39. this.Resize += frmTimeMain_Resize;
  40. //BindCompanyList();
  41. cbxCompanyList.ComboBoxTree_NodeMouseClick += CbxCompanyList_ComboBoxTree_NodeMouseClick;
  42. }
  43. private void CbxCompanyList_ComboBoxTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  44. {
  45. this.GetQueryMonthData();
  46. }
  47. DateTime WeekStartDate;
  48. DateTime WeekEndDate;
  49. string StrTextName = "";
  50. /// <summary>
  51. /// 窗体加载事件
  52. /// </summary>
  53. /// <param name="sender"></param>
  54. /// <param name="e"></param>
  55. void frmTimeMain_Load(object sender, EventArgs e)
  56. {
  57. this.panelLastNextWeek.Visible = false;
  58. Control.CheckForIllegalCrossThreadCalls = false;
  59. this.dgvData.dgvColumnHeadersHeight = 35;
  60. this.dtpYearMonth.StrDateValue = SDateTime.Now.ToString("yyyy-MM");
  61. #region 获取本周
  62. this.WeekStartDate = SDateTime.Now.AddDays(Convert.ToInt32(SDateTime.Now.DayOfWeek) * -1);
  63. this.WeekEndDate = SDateTime.Now.AddDays(6 - Convert.ToInt32(SDateTime.Now.DayOfWeek));
  64. #endregion
  65. StrTextName = "休息,请假,";
  66. DataTable dat = orbll.GetView_Custom("lonintimeset", StrWhere: "", ShowColumnName: "name").Tables[0];
  67. for (int cmb = 0; cmb < dat.Rows.Count; cmb++)
  68. { StrTextName += dat.Rows[cmb]["name"].ToString().Trim() + ","; }
  69. // 部门人员绑定
  70. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_DepartmentAndEmployee(this.cbxCompanyList, IsFirstNodeNull: true, IsFirstNodeName: "全部", IsShowResign: false, IsShowAdmin: true, tb_User: LYFZ.DAL.DAL_ErpUser.SimpleUserDataTable);
  71. this.cbxCompanyList.AfterSelectLevelFirstNode = true;
  72. this.cbxCompanyList.IsNodeMouseClick = true;
  73. this.cbxCompanyList.IsSelectParentNode = true;
  74. cbxCompanyList.TextFindTag("全部");
  75. this.GetQueryMonthData();
  76. bool b = LYFZ.Software.MainBusiness.VersionControl.StaticVersion.UIFunctionVersion(
  77. VersionControl.VersionFunctionEnum.员工考勤考勤管理);
  78. if (!b)
  79. {
  80. this.Close();
  81. }
  82. }
  83. void BindCompanyList()
  84. {
  85. BLL.BLL_ErpCompanyInfo bllCompany = new BLL.BLL_ErpCompanyInfo();
  86. DataTable dt = bllCompany.GetAllList().Tables[0];
  87. cbxCompanyList.Items.Add(new ItemValue("", "全部"));
  88. foreach(DataRow dr in dt.Rows)
  89. {
  90. cbxCompanyList.Items.Add(new ItemValue(dr["Company_DividedShop"].ToString(), dr["Company_Name"].ToString_s()));
  91. }
  92. cbxCompanyList.SelectedIndex = 0;
  93. }
  94. /// <summary>
  95. /// 上星期
  96. /// </summary>
  97. /// <param name="sender"></param>
  98. /// <param name="e"></param>
  99. void btnLastWeek_Click(object sender, EventArgs e)
  100. {
  101. this.WeekStartDate = this.WeekStartDate.AddDays(-7);
  102. this.WeekEndDate = this.WeekEndDate.AddDays(-7);
  103. this.GetQueryWeekData();
  104. this.GetWeekCount();
  105. }
  106. /// <summary>
  107. /// 下星期
  108. /// </summary>
  109. /// <param name="sender"></param>
  110. /// <param name="e"></param>
  111. void btnNextWeek_Click(object sender, EventArgs e)
  112. {
  113. this.WeekStartDate = this.WeekStartDate.AddDays(7);
  114. this.WeekEndDate = this.WeekEndDate.AddDays(7);
  115. this.GetQueryWeekData();
  116. this.GetWeekCount();
  117. }
  118. /// <summary>
  119. /// 员工档期
  120. /// </summary>
  121. /// <param name="sender"></param>
  122. /// <param name="e"></param>
  123. void btnEmployeeSchedule_Click(object sender, EventArgs e)
  124. {
  125. LYFZ.Software.MainBusiness.CameraControlBook.SmallForm.A_EmployeeScheduleSmallForm frm = new CameraControlBook.SmallForm.A_EmployeeScheduleSmallForm();
  126. frm.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
  127. frm.Location = new Point(LYFZ.EnumPublic.FormLocation_X, LYFZ.EnumPublic.FormLocation_Y);
  128. frm.Size = new Size(LYFZ.EnumPublic.FormSize_Width, LYFZ.EnumPublic.FormSize_Height);
  129. frm.ShowDialog();
  130. }
  131. /// <summary>
  132. /// 存为模板
  133. /// </summary>
  134. /// <param name="sender"></param>
  135. /// <param name="e"></param>
  136. void btnSaveModule_Click(object sender, EventArgs e)
  137. {
  138. string StrModelName = "考勤排班模板(月)";
  139. string StrExtension = ".Mban";
  140. if (this.chkWeekMode.Checked)
  141. {
  142. StrModelName = "考勤排班模板(周)";
  143. StrExtension = ".Wban";
  144. }
  145. DataTable NewTable = this.dgvData.ToDataTable(IsShowVisible: true);
  146. SaveFileDialog saveFile = new SaveFileDialog();
  147. saveFile.FileName = StrModelName;
  148. saveFile.Title = "存排班模板";
  149. saveFile.Filter = "文件ban |*" + StrExtension;
  150. saveFile.FilterIndex = 1;
  151. DialogResult drst = saveFile.ShowDialog();
  152. if (drst == DialogResult.No || drst == DialogResult.Cancel || drst == DialogResult.No || drst == DialogResult.Abort)
  153. { return; }
  154. string StrPath = saveFile.FileName.Trim().Replace(StrExtension, "");
  155. //if (LYFZ.Command.Command_ExportExcel.DataTable2Sheet(StrPath + ".xls", NewTable, "Sheet1", IsCoveredExistingFile: true))
  156. //{
  157. // string StrSrcPath = StrPath + ".xls";
  158. // string StrDesPath = saveFile.FileName.Trim();
  159. // if (File.Exists(StrSrcPath))
  160. // {
  161. // if (File.Exists(StrDesPath))
  162. // {
  163. // try
  164. // { File.Delete(StrDesPath); }
  165. // catch
  166. // { MessageBoxCustom.Show("存模板失败!"); return; }
  167. // }
  168. // FileInfo fi = new FileInfo(StrSrcPath);
  169. // try
  170. // {
  171. // fi.MoveTo(StrDesPath);
  172. // MessageBoxCustom.Show("存模板成功!");
  173. // }
  174. // catch
  175. // {
  176. // File.Delete(StrSrcPath);
  177. // MessageBoxCustom.Show("存模板失败!");
  178. // return;
  179. // }
  180. // }
  181. // else
  182. // { MessageBoxCustom.Show("存模板失败!"); }
  183. //}
  184. //else
  185. //{ MessageBoxCustom.Show("存模板失败!"); }
  186. LYFZ.ComponentLibrary.FrmLoadHandling.ExecutionDoWorkMethod(delegate (object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
  187. {
  188. try
  189. {
  190. if (LYFZ.WinAPI.CustomPublicMethod.DataGridViewToExcel(StrPath + ".xls", NewTable, null, backgroundWorker))
  191. {
  192. string StrSrcPath = StrPath + ".xls";
  193. string StrDesPath = saveFile.FileName.Trim();
  194. if (File.Exists(StrSrcPath))
  195. {
  196. if (File.Exists(StrDesPath))
  197. {
  198. try
  199. { File.Delete(StrDesPath); }
  200. catch
  201. { MessageBoxCustom.Show("存模板失败!"); return; }
  202. }
  203. FileInfo fi = new FileInfo(StrSrcPath);
  204. try
  205. {
  206. fi.MoveTo(StrDesPath);
  207. MessageBoxCustom.Show("存模板成功!");
  208. }
  209. catch
  210. {
  211. File.Delete(StrSrcPath);
  212. MessageBoxCustom.Show("存模板失败!");
  213. return;
  214. }
  215. }
  216. else
  217. { MessageBoxCustom.Show("存模板失败!"); }
  218. }
  219. else
  220. {
  221. MessageBoxCustom.Show("存模板失败!");
  222. }
  223. }
  224. catch (Exception ex)
  225. {
  226. MessageBoxCustom.Show(String.Format("导出数据出错:{0}", ex.Message));
  227. }
  228. });
  229. }
  230. /// <summary>
  231. /// 读取模板
  232. /// </summary>
  233. /// <param name="sender"></param>
  234. /// <param name="e"></param>
  235. void btnGetModule_Click(object sender, EventArgs e)
  236. {
  237. string StrExtension = ".Mban";
  238. if (this.chkWeekMode.Checked)
  239. { StrExtension = ".Wban"; }
  240. OpenFileDialog openFileDialog1 = new OpenFileDialog();
  241. openFileDialog1.Filter = "文件ban |*" + StrExtension;
  242. if (openFileDialog1.ShowDialog() == DialogResult.OK)
  243. {
  244. this.dgvData.Rows.Clear();
  245. DataGridViewRow dgvr = null;
  246. DataGridViewCell cell = null;
  247. DataTable dtPerson = orbll.GetView_Custom("tb_ErpUser", StrWhere: "User_Status='在职'", ShowColumnName: "User_EmployeeID,User_Name").Tables[0];
  248. DataTable dtExcel = LYFZ.WinAPI.CustomPublicMethod.GetExcelDatatable(openFileDialog1.FileName.Trim());
  249. string StrWhere = "";
  250. if (this.chkWeekMode.Checked)
  251. { StrWhere = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Time", this.WeekStartDate.ToString("yyyy-MM-dd"), this.WeekEndDate.ToString("yyyy-MM-dd")); }
  252. else
  253. {
  254. string StrDateStart = this.dtpYearMonth.StrDateValue.Trim() + "-01";
  255. string StrDateEnd = Convert.ToDateTime(StrDateStart).AddMonths(1).AddSeconds(-1).ToString("yyyy-MM-dd");
  256. StrWhere = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Time", StrDateStart, StrDateEnd);
  257. }
  258. DataTable dt = this.GetWorkPerson();
  259. if (dtPerson.Rows.Count > 0)
  260. {
  261. for (int i = 0; i < dtPerson.Rows.Count; i++)
  262. {
  263. dgvr = new DataGridViewRow();
  264. cell = new DataGridViewTextBoxCell();
  265. cell.Value = dtPerson.Rows[i]["User_EmployeeID"].ToString().Trim();
  266. dgvr.Cells.Add(cell);
  267. cell = new DataGridViewTextBoxCell();
  268. cell.Value = dtPerson.Rows[i]["User_Name"].ToString().Trim();
  269. dgvr.Cells.Add(cell);
  270. DataRow[] dtRows = dtExcel.Select("员工编号 = '" + dtPerson.Rows[i]["User_EmployeeID"].ToString().Trim() + "'");
  271. for (int j = 2; j < this.dgvData.Columns.Count; j++)
  272. {
  273. string StrCellValue = "";
  274. if (dtRows.Length > 0)
  275. {
  276. if (j < dtExcel.Columns.Count)
  277. {
  278. if (!string.IsNullOrEmpty(dtRows[0][j].ToString().Trim()))
  279. { StrCellValue = dtRows[0][j].ToString().Trim(); }
  280. }
  281. }
  282. cell = new DataGridViewTextBoxCell();
  283. cell.Value = StrCellValue.Trim();
  284. if (StrCellValue.Trim() == "休息")
  285. {
  286. string StrWhereDate = "";
  287. if (this.chkWeekMode.Checked)
  288. { StrWhereDate = this.WeekStartDate.AddDays((j - 2)).ToString("yyyy-MM-dd"); }
  289. else
  290. { StrWhereDate = Convert.ToDateTime(this.dtpYearMonth.StrDateValue.Trim() + "-01").AddDays((j - 2)).ToString("yyyy-MM-dd"); }
  291. DataRow[] dtRows2 = dt.Select("工作人员 = '" + dtPerson.Rows[i]["User_EmployeeID"].ToString().Trim() + "' And 工作日期 = '" + StrWhereDate + "'");
  292. if (dtRows2.Length > 0)
  293. { cell.Style.BackColor = Color.Red; }
  294. }
  295. dgvr.Cells.Add(cell);
  296. }
  297. this.dgvData.Rows.Add(dgvr);
  298. }
  299. }
  300. }
  301. }
  302. /// <summary>
  303. /// 获取人员
  304. /// </summary>
  305. /// <returns></returns>
  306. DataTable GetWorkPerson()
  307. {
  308. string StrDateStart = this.dtpYearMonth.StrDateValue.Trim() + "-01";
  309. string StrDateEnd = Convert.ToDateTime(StrDateStart).AddMonths(1).AddSeconds(-1).ToString("yyyy-MM-dd");
  310. if (this.chkWeekMode.Checked)
  311. {
  312. StrDateStart = this.WeekStartDate.ToString("yyyy-MM-dd");
  313. StrDateEnd = this.WeekEndDate.ToString("yyyy-MM-dd");
  314. }
  315. string StrWhere = " Where" + LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Convert(datetime,工作日期)", StrDateStart, StrDateEnd, ConnectWord: "");
  316. return this.GetWorkPerson(StrWhere);
  317. }
  318. /// <summary>
  319. /// 获取人员的DataTable
  320. /// </summary>
  321. /// <param name="StrWhere"></param>
  322. DataTable GetWorkPerson(string StrWhere)
  323. {
  324. string ExecuteSql = "with t AS ( " +
  325. "select Ordpg_ReservationPhotographyName AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_ReservationPhotographyTime)) AS 工作日期 from tb_ErpOrdersPhotography Where Ordpg_ReservationPhotographyName != '' And Ordpg_ReservationPhotographyTime is not null " +
  326. "UNION ALL " +
  327. "select Ordpg_ReservationPhotographyAssistant AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_ReservationPhotographyTime)) AS 工作日期 from tb_ErpOrdersPhotography Where Ordpg_ReservationPhotographyAssistant != '' And Ordpg_ReservationPhotographyTime is not null " +
  328. "UNION ALL " +
  329. "select Ordpg_ReservationMakeupArtist AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_ReservationPhotographyTime)) AS 工作日期 from tb_ErpOrdersPhotography Where Ordpg_ReservationMakeupArtist != '' And Ordpg_ReservationPhotographyTime is not null " +
  330. "UNION ALL " +
  331. "select Ordpg_ReservationMakeupAssistant AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_ReservationPhotographyTime)) AS 工作日期 from tb_ErpOrdersPhotography Where Ordpg_ReservationMakeupAssistant != '' And Ordpg_ReservationPhotographyTime is not null " +
  332. "UNION ALL " +
  333. "select Ordpg_ReservationBootDivision AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_ReservationPhotographyTime)) AS 工作日期 from tb_ErpOrdersPhotography Where Ordpg_ReservationBootDivision != '' And Ordpg_ReservationPhotographyTime is not null " +
  334. "UNION ALL " +
  335. "select Ordpg_ReservationBootDivisionAssistant AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_ReservationPhotographyTime)) AS 工作日期 from tb_ErpOrdersPhotography Where Ordpg_ReservationBootDivisionAssistant != '' And Ordpg_ReservationPhotographyTime is not null " +
  336. "UNION ALL " +
  337. "select Ordv_ReservationClothingName AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_ReservationClothingTime)) AS 工作日期 from tb_ErpOrderDigital Where Ordv_ReservationClothingName != '' And Ordv_ReservationClothingTime is not null " +
  338. "UNION ALL " +
  339. "select Ordv_ReservationEarlyRepairName AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_ReservationEarlyRepairTime)) AS 工作日期 from tb_ErpOrderDigital Where Ordv_ReservationEarlyRepairName != '' And Ordv_ReservationEarlyRepairTime is not null " +
  340. "UNION ALL " +
  341. "select Ordv_ReservationFilmSelectionName AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_ReservationFilmSelectionTime)) AS 工作日期 from tb_ErpOrderDigital Where Ordv_ReservationFilmSelectionName != '' And Ordv_ReservationFilmSelectionTime is not null " +
  342. "UNION ALL " +
  343. "select Ordv_ReservationRefinementName AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_ReservationRefinementTime)) AS 工作日期 from tb_ErpOrderDigital Where Ordv_ReservationRefinementName != '' And Ordv_ReservationRefinementTime is not null " +
  344. "UNION ALL " +
  345. "select Ordv_ReservationDesignerName AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_ReservationDesignerTime)) AS 工作日期 from tb_ErpOrderDigital Where Ordv_ReservationDesignerName != '' And Ordv_ReservationDesignerTime is not null " +
  346. "UNION ALL " +
  347. "select Ordv_ReservationLookDesignName AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_ReservationLookDesignTime)) AS 工作日期 from tb_ErpOrderDigital Where Ordv_ReservationLookDesignName != '' And Ordv_ReservationLookDesignTime is not null " +
  348. "UNION ALL " +
  349. "select Ordv_ReservationSendPhotoName AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_ReservationSendPhotoTime)) AS 工作日期 from tb_ErpOrderDigital Where Ordv_ReservationSendPhotoName != '' And Ordv_ReservationSendPhotoTime is not null " +
  350. "UNION ALL " +
  351. "select OPlist_ReservationTakeName AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_ReservationTakeTime)) AS 工作日期 from tb_ErpOrderProductList where OPlist_Type = '2' And OPlist_ReservationTakeName != '' And OPlist_ReservationTakeTime is not null " +
  352. "UNION ALL " +
  353. "select Ws_Serviceman1 AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ws_WeddingDate)) AS 工作日期 from tb_ErpWeddingService Where Ws_Status = '0' And Ws_Serviceman1 != '' And Ws_WeddingDate is not null " +
  354. "UNION ALL " +
  355. "select Ws_Serviceman2 AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ws_WeddingDate)) AS 工作日期 from tb_ErpWeddingService Where Ws_Status = '0' And Ws_Serviceman2 != '' And Ws_WeddingDate is not null " +
  356. ") " +
  357. "select * from t " + StrWhere + "Group By 工作人员,工作日期";
  358. return orbll.GetView_Custom(ExecuteSql).Tables[0];
  359. }
  360. /// <summary>
  361. /// 保存
  362. /// </summary>
  363. /// <param name="sender"></param>
  364. /// <param name="e"></param>
  365. void btnSaveed_Click(object sender, EventArgs e)
  366. {
  367. LYFZ.Model.Model_Loninbansets model = null;
  368. List<Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
  369. string StrMages = "";
  370. for (int i = 0; i < this.dgvData.Rows.Count; i++)
  371. {
  372. string StrTip = "";
  373. for (int j = 2; j < this.dgvData.Columns.Count; j++)
  374. {
  375. if (this.dgvData.Rows[i].Cells[j].Value.ToString().Trim() == "休息" && this.dgvData.Rows[i].Cells[j].Style.BackColor == Color.Red)
  376. { StrTip += this.dgvData.Columns[j].Name.Trim().Replace("\r\n", "") + ","; }
  377. }
  378. if (!string.IsNullOrEmpty(StrTip))
  379. { StrMages += this.dgvData.Rows[i].Cells["姓名"].Value.ToString().Trim() + ":" + StrTip.TrimEnd(',') + "\r\n"; }
  380. }
  381. if (!string.IsNullOrEmpty(StrMages))
  382. { MessageBoxCustom.Show("列表中红色格子的休息日已安排有工作,不能安排休息!\r\n" + StrMages); return; }
  383. if (this.chkWeekMode.Checked)
  384. {
  385. string StrStartDate = this.WeekStartDate.ToString("yyyy-MM-dd");
  386. string StrEndDate = this.WeekEndDate.ToString("yyyy-MM-dd");
  387. string StrWhere = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Time", StrStartDate, StrEndDate, ConnectWord: "");
  388. DataTable dt = orbll.GetView_Custom("loninbansets", StrWhere: StrWhere, ShowColumnName: "*").Tables[0];
  389. for (int i = 0; i < this.dgvData.Rows.Count; i++)
  390. {
  391. for (int j = 3; j < this.dgvData.Columns.Count; j++)
  392. {
  393. string StrNowDateTime = Convert.ToDateTime(this.WeekStartDate.AddDays(j - 3).ToString("yyyy-MM-dd")).ToString("yyyy-MM-dd HH:mm:ss");
  394. DataRow[] dtRows = dt.Select("User_ID = '" + this.dgvData.Rows[i].Cells["员工编号"].Value.ToString().Trim() + "' And Time = '" + StrNowDateTime + "'");
  395. if (dtRows.Length > 0)
  396. {
  397. if (this.dgvData.Rows[i].Cells[j].Value.ToString().Trim() != dtRows[0]["Fixed"].ToString().Trim())
  398. {
  399. model = lbsetbll.DataRowToModel(dtRows[0]);
  400. model.Fixed = this.dgvData.Rows[i].Cells[j].Value.ToString().Trim();
  401. model.Time = Convert.ToDateTime(model.Time).ToString("yyyy-MM-dd HH:mm:ss");
  402. clist.Add(lbsetbll.GetUpdateCommandInfo(model));
  403. }
  404. }
  405. else
  406. {
  407. model = new Model.Model_Loninbansets();
  408. model.User_ID = this.dgvData.Rows[i].Cells["员工编号"].Value.ToString().Trim();
  409. model.Time = StrNowDateTime;
  410. model.Fixed = this.dgvData.Rows[i].Cells[j].Value.ToString().Trim();
  411. clist.Add(lbsetbll.GetAddCommandInfo(model));
  412. }
  413. }
  414. }
  415. }
  416. else
  417. {
  418. string StrStartDate = this.dtpYearMonth.StrDateValue.Trim() + "-01";
  419. string StrEndDate = Convert.ToDateTime(StrStartDate).AddMonths(1).ToString("yyyy-MM-dd");
  420. string StrWhere = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Time", StrStartDate, StrEndDate, ConnectWord: "");
  421. DataTable dt = orbll.GetView_Custom("loninbansets", StrWhere: StrWhere, ShowColumnName: "*").Tables[0];
  422. for (int i = 0; i < this.dgvData.Rows.Count; i++)
  423. {
  424. for (int j = 1; j < this.dgvData.Columns.Count - 2; j++)
  425. {
  426. string StrNowDateTime = this.dtpYearMonth.StrDateValue.Trim() + "-" + (j).ToString("d2") + " 00:00:00";
  427. DataRow[] dtRows = dt.Select("User_ID = '" + this.dgvData.Rows[i].Cells["员工编号"].Value.ToString().Trim() + "' And Time = '" + StrNowDateTime + "'");
  428. if (dtRows.Length > 0)
  429. {
  430. if (this.dgvData.Rows[i].Cells[j + 2].Value.ToString().Trim() != dtRows[0]["Fixed"].ToString().Trim())
  431. {
  432. model = lbsetbll.DataRowToModel(dtRows[0]);
  433. model.Fixed = this.dgvData.Rows[i].Cells[j + 2].Value.ToString().Trim();
  434. model.Time = Convert.ToDateTime(model.Time).ToString("yyyy-MM-dd HH:mm:ss");
  435. clist.Add(lbsetbll.GetUpdateCommandInfo(model));
  436. }
  437. }
  438. else
  439. {
  440. model = new Model.Model_Loninbansets();
  441. model.User_ID = this.dgvData.Rows[i].Cells["员工编号"].Value.ToString().Trim();
  442. model.Time = StrNowDateTime;
  443. model.Fixed = this.dgvData.Rows[i].Cells[j + 2].Value.ToString().Trim();
  444. clist.Add(lbsetbll.GetAddCommandInfo(model));
  445. }
  446. }
  447. }
  448. }
  449. if (clist.Count > 0)
  450. {
  451. if (MessageBoxCustom.Show("您确定要保存吗?", "温馨提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
  452. {
  453. int intExecuteCount = 0;
  454. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
  455. {
  456. intExecuteCount = LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist);
  457. });
  458. if (intExecuteCount > 0)
  459. { MessageBoxCustom.Show("保存成功!"); }
  460. else
  461. { MessageBoxCustom.Show("保存失败!"); }
  462. }
  463. }
  464. else
  465. { MessageBoxCustom.Show("没做过任何修改,无须保存!"); }
  466. }
  467. /// <summary>
  468. /// 时间设置
  469. /// </summary>
  470. /// <param name="sender"></param>
  471. /// <param name="e"></param>
  472. void btnTimeSet_Click(object sender, EventArgs e)
  473. {
  474. frmTimeupdate frm = new frmTimeupdate();
  475. frm.ShowDialog();
  476. }
  477. /// <summary>
  478. /// 签单
  479. /// </summary>
  480. /// <param name="sender"></param>
  481. /// <param name="e"></param>
  482. void btnSigned_Click(object sender, EventArgs e)
  483. {
  484. if (this.dgvData.SelectedRows.Count > 0)
  485. {
  486. frmTimesign frm = new frmTimesign();
  487. frm.StrUserNumber = this.dgvData.SelectedRows[0].Cells["员工编号"].Value.ToString().Trim();
  488. frm.StrUserName = this.dgvData.SelectedRows[0].Cells["姓名"].Value.ToString().Trim();
  489. frm.ShowDialog();
  490. }
  491. else
  492. { MessageBoxCustom.Show("请选择一个员工签单!"); }
  493. }
  494. /// <summary>
  495. /// 签单记录
  496. /// </summary>
  497. /// <param name="sender"></param>
  498. /// <param name="e"></param>
  499. void btnSignedRecords_Click(object sender, EventArgs e)
  500. {
  501. frmtimeRecording frm = new frmtimeRecording();
  502. frm.ShowDialog();
  503. }
  504. /// <summary>
  505. /// 关闭
  506. /// </summary>
  507. /// <param name="sender"></param>
  508. /// <param name="e"></param>
  509. void btnClose_Click(object sender, EventArgs e)
  510. {
  511. this.Close();
  512. }
  513. /// <summary>
  514. /// 选择年月
  515. /// </summary>
  516. /// <param name="SelectValue"></param>
  517. void dtpYearMonth_ClickChengedValue(string SelectValue)
  518. {
  519. this.GetQueryMonthData();
  520. }
  521. /// <summary>
  522. /// 周模式
  523. /// </summary>
  524. /// <param name="sender"></param>
  525. /// <param name="e"></param>
  526. void chkzhouyue_Click(object sender, EventArgs e)
  527. {
  528. this.dgvData.Rows.Clear();
  529. if (this.chkWeekMode.Checked)
  530. {
  531. this.panelLastNextWeek.Visible = true;
  532. this.dtpYearMonth.Visible = false;
  533. this.lblWhichWeek.Visible = true;
  534. this.GetQueryWeekData();
  535. this.GetWeekCount();
  536. }
  537. else
  538. {
  539. this.panelLastNextWeek.Visible = false;
  540. this.dtpYearMonth.Visible = true;
  541. this.lblWhichWeek.Visible = false;
  542. this.frmTimeMain_Load(null, null);
  543. }
  544. }
  545. /// <summary>
  546. /// 鼠标焦点离开时
  547. /// </summary>
  548. /// <param name="sender"></param>
  549. /// <param name="e"></param>
  550. void cmbtreev_Leave(object sender, EventArgs e)
  551. {
  552. if (this.cmbtreev.Visible)
  553. {
  554. if (this.cmbtreev.Text.Trim() == "休息")
  555. {
  556. string StrTime = "";
  557. if (this.chkWeekMode.Checked == true)
  558. { StrTime = this.WeekStartDate.AddDays(this.dgvData.CurrentCell.ColumnIndex - 3).ToString("yyyy-MM-dd"); }
  559. else
  560. { StrTime = this.dtpYearMonth.StrDateValue + "-" + (this.dgvData.CurrentCell.ColumnIndex - 2).ToString("d2"); }
  561. string StrWhere = "where 工作人员='" + this.dgvData.CurrentRow.Cells["员工编号"].Value.ToString() + "' " + LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Convert(datetime,工作日期)", StrTime, StrTime) + " ";
  562. DataTable dt = new DataTable();
  563. #region 查询当安排为休息或者空时 判断该员工当天有没有安排
  564. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
  565. {
  566. dt = this.GetWorkPerson(StrWhere);
  567. });
  568. if (dt.Rows.Count > 0)
  569. { MessageBoxCustom.Show("此员工当前时间已有安排!请选择正确的排班"); }
  570. else
  571. { this.dgvData.CurrentCell.Value = this.cmbtreev.Text.Trim(); }
  572. #endregion
  573. }
  574. else
  575. {
  576. this.dgvData.CurrentCell.Value = this.cmbtreev.Text.Trim();
  577. if (this.dgvData.CurrentCell.Style.BackColor == Color.Red)
  578. { this.dgvData.CurrentCell.Style.BackColor = this.dgvData.CurrentRow.Cells[this.dgvData.CurrentCell.ColumnIndex - 1].Style.BackColor; }
  579. }
  580. this.cmbtreev.Visible = false;
  581. }
  582. }
  583. /// <summary>
  584. /// 双击单元格显示下拉框
  585. /// </summary>
  586. /// <param name="sender"></param>
  587. /// <param name="e"></param>
  588. void dgvData_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  589. {
  590. if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
  591. {
  592. if (this.dgvData.Columns[e.ColumnIndex].HeaderText.Trim() != "姓名")
  593. {
  594. DataGridViewCell cell = this.dgvData.Rows[e.RowIndex].Cells[e.ColumnIndex];
  595. Rectangle rect = this.dgvData.GetCellDisplayRectangle(cell.ColumnIndex, cell.RowIndex, true);
  596. this.cmbtreev.Size = cell.Size;
  597. this.cmbtreev.Location = new Point(rect.Location.X + this.dgvData.Location.X, rect.Location.Y + this.dgvData.Location.Y);
  598. this.cmbtreev.Visible = true;
  599. if (cell.Value != System.DBNull.Value)
  600. { this.cmbtreev.TextFindTag(cell.Value.ToString().Trim()); }
  601. this.cmbtreev.Focus();
  602. }
  603. }
  604. }
  605. /// <summary>
  606. /// 右键菜单
  607. /// </summary>
  608. /// <param name="sender"></param>
  609. /// <param name="e"></param>
  610. void dgvData_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
  611. {
  612. if (e.Button == MouseButtons.Right)
  613. {
  614. this.dgvData.conMenu.Items.Clear();
  615. ToolStripMenuItem item = null;
  616. string StrTime = "";
  617. if (this.chkWeekMode.Checked == true)
  618. { StrTime = this.WeekStartDate.AddDays(e.ColumnIndex - 3).ToString("yyyy-MM-dd"); }
  619. else
  620. { StrTime = this.dtpYearMonth.StrDateValue + "-" + (e.ColumnIndex - 2).ToString("d2"); }
  621. List<string> strList = new List<string>(this.StrTextName.Split(','));
  622. for (int i = 0; i < strList.Count; i++)
  623. {
  624. item = new ToolStripMenuItem();
  625. item.Text = strList[i].Trim();
  626. item.Tag = StrTime + "|" + e.ColumnIndex;
  627. this.dgvData.conMenu.Items.Add(item);
  628. }
  629. }
  630. }
  631. /// <summary>
  632. /// 右键菜单选择项事件
  633. /// </summary>
  634. /// <param name="sender"></param>
  635. /// <param name="e"></param>
  636. void dgvData_DataGridViewConMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  637. {
  638. ToolStripItem item = e.ClickedItem;
  639. string[] StrSplit = item.Tag.ToString().Trim().Split('|');
  640. if (item.Text.Trim() == "休息"|| item.Text.Trim() == "请假")
  641. {
  642. string StrMagess = "";
  643. string StrpPrson = "";
  644. List<string> StrList = new List<string>();
  645. for (int i = 0; i < this.dgvData.SelectedRows.Count; i++)
  646. {
  647. StrList.Add(this.dgvData.SelectedRows[i].Cells["员工编号"].Value.ToString().Trim());
  648. StrpPrson += "'" + this.dgvData.SelectedRows[i].Cells["员工编号"].Value.ToString().Trim() + "',";
  649. }
  650. Hashtable htData = new Hashtable();
  651. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
  652. {
  653. string StrWhere = "where 工作人员 in (" + StrpPrson.TrimEnd(',') + ") " + LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Convert(datetime,工作日期)", StrSplit[0].Trim(), StrSplit[0].Trim()) + " ";
  654. DataTable dt = this.GetWorkPerson(StrWhere);
  655. for (int i = 0; i < StrList.Count; i++)
  656. {
  657. DataRow[] dtRows = dt.Select("工作人员 = '" + StrList[i].Trim() + "'");
  658. if (dtRows.Length > 0)
  659. { StrMagess += LYFZ.BLL.BLL_ErpOrderView.GetUserName(StrList[i].Trim()) + ","; }
  660. else
  661. { htData[StrList[i].Trim()] = item.Text.Trim(); }
  662. }
  663. });
  664. for (int i = 0; i < this.dgvData.SelectedRows.Count; i++)
  665. {
  666. if (htData.ContainsKey(this.dgvData.SelectedRows[i].Cells["员工编号"].Value.ToString().Trim()))
  667. { this.dgvData.SelectedRows[i].Cells[Convert.ToInt32(StrSplit[1])].Value = item.Text.Trim(); }
  668. }
  669. if (StrMagess.Trim().Length > 0)
  670. { MessageBoxCustom.Show("员工:" + StrMagess + ",当前时间已有安排!请选择正确的排班"); }
  671. }
  672. else
  673. {
  674. for (int i = 0; i < this.dgvData.SelectedRows.Count; i++)
  675. {
  676. this.dgvData.SelectedRows[i].Cells[Convert.ToInt32(StrSplit[1])].Value = item.Text.Trim();
  677. if (this.dgvData.SelectedRows[i].Cells[Convert.ToInt32(StrSplit[1])].Style.BackColor == Color.Red)
  678. { this.dgvData.SelectedRows[i].Cells[Convert.ToInt32(StrSplit[1])].Style.BackColor = this.dgvData.SelectedRows[i].Cells[Convert.ToInt32(StrSplit[1]) - 1].Style.BackColor; }
  679. }
  680. }
  681. }
  682. /// <summary>
  683. /// 列表滚动条滚动事件
  684. /// </summary>
  685. /// <param name="sender"></param>
  686. /// <param name="e"></param>
  687. void dgvData_Scroll(object sender, ScrollEventArgs e)
  688. {
  689. if (this.cmbtreev.Visible)
  690. { this.cmbtreev_Leave(this, null); }
  691. }
  692. /// <summary>
  693. /// 窗体大小发生变化
  694. /// </summary>
  695. /// <param name="sender"></param>
  696. /// <param name="e"></param>
  697. void frmTimeMain_Resize(object sender, EventArgs e)
  698. {
  699. switch (this.panelClose.Location.Y)
  700. {
  701. case 1: this.flowLayoutPanel1.Height = 31; break;
  702. case 31: this.flowLayoutPanel1.Height = 62; break;
  703. }
  704. }
  705. /// <summary>
  706. /// 获取Excel数据
  707. /// </summary>
  708. /// <param name="path"></param>
  709. /// <returns></returns>
  710. DataTable FromExcel(string path)
  711. {
  712. string strConn;
  713. strConn = "provider=microsoft.jet.oledb.4.0;data source=" + path + ";extended properties=excel 8.0";
  714. OleDbConnection OleConn = new OleDbConnection(strConn);
  715. OleConn.Open();
  716. String sql = "SELECT * FROM [Sheet1$]";//改变这sql语句取你需要的
  717. OleDbDataAdapter OleDaExcel = new OleDbDataAdapter(sql, OleConn);
  718. DataSet OleDsExcle = new DataSet();
  719. OleDaExcel.Fill(OleDsExcle);
  720. OleConn.Close();
  721. return OleDsExcle.Tables[0];
  722. }
  723. /// <summary>
  724. /// 获取当前星期是今年的第几周
  725. /// </summary>
  726. void GetWeekCount()
  727. {
  728. int IntWeekCount = (this.WeekStartDate.DayOfYear / 7);
  729. DateTime d1 = new DateTime(this.WeekStartDate.Year, 1, 1);
  730. if (d1.DayOfWeek != 0)
  731. { IntWeekCount += 2; }
  732. else
  733. { IntWeekCount += 1; }
  734. this.lblWhichWeek.Text = "第" + IntWeekCount + "周";
  735. }
  736. /// <summary>
  737. /// 周查询
  738. /// </summary>
  739. void GetQueryWeekData()
  740. {
  741. string StrColumnName = "员工编号,部门,姓名";
  742. for (int i = 0; i < 7; i++)
  743. {
  744. int dd = this.WeekStartDate.AddDays(i).Day;
  745. int MM = this.WeekStartDate.AddDays(i).Month;
  746. switch (i)
  747. {
  748. case 0: StrColumnName += ",星期日\r\n" + MM + "月" + dd + "日";
  749. break;
  750. case 1: StrColumnName += ",星期一\r\n" + MM + "月" + dd + "日";
  751. break;
  752. case 2: StrColumnName += ",星期二\r\n" + MM + "月" + dd + "日";
  753. break;
  754. case 3: StrColumnName += ",星期三\r\n" + MM + "月" + dd + "日";
  755. break;
  756. case 4: StrColumnName += ",星期四\r\n" + MM + "月" + dd + "日";
  757. break;
  758. case 5: StrColumnName += ",星期五\r\n" + MM + "月" + dd + "日";
  759. break;
  760. case 6: StrColumnName += ",星期六\r\n" + MM + "月" + dd + "日";
  761. break;
  762. }
  763. }
  764. this.dgvData.DataColumns(StrColumnName, strHideField: "员工编号");
  765. this.dgvData.Columns["姓名"].Frozen = true;
  766. int IntdgvDataColumnsCount = this.dgvData.Columns.GetColumnCount(DataGridViewElementStates.Visible);
  767. int intdgvDataWidth = (this.dgvData.Width - 50) / IntdgvDataColumnsCount;
  768. for (int i = 0; i < this.dgvData.Columns.Count; i++)
  769. { this.dgvData.Columns[i].Width = intdgvDataWidth; }
  770. string companyWhere = "";
  771. ItemValue itemValue = GetCompanyDataInfo();
  772. if (!string.IsNullOrEmpty(itemValue.Value.ToString_s()))
  773. {
  774. companyWhere = itemValue.Value.ToString_s();
  775. }
  776. //if(!string.IsNullOrEmpty(((ItemValue)cbxCompanyList.SelectedItem).Value.ToString_s()))
  777. //{
  778. // companyWhere = " and User_DividedShop = '" + ((ItemValue)cbxCompanyList.SelectedItem).Value.ToString_s()+"'";
  779. //}
  780. DataSet dtSet = new DataSet();
  781. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
  782. {
  783. string ExecuteSql = "select Dt_Name,User_EmployeeID,User_Name from tb_ErpUser Left Join tb_ErpDepartment on tb_ErpDepartment.ID = User_Department where User_Status='在职' And User_Account <> 'admin' " + companyWhere + " order by tb_ErpDepartment.ID;";
  784. ExecuteSql += "select User_ID,fixed,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(time)) AS time from loninbansets where time >= '" + this.WeekStartDate.ToString("yyyy-MM-dd 00:00:00") + "' and time <= '" + this.WeekEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "' order by time;";
  785. dtSet = orbll.GetView_Custom(ExecuteSql);
  786. });
  787. DataTable da = dtSet.Tables["ds"];
  788. DataTable dt = dtSet.Tables["ds1"];
  789. for (int i = 0; i < da.Rows.Count; i++)
  790. {
  791. DataGridViewRow dgvr = new DataGridViewRow();
  792. DataGridViewCell cell = null;
  793. cell = new DataGridViewTextBoxCell();
  794. cell.Value = da.Rows[i]["User_EmployeeID"].ToString().Trim();
  795. dgvr.Cells.Add(cell);
  796. cell = new DataGridViewTextBoxCell();
  797. cell.Value = da.Rows[i]["Dt_Name"].ToString().Trim();
  798. dgvr.Cells.Add(cell);
  799. cell = new DataGridViewTextBoxCell();
  800. cell.Value = da.Rows[i]["User_Name"].ToString().Trim();
  801. dgvr.Cells.Add(cell);
  802. for (int j = 3; j < this.dgvData.Columns.Count; j++)
  803. {
  804. cell = new DataGridViewTextBoxCell();
  805. cell.Value = "";
  806. DataRow[] dtRow = dt.Select("user_id = '" + da.Rows[i]["User_EmployeeID"].ToString().Trim() + "' And time = '" + this.WeekStartDate.AddDays(j - 3).ToString("yyyy-MM-dd") + "'");
  807. if (dtRow.Length > 0)
  808. {
  809. if (!string.IsNullOrEmpty(dtRow[0]["fixed"].ToString()))
  810. { cell.Value = dtRow[0]["fixed"]; }
  811. }
  812. dgvr.Cells.Add(cell);
  813. }
  814. this.dgvData.Rows.Add(dgvr);
  815. }
  816. this.dgvData.ClearSelection();
  817. }
  818. ItemValue GetCompanyDataInfo()
  819. {
  820. ItemValue itemValue = new ItemValue("","");
  821. if (this.cbxCompanyList.Tag != null && this.cbxCompanyList.TreeView.SelectedNode != null)
  822. {
  823. string dataValue = this.cbxCompanyList.Tag.ToString();
  824. string dataType = this.cbxCompanyList.StrGetName.Trim();
  825. if (dataType.Length > 0)
  826. {
  827. switch (dataType.ToLower())
  828. {
  829. case "storename":
  830. itemValue.Value = "and User_DividedShop = '" + dataValue + "'";
  831. break;
  832. case "department":
  833. itemValue.Value = "and User_Department = '" + dataValue + "'";
  834. break;
  835. case "user":
  836. itemValue.Value = "and User_EmployeeID = '" + dataValue + "'";
  837. break;
  838. }
  839. }
  840. }
  841. return itemValue;
  842. }
  843. /// <summary>
  844. /// 月查询
  845. /// </summary>
  846. void GetQueryMonthData()
  847. {
  848. string companyWhere = "";
  849. ItemValue itemValue = GetCompanyDataInfo();
  850. if(!string.IsNullOrEmpty(itemValue.Value.ToString_s()))
  851. {
  852. companyWhere = itemValue.Value.ToString_s();
  853. }
  854. int yyyy = Convert.ToInt32(this.dtpYearMonth.StrYear);
  855. int MM = Convert.ToInt32(this.dtpYearMonth.StrMonth);
  856. DataSet dtSet = new DataSet();
  857. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
  858. {
  859. string ExecuteSql = "select Dt_Name,User_EmployeeID,User_Name from tb_ErpUser Left Join tb_ErpDepartment on tb_ErpDepartment.ID = User_Department where User_Status='在职' And User_Account <> 'admin' "+ companyWhere + " order by tb_ErpDepartment.ID;";
  860. ExecuteSql += "select User_ID,fixed,time from loninbansets where datename(yyyy,Time)='" + yyyy + "' and datename(MM,Time)='" + MM.ToString("d2") + "';";
  861. dtSet = orbll.GetView_Custom(ExecuteSql);
  862. });
  863. DataTable da = dtSet.Tables["ds"];
  864. DataTable dt = dtSet.Tables["ds1"];
  865. this.dgvData.Rows.Clear();
  866. this.dgvData.Columns.Clear();
  867. string StrColumnName = "员工编号,部门,姓名";
  868. int intDsy = Convert.ToInt32(Convert.ToDateTime(this.dtpYearMonth.StrDateValue.Trim() + "-01").AddMonths(1).AddSeconds(-1).ToString("dd"));
  869. for (int i = 0; i < intDsy; i++)
  870. {
  871. StrColumnName += "," + (i + 1) + "日" + Environment.NewLine + Convert.ToDateTime(this.dtpYearMonth.StrDateValue + "-01").AddDays(i).ToString("dddd") + "";
  872. }
  873. this.dgvData.DataColumns(StrColumnName, strHideField: "员工编号");
  874. this.dgvData.Columns["姓名"].Frozen = true;
  875. for (int i = 0; i < this.dgvData.Columns.Count; i++)
  876. {
  877. switch (this.dgvData.Columns[i].Name.Trim())
  878. {
  879. case "姓名":
  880. this.dgvData.Columns[i].Width = 80;
  881. break;
  882. default:
  883. this.dgvData.Columns[i].Width = 80;
  884. break;
  885. }
  886. }
  887. for (int i = 0; i < da.Rows.Count; i++)
  888. {
  889. DataGridViewRow dgvr = new DataGridViewRow();
  890. DataGridViewCell cell = null;
  891. for (int j = 0; j < dgvData.Columns.Count; j++)
  892. {
  893. cell = new DataGridViewTextBoxCell();
  894. switch (j)
  895. {
  896. case 0:
  897. cell.Value = da.Rows[i]["User_EmployeeID"];
  898. break;
  899. case 1:
  900. cell.Value = da.Rows[i]["Dt_Name"].ToString().Trim();
  901. break;
  902. case 2:
  903. cell.Value = da.Rows[i]["User_Name"];
  904. break;
  905. default:
  906. cell.Value = "";
  907. DataRow[] dtRow = dt.Select("user_id='" + da.Rows[i]["User_EmployeeID"] + "' And time = '" + Convert.ToDateTime((this.dtpYearMonth.StrDateValue + "-" + (j - 2).ToString("d2"))) + "'");
  908. if (dtRow.Length > 0)
  909. {
  910. if (!string.IsNullOrEmpty(dtRow[0]["fixed"].ToString()))
  911. { cell.Value = dtRow[0]["fixed"]; }
  912. }
  913. break;
  914. }
  915. dgvr.Cells.Add(cell);
  916. }
  917. this.dgvData.Rows.Add(dgvr);
  918. }
  919. this.dgvData.ClearSelection();
  920. }
  921. /// <summary>
  922. /// 把空数据转换成SQL的空字符
  923. /// </summary>
  924. /// <param name="obj"></param>
  925. /// <returns></returns>
  926. string SqlNull(object obj)
  927. {
  928. if (obj == null)
  929. return "";
  930. return obj.ToString().Trim();
  931. }
  932. }
  933. }