AddTimeTemplate.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using LYFZ.ComponentLibrary;
  6. using LYFZ.Model;
  7. namespace LYFZ.Software.MainBusiness.NewCameraControlBook
  8. {
  9. public class AddTimeTemplate : LYFZ.Software.NewCameraControlBook.AddTimeTemplate
  10. {
  11. public AddTimeTemplate()
  12. {
  13. this.Shown += AddTimeTemplate_Shown;
  14. this.btnSave.Click += BtnSave_Click;
  15. this.btnColse.Click += BtnColse_Click;
  16. this.txtTimeTemplateValue.BaseText.TextChanged += BaseText_TextChanged;
  17. this.SizeChanged += AddTimeTemplate_SizeChanged;
  18. this.lkFormatTime1.Click += LkFormatTime1_Click;
  19. this.lkFormatTime2.Click += LkFormatTime2_Click;
  20. }
  21. private void LkFormatTime1_Click(object sender, EventArgs e)
  22. {
  23. string timeString = BLL.CameraTemplateHandle.FormatTimeStirng(this.txtTimeTemplateValue.Text.Trim());
  24. this.txtTimeTemplateValue.Text = timeString.Replace(",", System.Environment.NewLine);
  25. this.BaseText_TextChanged(null,null);
  26. if (sender!=null&&!this.VerificationTimeString(timeString))
  27. {
  28. MessageBoxCustom.Show(String.Format("格式化完成,但是检测到输入的时间格式不正确"));
  29. }
  30. }
  31. private void LkFormatTime2_Click(object sender, EventArgs e)
  32. {
  33. this.txtTimeTemplateValue.Text = BLL.CameraTemplateHandle.FormatTimeStirng(this.txtTimeTemplateValue.Text.Trim());
  34. this.BaseText_TextChanged(null, null);
  35. if (sender != null && !this.VerificationTimeString(this.txtTimeTemplateValue.Text.Trim()))
  36. {
  37. MessageBoxCustom.Show(String.Format("格式化完成,但是检测到输入的时间格式不正确"));
  38. }
  39. }
  40. private void AddTimeTemplate_SizeChanged(object sender, EventArgs e)
  41. {
  42. if (this.WindowState == System.Windows.Forms.FormWindowState.Maximized)
  43. {
  44. this.LkFormatTime1_Click(null,null);
  45. }
  46. else {
  47. this.LkFormatTime2_Click(null, null);
  48. }
  49. }
  50. private void BaseText_TextChanged(object sender, EventArgs e)
  51. {
  52. string timeString = BLL.CameraTemplateHandle.FormatTimeStirng(this.txtTimeTemplateValue.Text.Trim());
  53. if (!String.IsNullOrWhiteSpace(timeString))
  54. {
  55. string[] timeList = BLL.CameraTemplateHandle.TimeStirngToSplit(timeString);
  56. this.skinLabel1.Text = String.Format("共计:{0} 个档期", timeList.Length);
  57. }
  58. }
  59. private void BtnColse_Click(object sender, EventArgs e)
  60. {
  61. this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  62. }
  63. private void BtnSave_Click(object sender, EventArgs e)
  64. {
  65. List<CameraTimeTemplate> tempList = cameraTemplate.TimeTemplateData.TimeTemplateDataList.FindAll(t => t.ReservationTime.IsEnable == 0 || !String.IsNullOrWhiteSpace(t.ReservationTime.OrderNumber));
  66. string timeString = BLL.CameraTemplateHandle.FormatTimeStirng(this.txtTimeTemplateValue.Text.Trim());
  67. if (this.VerificationTimeString(timeString))
  68. {
  69. this.txtTimeTemplateValue.Text = timeString;
  70. string[] timeList = BLL.CameraTemplateHandle.TimeStirngToSplit(timeString);
  71. if (timeList.Length > 100)
  72. {
  73. MessageBoxCustom.Show("摄控本模板档期数量最大不能超过100个");
  74. return;
  75. }
  76. cameraTemplate.TimeTemplateData.TimeTemplateDataList.Clear();
  77. foreach (string timeValue in timeList)
  78. {
  79. if (tempList.Any(t => t.CameraTime == timeValue))
  80. {
  81. CameraTimeTemplate cameraTime = tempList.Find(t => t.CameraTime == timeValue);
  82. cameraTemplate.TimeTemplateData.TimeTemplateDataList.Add(cameraTime);
  83. tempList.Remove(cameraTime);
  84. }
  85. else
  86. {
  87. cameraTemplate.TimeTemplateData.TimeTemplateDataList.Add(new CameraTimeTemplate { ID = LYFZ.WinAPI.CustomPublicMethod.GenerateId(), CameraTime = timeValue ,DayTemplate= cameraTemplate });
  88. }
  89. }
  90. cameraTemplate.TimeTemplateData.TimeTemplateDataList.AddRange(tempList);
  91. cameraTemplate.TimeTemplateData.TimeTemplateDataList = cameraTemplate.TimeTemplateData.TimeTemplateDataList.OrderBy(t => t.CameraTime).ToList();
  92. this.DialogResult = System.Windows.Forms.DialogResult.OK;
  93. }
  94. else {
  95. if (String.IsNullOrWhiteSpace(timeString))
  96. {
  97. cameraTemplate.TimeTemplateData.TimeTemplateDataList.Clear();
  98. cameraTemplate.TimeTemplateData.TimeTemplateDataList.AddRange(tempList);
  99. cameraTemplate.TimeTemplateData.TimeTemplateDataList = cameraTemplate.TimeTemplateData.TimeTemplateDataList.OrderBy(t => t.CameraTime).ToList();
  100. this.DialogResult = System.Windows.Forms.DialogResult.OK;
  101. }
  102. else
  103. {
  104. MessageBoxCustom.Show(String.Format("输入的时间格式不正确"));
  105. }
  106. }
  107. }
  108. private void AddTimeTemplate_Shown(object sender, EventArgs e)
  109. {
  110. CameraOrderType cameraOrderType = (CameraOrderType)cameraTemplate.OrderType;
  111. CameraType cameraType= (CameraType)cameraTemplate.CameraType;
  112. this.lbTibsInfo.Text= String.Format("{0}:{1} 日期:{2} 说明:已预约和被禁用的档期不可修改", cameraType.ToString(), cameraOrderType.ToString(), currentDataRow.DataColumnList[0].Text.Replace("\r\n"," "));
  113. this.txtTimeTemplateValue.Text = cameraTemplate.TimeTemplateData.ToTimeValueString();
  114. }
  115. bool VerificationTimeString(string timeString)
  116. {
  117. return BLL.CameraTemplateHandle.VerificationTimeString(timeString);
  118. }
  119. Model.CameraControlTemplate cameraTemplate = new Model.CameraControlTemplate();
  120. ComponentLibrary.PDataRow currentDataRow;
  121. /// <summary>
  122. /// 当前行
  123. /// </summary>
  124. public PDataRow CurrentDataRow { get => currentDataRow; set => currentDataRow = value; }
  125. /// <summary>
  126. /// 摄控数据
  127. /// </summary>
  128. public CameraControlTemplate CameraTemplate { get => cameraTemplate; set => cameraTemplate = value; }
  129. }
  130. }