SetCameraTemplate.cs 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. using LYFZ.BLL;
  2. using LYFZ.ComponentLibrary;
  3. using LYFZ.Model;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Windows.Forms;
  12. namespace LYFZ.Software.MainBusiness.NewCameraControlBook
  13. {
  14. public class SetCameraTemplate:LYFZ.Software.NewCameraControlBook.SetCameraTemplate
  15. {
  16. PanelToDataTableView PanelDataView = null;
  17. LYFZ.Software.MainBusiness.EnumPermissions.BusinessType CurrentBusinessType = EnumPermissions.BusinessType.旗舰版;
  18. public SetCameraTemplate()
  19. {
  20. CurrentBusinessType = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetBusinessType();
  21. if (CurrentBusinessType == EnumPermissions.BusinessType.婚纱版)
  22. {
  23. this.rdoHospitalClient.Hide();
  24. }
  25. else {
  26. this.rdoHospitalClient.Show();
  27. }
  28. this.dateTimePickerStar.Value = SDateTime.Now;
  29. PanelDataView = new PanelToDataTableView(this.plTbleContainer);
  30. PanelDataView.EventCell_Click += PanelDataView_EventCell_Click;
  31. PanelDataView.EventCell_DoubleClick += PanelDataView_EventCell_DoubleClick;
  32. PanelDataView.EventCell_MouseEnter += PanelDataView_EventCell_MouseEnter;
  33. PanelDataView.EventCellThumbtack_MouseEnter += PanelDataView_EventCellThumbtack_MouseEnter;
  34. PanelDataView.EventCellThumbtack_DoubleClick += PanelDataView_EventCellThumbtack_DoubleClick;
  35. this.cmenuCameraBook.ItemClicked += CmenuCameraBook_ItemClicked;
  36. this.Shown += SetCameraTemplate_Shown;
  37. this.Load += SetCameraTemplate_Load;
  38. this.lkBeforeDay.Click += BtnBeforeDay_Click;
  39. this.lkAfterDay.Click += BtnAfterDay_Click;
  40. this.lkNearlyOneWeek.Click += BtnNearlyOneWeek_Click;
  41. this.dateTimePickerStar.ValueChanged += DateTimePickerStar_ValueChanged;
  42. this.btnExportTemplate.Click += BtnExportTemplate_Click;
  43. this.btnImportTemplate.Click += BtnImportTemplate_Click;
  44. this.btnDellTle.Click += BtnDellTle_Click;
  45. this.SizeChanged += SetCameraTemplate_SizeChanged;
  46. this.RegisteredRadioButtonEvent();
  47. this.btnDelError.Click += BtnDelError_Click;
  48. }
  49. private void BtnDelError_Click(object sender, EventArgs e)
  50. {
  51. if (LYFZ.DAL.CameraControlTemplate.DelErrorTemplate())
  52. {
  53. this.LoadCameraControlTemplate();
  54. this.BindPanelDataView();
  55. MessageBoxCustom.Show("清除成功");
  56. }
  57. else {
  58. MessageBoxCustom.Show("清除失败");
  59. }
  60. }
  61. private bool whetherUpdate = false;
  62. private void BtnDellTle_Click(object sender, EventArgs e)
  63. {
  64. if (MessageBoxCustom.Show("执行清空档期后将不能恢复,是否要继续清空当前档期设置?") != DialogResult.OK)
  65. {
  66. return;
  67. }
  68. List<Model.CameraControlTemplate> delList = new List<Model.CameraControlTemplate>();
  69. bool isNoDell = false;
  70. foreach (PDataRow row in this.PanelDataView.DataRowList)
  71. {
  72. Model.CameraControlTemplate cameraTemplate = (Model.CameraControlTemplate)row.Tag;
  73. if (cameraTemplate.TimeTemplateData.TimeTemplateDataList.Any(t => t.ReservationTime.IsEnable == 0 || !String.IsNullOrWhiteSpace(t.ReservationTime.OrderNumber)))
  74. {
  75. isNoDell = true;
  76. }
  77. else {
  78. delList.Add(cameraTemplate);
  79. }
  80. }
  81. if (delList.Count>0)
  82. {
  83. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, BackgroundWorker backgroundWorker)
  84. {
  85. List<long> longIds = new List<long>();
  86. foreach (Model.CameraControlTemplate row in delList)
  87. {
  88. longIds.Add(row.ID);
  89. }
  90. cameraTemplateBll.DeleteList(String.Join(",", longIds));
  91. });
  92. this.LoadCameraControlTemplate();
  93. this.BindPanelDataView();
  94. this.whetherUpdate = true;
  95. }
  96. if(isNoDell)
  97. {
  98. MessageBoxCustom.Show("为了避免误操作\r\n档期中有被安排过客人或有被设置为禁用的档期时不可清空");
  99. }
  100. }
  101. /// <summary>
  102. /// 导入模板
  103. /// </summary>
  104. /// <param name="sender"></param>
  105. /// <param name="e"></param>
  106. private void BtnImportTemplate_Click(object sender, EventArgs e)
  107. {
  108. OpenFileDialog ImportRoleDlg = new OpenFileDialog();
  109. ImportRoleDlg.Filter = "档期模板|*.tle";
  110. if (ImportRoleDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  111. {
  112. try
  113. {
  114. CameraType cameraType = SetCameraTemplate.GetCameraType(this.flowLayoutPanel3.Controls);
  115. string ImportRoleFileName = ImportRoleDlg.FileName;
  116. if (System.IO.File.Exists(ImportRoleFileName))
  117. {
  118. dynamic ImportDataList =Newtonsoft.Json.JsonConvert.DeserializeObject(System.IO.File.ReadAllText(ImportRoleFileName, Encoding.UTF8));
  119. if (Convert.ToInt32(ImportDataList.TleCameraType)!=(int)cameraType)
  120. {
  121. MessageBoxCustom.Show("选择的档期模板不是当前类型的模板数据,请重新选择!");
  122. return;
  123. }
  124. bool isSaveOk = true;
  125. List<Model.CameraControlTemplate> templateList = new List<Model.CameraControlTemplate>();
  126. if (ImportDataList.DataList.Count > 0)
  127. {
  128. foreach (dynamic iData in ImportDataList.DataList)
  129. {
  130. try
  131. {
  132. string WeekName = iData.WeekName;
  133. List<ComponentLibrary.PDataRow> dataRowList = this.PanelDataView.DataRowList.FindAll(r => r.DataColumnList[0].Tag.ToString() == WeekName);
  134. if (iData.ValueList.Count > 0)
  135. {
  136. foreach (dynamic vData in iData.ValueList)
  137. {
  138. int orderType = Convert.ToInt32(vData.orderType);
  139. PDataRow dataRow = dataRowList.Find(r => ((Model.CameraControlTemplate)r.Tag).OrderType == orderType);
  140. if (dataRow != null)
  141. {
  142. Model.CameraControlTemplate template = (Model.CameraControlTemplate)dataRow.Tag;
  143. List<CameraTimeTemplate> tempList = template.TimeTemplateData.TimeTemplateDataList.FindAll(t => t.ReservationTime.IsEnable == 0 || !String.IsNullOrWhiteSpace(t.ReservationTime.OrderNumber));
  144. template.TimeTemplateData.TimeTemplateDataList.Clear();
  145. string[] values = vData.values.ToString().Split(',');
  146. foreach (string timeValue in values)
  147. {
  148. if (!String.IsNullOrWhiteSpace(timeValue))
  149. {
  150. if (tempList.Any(t => t.CameraTime == timeValue))
  151. {
  152. CameraTimeTemplate cameraTime = tempList.Find(t => t.CameraTime == timeValue);
  153. template.TimeTemplateData.TimeTemplateDataList.Add(cameraTime);
  154. tempList.Remove(cameraTime);
  155. }
  156. else
  157. {
  158. template.TimeTemplateData.TimeTemplateDataList.Add(new CameraTimeTemplate { ID = LYFZ.WinAPI.CustomPublicMethod.GenerateId(), CameraTime = timeValue, DayTemplate = template });
  159. }
  160. }
  161. }
  162. template.TimeTemplateData.TimeTemplateDataList.AddRange(tempList);
  163. template.TimeTemplateData.TimeTemplateDataList = template.TimeTemplateData.TimeTemplateDataList.OrderBy(t => t.CameraTime).ToList();
  164. if (template.ID > 0)
  165. {
  166. template.UpdateDateTime = SDateTime.Now.ToJavaScriptTimeStamp();
  167. template.UpdatePeople = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  168. }
  169. else
  170. {
  171. template.CreateDateTime = SDateTime.Now.ToJavaScriptTimeStamp();
  172. template.CreatePeople = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  173. template.UpdateDateTime = SDateTime.Now.ToJavaScriptTimeStamp();
  174. template.UpdatePeople = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  175. }
  176. if (template.TimeTemplateData.TimeTemplateDataList.Count > 0)
  177. {
  178. templateList.Add(template);
  179. }
  180. }
  181. }
  182. }
  183. }
  184. catch (Exception ex)
  185. {
  186. isSaveOk = false;
  187. MessageBoxCustom.Show("档期模板导入失败:" + ex.Message);
  188. break;
  189. }
  190. }
  191. }
  192. if (isSaveOk)
  193. {
  194. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, BackgroundWorker backgroundWorker)
  195. {
  196. backgroundWorker.ReportProgress(0, "正在导入档期模板,请稍等...");
  197. foreach (Model.CameraControlTemplate template in templateList)
  198. {
  199. backgroundWorker.ReportProgress(0, String.Format("正在导入 {0}-{1} 档期模板,请稍等..."
  200. , template.CameraDateTime.JavaScriptTimeStampToDateTime().ToYYYY_MM_dd(), ((CameraOrderType)template.OrderType).ToString()));
  201. if (template.ID > 0)
  202. {
  203. if (!cameraTemplateBll.Update(template))
  204. {
  205. isSaveOk = false;
  206. break;
  207. }
  208. }
  209. else
  210. {
  211. template.ID = LYFZ.WinAPI.CustomPublicMethod.GenerateId();
  212. if (cameraTemplateBll.Add(template))
  213. {
  214. this.CameraControlTemplateList.Add(template);
  215. }
  216. else
  217. {
  218. isSaveOk = false;
  219. break;
  220. }
  221. }
  222. }
  223. });
  224. }
  225. if (isSaveOk)
  226. {
  227. // LYFZ.BLL.BLL_ErpSystemLogs.WriteSystemLog("", LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID, LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name);
  228. MessageBoxCustom.Show("档期模板导入成功");
  229. this.LoadCameraControlTemplate();
  230. this.BindPanelDataView();
  231. this.whetherUpdate = true;
  232. }
  233. else
  234. {
  235. MessageBoxCustom.Show("档期模板导入失败,请重启软件后重试");
  236. }
  237. }
  238. else
  239. {
  240. MessageBoxCustom.Show("选择的档期模板文件不存在");
  241. }
  242. }
  243. catch (Exception ex)
  244. {
  245. MessageBoxCustom.Show("档期模板导入失败:" + ex.Message);
  246. }
  247. }
  248. }
  249. /// <summary>
  250. /// 导出模板
  251. /// </summary>
  252. /// <param name="sender"></param>
  253. /// <param name="e"></param>
  254. private void BtnExportTemplate_Click(object sender, EventArgs e)
  255. {
  256. SaveFileDialog ExportRoleDlg = new SaveFileDialog();
  257. ExportRoleDlg.Filter = "档期模板|*.tle";
  258. CameraType cameraType = SetCameraTemplate.GetCameraType(this.flowLayoutPanel3.Controls);
  259. ExportRoleDlg.FileName =String.Format("{0}_{1}_档期模板_{2}" , GetCurrentStoreInfo().DividedShop_Name, cameraType.ToString(), SDateTime.Now.ToString("yyyy-MM-dd"));
  260. if (ExportRoleDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  261. {
  262. try
  263. {
  264. string ImportRoleFileName = LYFZ.WinAPI.CustomPublicMethod.GetFullDirectoryPath(System.IO.Path.GetDirectoryName(ExportRoleDlg.FileName))
  265. + System.IO.Path.GetFileNameWithoutExtension(ExportRoleDlg.FileName) + ".tle";
  266. List<object> tleDataList = new List<object>();
  267. for (int i = 0; i < weekNames.Length; i++)
  268. {
  269. List< ComponentLibrary.PDataRow > rowList= this.PanelDataView.DataRowList.FindAll(r=>r.DataColumnList[0].Tag.ToString()== weekNames[i]);
  270. List<object> valueList = new List<object>();
  271. foreach (PDataRow row in rowList)
  272. {
  273. Model.CameraControlTemplate cameraTemplate = (Model.CameraControlTemplate)row.Tag;
  274. valueList.Add(new {
  275. orderType = cameraTemplate.OrderType
  276. ,values= cameraTemplate.TimeTemplateData.ToTimeValueString()
  277. });
  278. }
  279. tleDataList.Add(new
  280. {
  281. WeekName = weekNames[i]
  282. ,
  283. ValueList = valueList
  284. });
  285. }
  286. dynamic tleData = new {
  287. TleCameraType= cameraType
  288. ,
  289. DataList= tleDataList
  290. };
  291. string ExportRoleData = Newtonsoft.Json.JsonConvert.SerializeObject(tleData);
  292. System.IO.File.WriteAllText(ImportRoleFileName, ExportRoleData.Trim('|'), Encoding.UTF8);
  293. MessageBoxCustom.Show("档期模板数据导出成功");
  294. }
  295. catch (Exception ex)
  296. {
  297. MessageBoxCustom.Show("档期模板数据导出失败:" + ex.Message);
  298. }
  299. }
  300. }
  301. void RegisteredRadioButtonEvent()
  302. {
  303. foreach (Control con in this.flowLayoutPanel3.Controls)
  304. {
  305. if (con.GetType() == typeof(LYFZ.ComponentLibrary.RadioButtonEx))
  306. {
  307. LYFZ.ComponentLibrary.RadioButtonEx rdo = (LYFZ.ComponentLibrary.RadioButtonEx)con;
  308. rdo.Click += Rdo_Click;
  309. }
  310. }
  311. }
  312. private void Rdo_Click(object sender, EventArgs e)
  313. {
  314. this.LoadCameraControlTemplate();
  315. this.BindPanelDataView();
  316. }
  317. private void SetCameraTemplate_SizeChanged(object sender, EventArgs e)
  318. {
  319. foreach (PDataColumn column in this.PanelDataView.HeadColumnRow.DataColumnList)
  320. {
  321. column.Width = GetTitleDataColumnWidth(column.Text);
  322. }
  323. this.PanelDataView.RefreshTableView();
  324. }
  325. LYFZ.BLL.CameraControlTemplate cameraTemplateBll = new BLL.CameraControlTemplate();
  326. LYFZ.DAL.CameraControlTemplate cameraTemplateDal = new DAL.CameraControlTemplate();
  327. LYFZ.BLL.ThumbtackRecord thumbtackBll = new BLL.ThumbtackRecord();
  328. private void SetCameraTemplate_Load(object sender, EventArgs e)
  329. {
  330. if (LYFZ.BLL.BLL_ErpUser.IsAdministrator())
  331. {
  332. this.btnDelError.Show();
  333. }
  334. else {
  335. this.btnDelError.Hide();
  336. }
  337. }
  338. private void SetCameraTemplate_Shown(object sender, EventArgs e)
  339. {
  340. this.lbShopName.Text = this.GetCurrentStoreInfo().DividedShop_Name;
  341. this.LoadCameraControlTemplate();
  342. BindPanelDataView();
  343. }
  344. List<LYFZ.Model.CameraControlTemplate> CameraControlTemplateList = new List<Model.CameraControlTemplate>();
  345. List<LYFZ.Model.ThumbtackRecord> thumbtackRecordList = new List<Model.ThumbtackRecord>();
  346. /// <summary>
  347. /// 加载模板数据
  348. /// </summary>
  349. void LoadCameraControlTemplate()
  350. {
  351. CameraType cameraType = SetCameraTemplate.GetCameraType(this.flowLayoutPanel3.Controls);
  352. LoadCameraControlTemplate(DateStart, DateEnd,(int)cameraType, GetCurrentStoreInfo().DividedShop);
  353. }
  354. DateTime DateStart
  355. {
  356. get {
  357. DateTime selectDate = this.dateTimePickerStar.Value;
  358. int dayOfWeekIndex = GetDayOfWeekIndex(selectDate.DayOfWeek);
  359. return selectDate.AddDays(-(dayOfWeekIndex - (0 + 1)));
  360. }
  361. }
  362. DateTime DateEnd
  363. {
  364. get
  365. {
  366. DateTime selectDate = this.dateTimePickerStar.Value;
  367. int dayOfWeekIndex = GetDayOfWeekIndex(selectDate.DayOfWeek);
  368. return selectDate.AddDays(-(dayOfWeekIndex - (6 + 1)));
  369. }
  370. }
  371. public bool WhetherUpdate { get => whetherUpdate; set => whetherUpdate = value; }
  372. /// <summary>
  373. /// 加载模板数据
  374. /// </summary>
  375. /// <param name="dateStart"></param>
  376. /// <param name="dateEnd"></param>
  377. void LoadCameraControlTemplate(DateTime dateStart, DateTime dateEnd, int cameraType, string shopID)
  378. {
  379. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, BackgroundWorker backgroundWorker)
  380. {
  381. this.CameraControlTemplateList = cameraTemplateBll.GetCameraControlTemplateList(dateStart, dateEnd.ToDayDateMaxTime(), cameraType, shopID);
  382. // this.thumbtackRecordList = thumbtackBll.GetThumbtackRecordList(dateStart, dateEnd);
  383. });
  384. }
  385. private void PanelDataView_EventCellThumbtack_MouseEnter(Panel viewPanel, DataEventArgs e)
  386. {
  387. this.tpsInfo.ToolTipTitle = "图钉内容预览";
  388. this.tpsInfo.Show(String.Format("{0}", e.CurrentThumbtack.ThumbtackText), this.PanelDataView, new Point(e.MousePoint.X + 10, e.MousePoint.Y), 5000);
  389. }
  390. private void PanelDataView_EventCellThumbtack_DoubleClick(Panel viewPanel, DataEventArgs e)
  391. {
  392. MessageBoxCustom.Show(e.CurrentThumbtack.ThumbtackText);
  393. }
  394. private void PanelDataView_EventCell_MouseEnter(Panel viewPanel, DataEventArgs e)
  395. {
  396. }
  397. private void PanelDataView_EventCell_DoubleClick(Panel viewPanel, DataEventArgs e)
  398. {
  399. if (e.CurrentCell.CellIndex > 0 && !e.IsHeadRow)
  400. {
  401. if (e.CrrrentRow.Tag != null)
  402. {
  403. Model.CameraControlTemplate template= (Model.CameraControlTemplate)e.CrrrentRow.Tag;
  404. AddTimeTemplate addTime = new AddTimeTemplate();
  405. addTime.CurrentDataRow = e.CrrrentRow;
  406. addTime.CameraTemplate = template;
  407. List<CameraTimeTemplate> OldTimeTemplateDataList = new List<CameraTimeTemplate>(template.TimeTemplateData.TimeTemplateDataList);
  408. if (addTime.ShowDialog() == DialogResult.OK)
  409. {
  410. bool isSave = true;
  411. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, BackgroundWorker backgroundWorker)
  412. {
  413. try
  414. {
  415. if (template.ID <= 0)
  416. {
  417. template.ID = LYFZ.WinAPI.CustomPublicMethod.GenerateId();
  418. template.CreateDateTime = SDateTime.Now.ToJavaScriptTimeStamp();
  419. template.CreatePeople = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  420. template.UpdateDateTime = SDateTime.Now.ToJavaScriptTimeStamp();
  421. template.UpdatePeople = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  422. if (template.TimeTemplateData.TimeTemplateDataList.Count > 0)
  423. {
  424. if (cameraTemplateBll.Add(template))
  425. {
  426. this.CameraControlTemplateList.Add(template);
  427. isSave = true;
  428. }
  429. else
  430. {
  431. template.ID = 0;
  432. isSave = false;
  433. }
  434. }
  435. }
  436. else
  437. {
  438. if (template.TimeTemplateData.TimeTemplateDataList.Count > 0)
  439. {
  440. template.UpdateDateTime = SDateTime.Now.ToJavaScriptTimeStamp();
  441. template.UpdatePeople = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  442. isSave = cameraTemplateBll.Update(template);
  443. }
  444. else
  445. {
  446. isSave = cameraTemplateBll.Delete(template);
  447. }
  448. }
  449. }
  450. catch (Exception ex){
  451. MessageBoxCustom.Show("保存模板失败:"+ ex.Message);
  452. }
  453. });
  454. if (isSave)
  455. {
  456. this.LoadCameraControlTemplate();
  457. this.BindPanelDataView();
  458. this.whetherUpdate = true;
  459. }
  460. else {
  461. template.TimeTemplateData.TimeTemplateDataList.Clear();
  462. template.TimeTemplateData.TimeTemplateDataList.AddRange(OldTimeTemplateDataList);
  463. MessageBoxCustom.Show("模板数据保存失败,请重新启动软件后重试");
  464. }
  465. }
  466. }
  467. else {
  468. MessageBoxCustom.Show("模板数据不正确");
  469. }
  470. }
  471. }
  472. private void PanelDataView_EventCell_Click(Panel viewPanel, DataEventArgs e)
  473. {
  474. this.HideTpsInfo();
  475. /* if (e.Button == MouseButtons.Right)
  476. {
  477. if (!e.IsHeadRow)
  478. {
  479. if (e.CurrentCell.CellIndex > 2)
  480. {
  481. this.cmenuCameraBook.Tag = e.CrrrentRow;
  482. this.cmenuCameraBook.Show(this.PanelDataView, e.MousePoint);
  483. }
  484. }
  485. }*/
  486. }
  487. /// <summary>
  488. /// 单击右键菜单时
  489. /// </summary>
  490. /// <param name="sender"></param>
  491. /// <param name="e"></param>
  492. private void CmenuCameraBook_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  493. {
  494. /* PDataRow cRow = (PDataRow)this.cmenuCameraBook.Tag;
  495. Model.CameraControlTemplate template = (Model.CameraControlTemplate)cRow.Tag;
  496. //MessageBoxCustom.Show(String.Join(",", template.TimeTemplateData.TimeTemplateDataList));
  497. switch (e.ClickedItem.Text)
  498. {
  499. case "编辑档期":
  500. this.PanelDataView_EventCell_DoubleClick(this.PanelDataView, new DataEventArgs {
  501. CrrrentRow = cRow
  502. , CurrentCell = cRow.DataColumnList[3]
  503. });
  504. break;
  505. case "清除档期":
  506. if (template.TimeTemplateData.TimeTemplateDataList.Any(t => t.ReservationTime.IsEnable == 0 || !String.IsNullOrWhiteSpace(t.ReservationTime.OrderNumber)))
  507. {
  508. MessageBoxCustom.Show("为了避免误操作\r\n档期中已被预约或被设置为禁用的档期模板不可清除档期");
  509. return;
  510. }
  511. break;
  512. }*/
  513. }
  514. void HideTpsInfo()
  515. {
  516. this.tpsInfo.Hide(this.PanelDataView);
  517. }
  518. public static int GetDayOfWeekIndex(DayOfWeek dayOfWeek)
  519. {
  520. int weekIndex = (int)dayOfWeek;
  521. if (weekIndex == 0)
  522. {
  523. weekIndex = 7;
  524. }
  525. return weekIndex;
  526. }
  527. string[] titleNames = new string[4] { "设置日期", "订单类别", "档期数", "档期时间" };
  528. string[] weekNames = new string[7] { "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日" };
  529. /// <summary>
  530. /// 绑定数据
  531. /// </summary>
  532. void BindPanelDataView()
  533. {
  534. this.PanelDataView.DataRowList.Clear();
  535. PanelDataView.HeadColumnRow.DataColumnList.Clear();
  536. PanelDataView.HeadColumnRow.Height = 32;
  537. for (int i = 0; i < titleNames.Length; i++)
  538. {
  539. PanelDataView.HeadColumnRow.DataColumnList.Add(GetNewTitleDataColumn(titleNames[i]));
  540. }
  541. CameraType cameraType = SetCameraTemplate.GetCameraType(this.flowLayoutPanel3.Controls);
  542. List<CameraOrderType> cameraOrderTypeList =SetCameraTemplate.GetCameraOrderTypeList(cameraType, GetCurrentStoreBusinessType());
  543. DateTime selectDate = this.dateTimePickerStar.Value;
  544. int dayOfWeekIndex = GetDayOfWeekIndex(selectDate.DayOfWeek);
  545. for (int i = 0; i < weekNames.Length; i++)
  546. {
  547. this.AddCameraDate(weekNames[i], selectDate.AddDays(-(dayOfWeekIndex- (i+1))), cameraOrderTypeList, cameraType);
  548. }
  549. PanelDataView.RefreshTableView();
  550. }
  551. public static CameraType GetCameraType(Control.ControlCollection controls)
  552. {
  553. CameraType cameraType = CameraType.拍照客人;
  554. foreach (Control con in controls)
  555. {
  556. if (con.GetType() == typeof(LYFZ.ComponentLibrary.RadioButtonEx))
  557. {
  558. LYFZ.ComponentLibrary.RadioButtonEx rdo = (LYFZ.ComponentLibrary.RadioButtonEx)con;
  559. if (rdo.Checked)
  560. {
  561. cameraType = (CameraType)Enum.Parse(typeof(CameraType), rdo.Text);
  562. break;
  563. }
  564. }
  565. }
  566. return cameraType;
  567. }
  568. public static List<CameraOrderType> GetCameraOrderTypeList(CameraType cameraType, EnumPermissions.BusinessType businessType)
  569. {
  570. List<CameraOrderType> cameraOrderTypes = new List<CameraOrderType>();
  571. switch (cameraType)
  572. {
  573. case CameraType.拍照客人:
  574. case CameraType.选片客人:
  575. case CameraType.看版客人:
  576. case CameraType.取件客人:
  577. case CameraType.选衣客人:
  578. case CameraType.服务客人:
  579. if (businessType != EnumPermissions.BusinessType.儿童版)
  580. {
  581. cameraOrderTypes.Add(CameraOrderType.婚纱订单);
  582. }
  583. if (businessType != EnumPermissions.BusinessType.婚纱版)
  584. {
  585. cameraOrderTypes.Add(CameraOrderType.儿童订单);
  586. }
  587. cameraOrderTypes.Add(CameraOrderType.写真订单);
  588. break;
  589. case CameraType.爱婴上门:
  590. cameraOrderTypes.Add(CameraOrderType.爱婴跟踪);
  591. break;
  592. }
  593. if (cameraType == CameraType.选衣客人)
  594. {
  595. cameraOrderTypes.Add(CameraOrderType.礼服租售);
  596. if (businessType != EnumPermissions.BusinessType.儿童版)
  597. {
  598. cameraOrderTypes.Add(CameraOrderType.婚庆订单);
  599. }
  600. }
  601. if (cameraType == CameraType.取件客人||cameraType== CameraType.服务客人)
  602. {
  603. cameraOrderTypes.Add(CameraOrderType.服务订单);
  604. if (businessType != EnumPermissions.BusinessType.儿童版)
  605. {
  606. cameraOrderTypes.Add(CameraOrderType.婚庆订单);
  607. }
  608. }
  609. return cameraOrderTypes;
  610. }
  611. void AddCameraDate(string weekName, DateTime dayDate, List<CameraOrderType> cameraOrderTypeList, CameraType cameraType)
  612. {
  613. for (int i = 0; i < cameraOrderTypeList.Count; i++)
  614. {
  615. int crossRowCount = 1;
  616. if (i == 0)
  617. {
  618. crossRowCount = cameraOrderTypeList.Count;
  619. }
  620. ComponentLibrary.PDataRow row = GetNewDataRow(weekName, dayDate, crossRowCount, cameraOrderTypeList[i], cameraType);
  621. if (cameraOrderTypeList.Count == 1)
  622. {
  623. row.Height = 64;
  624. }
  625. PanelDataView.DataRowList.Add(row);
  626. }
  627. }
  628. ComponentLibrary.PDataRow GetNewDataRow(string weekName, DateTime dayDate, int crossRowCount, CameraOrderType cameraOrderType, CameraType cameraType)
  629. {
  630. ComponentLibrary.PDataRow row = new PDataRow();
  631. string LunarCalendarDayTime = Command.Command_CalendarTurnLunar.GetChineseDateTimeToNoYear(dayDate);
  632. Model.CameraControlTemplate cameraTemplate = this.GetCameraControlTemplate(dayDate, cameraOrderType, cameraType);
  633. ComponentLibrary.PDataColumn cell0 = new ComponentLibrary.PDataColumn
  634. {
  635. Text = String.Format("{0}\r\n{1}\r\n{2}", weekName, dayDate.ToString("yyyy-MM-dd"), LunarCalendarDayTime)
  636. ,
  637. CrossRow = crossRowCount
  638. , DateTimeTag = dayDate
  639. ,Tag= weekName
  640. };
  641. ComponentLibrary.PDataColumn cell1 = new ComponentLibrary.PDataColumn
  642. {
  643. Text = String.Format("{0}", cameraOrderType.ToString())
  644. ,
  645. Tag = (int)cameraOrderType
  646. };
  647. ComponentLibrary.PDataColumn cell2 = new ComponentLibrary.PDataColumn
  648. {
  649. Text = String.Format("{0}", cameraTemplate.TimeTemplateData.TimeTemplateDataList.Count)
  650. };
  651. ComponentLibrary.PDataColumn cell3 = new ComponentLibrary.PDataColumn
  652. {
  653. Text = String.Format("{0}", cameraTemplate.TimeTemplateData.ToTimeTextString())
  654. ,TextAlignment= StringAlignment.Near
  655. };
  656. row.DataColumnList.AddRange(new ComponentLibrary.PDataColumn[] { cell0, cell1, cell2, cell3 });
  657. row.Tag = cameraTemplate;
  658. return row;
  659. }
  660. Model.CameraControlTemplate GetCameraControlTemplate(DateTime date, CameraOrderType cameraOrderType, CameraType cameraType)
  661. {
  662. Model.CameraControlTemplate cameraTemplate= this.CameraControlTemplateList.Find(t=>t.CameraDateTime==date.ToYYYYMMddDate().ToJavaScriptTimeStamp()&&t.CameraType== (int)cameraType && t.OrderType==(int)cameraOrderType);
  663. if (cameraTemplate == null)
  664. {
  665. cameraTemplate = new Model.CameraControlTemplate {
  666. CameraType= (int)cameraType
  667. ,OrderType= (int)cameraOrderType
  668. ,CameraDateTime=date.ToYYYYMMddDate().ToJavaScriptTimeStamp()
  669. ,
  670. ShopID=GetCurrentStoreInfo().DividedShop
  671. };
  672. }
  673. return cameraTemplate;
  674. }
  675. ComponentLibrary.PDataColumn GetNewTitleDataColumn(string titleName)
  676. {
  677. ComponentLibrary.PDataColumn cell = new ComponentLibrary.PDataColumn
  678. {
  679. Text = String.Format("{0}", titleName)
  680. ,
  681. Width = GetTitleDataColumnWidth(titleName)
  682. };
  683. if (titleName.Trim() == titleNames[3])
  684. {
  685. cell.TextAlignment = StringAlignment.Near;
  686. }
  687. return cell;
  688. }
  689. int GetTitleDataColumnWidth(string titleName)
  690. {
  691. int cell_width = 180;
  692. if (titleName.Trim() == titleNames[0])
  693. {
  694. cell_width = 180;
  695. }
  696. else if (titleName.Trim() == titleNames[1])
  697. {
  698. cell_width = 100;
  699. }
  700. else if (titleName.Trim() == titleNames[2])
  701. {
  702. cell_width = 80;
  703. }
  704. else if (titleName.Trim() == titleNames[3])
  705. {
  706. cell_width = this.Width - 400;
  707. if (cell_width < 480)
  708. {
  709. cell_width = 480;
  710. }
  711. }
  712. return cell_width;
  713. }
  714. #region 摄控详情时间控制
  715. bool isNowWeek = false;
  716. private void DateTimePickerStar_ValueChanged(object sender, EventArgs e)
  717. {
  718. if (!this.PanelDataView.DataRowList.Any(r => r.DataColumnList.Any(c => c.CellIndex == 0 && c.DateTimeTag.ToString("yyyy-MM-dd") == this.dateTimePickerStar.Value.ToString("yyyy-MM-dd"))))
  719. {
  720. this.LoadCameraControlTemplate();
  721. this.BindPanelDataView();
  722. }
  723. else if(isNowWeek)
  724. {
  725. isNowWeek = false;
  726. this.LoadCameraControlTemplate();
  727. this.BindPanelDataView();
  728. }
  729. }
  730. /// <summary>
  731. /// 本周
  732. /// </summary>
  733. /// <param name="sender"></param>
  734. /// <param name="e"></param>
  735. private void BtnNearlyOneWeek_Click(object sender, EventArgs e)
  736. {
  737. this.dateTimePickerStar.Value = SDateTime.Now;
  738. isNowWeek = true;
  739. }
  740. /// <summary>
  741. /// 上一周
  742. /// </summary>
  743. /// <param name="sender"></param>
  744. /// <param name="e"></param>
  745. private void BtnBeforeDay_Click(object sender, EventArgs e)
  746. {
  747. this.dateTimePickerStar.Value = this.dateTimePickerStar.Value.AddDays(-7);
  748. }
  749. /// <summary>
  750. /// 下一周
  751. /// </summary>
  752. /// <param name="sender"></param>
  753. /// <param name="e"></param>
  754. private void BtnAfterDay_Click(object sender, EventArgs e)
  755. {
  756. this.dateTimePickerStar.Value = this.dateTimePickerStar.Value.AddDays(7);
  757. }
  758. #endregion
  759. #region 门店列表处理
  760. QueryStoreInfo GetCurrentStoreInfo()
  761. {
  762. if (CurrentQueryStoreList != null&& CurrentQueryStoreList.QueryStoreInfoList.Count > 0)
  763. {
  764. return CurrentQueryStoreList.QueryStoreInfoList[0];
  765. }
  766. return new QueryStoreInfo {
  767. DividedShop = LYFZ.BLL.BLL_ErpCompanyInfo.CurrentCompanyInfoID
  768. , DividedShop_Name = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.CompanyName
  769. };
  770. }
  771. /// <summary>
  772. /// 当前要查询的门店信息集合
  773. /// </summary>
  774. public QueryStoreList CurrentQueryStoreList = null;
  775. public EnumPermissions.BusinessType GetCurrentStoreBusinessType()
  776. {
  777. if (CurrentQueryStoreList != null)
  778. {
  779. return GetStoreBusinessType(CurrentQueryStoreList);
  780. }
  781. else {
  782. return LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetBusinessType();
  783. }
  784. }
  785. public static EnumPermissions.BusinessType GetStoreBusinessType(QueryStoreList storeList)
  786. {
  787. if (storeList.QueryStoreInfoList.Count > 0)
  788. {
  789. return GetStoreBusinessType(storeList.QueryStoreInfoList[0]);
  790. }
  791. return LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetBusinessType();
  792. }
  793. public static EnumPermissions.BusinessType GetStoreBusinessType(QueryStoreInfo storeInfo)
  794. {
  795. EnumPermissions.BusinessType buType = (EnumPermissions.BusinessType)storeInfo.ShopStoreFeature.BusinessType;
  796. return buType;
  797. }
  798. #endregion
  799. }
  800. }