锐腾搅拌上料功能
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

410 lines
15 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using DevExpress.XtraEditors;
  9. using System.Data.SqlClient;
  10. using ICSSoft.Frame.Data.BLL;
  11. using ICSSoft.Base.Language.Tool;
  12. using ICSSoft.Base.UserControl.MessageControl;
  13. using ICSSoft.Base.Report.Filter;
  14. using ICSSoft.Base.Config.DBHelper;
  15. using ICSSoft.Base.UserControl.FormControl;
  16. using ICSSoft.Base.ReferForm.AppReferForm;
  17. using ICSSoft.Base.Lable.PrintTool;
  18. using ICSSoft.Base.Config.AppConfig;
  19. using ICSSoft.Base.Report.GridReport;
  20. using ICSSoft.Frame.APP.Entity;
  21. using ICSSoft.Frame.Data.Entity;
  22. namespace ICSSoft.Frame.APP
  23. {
  24. public partial class FormICSOPHours : DevExpress.XtraEditors.XtraForm
  25. {
  26. private string sqltxt = "";
  27. private string sqlconn = "";
  28. String guid = AppConfig.GetGuid();
  29. private DataTable dataSource = null;
  30. //WorkPointBLL workBll = new WorkPointBLL();
  31. private static int colIndex = 6;
  32. private string[] colNames = new string[colIndex];
  33. #region 构造函数
  34. public FormICSOPHours()
  35. {
  36. InitializeComponent();
  37. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  38. this.WindowState = FormWindowState.Maximized;
  39. }
  40. #endregion
  41. #region 移动窗体
  42. private const int WM_NCHITTEST = 0x84;
  43. private const int HTCLIENT = 0x1;
  44. private const int HTCAPTION = 0x2;
  45. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  46. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  47. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  48. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  49. //重写窗体,使窗体可以不通过自带标题栏实现移动
  50. protected override void WndProc(ref Message m)
  51. {
  52. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  53. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  54. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  55. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  56. switch (m.Msg)
  57. {
  58. case WM_NCHITTEST:
  59. base.WndProc(ref m);
  60. if ((int)m.Result == HTCLIENT)
  61. m.Result = (IntPtr)HTCAPTION;
  62. return;
  63. }
  64. //拦截双击标题栏、移动窗体的系统消息
  65. if (m.Msg != 0xA3)
  66. {
  67. base.WndProc(ref m);
  68. }
  69. }
  70. #endregion
  71. #region SystemOptition
  72. /// <summary>
  73. /// 操作权限
  74. /// </summary>
  75. /// <returns></returns>
  76. public DataTable RightOfExute()
  77. {
  78. DataTable rData = new DataTable();
  79. rData.Columns.Add("BtnName");
  80. rData.Columns.Add("ActionName");
  81. //查看权限(必须有)
  82. DataRow seeRow = rData.NewRow();
  83. seeRow["BtnName"] = "see";
  84. seeRow["ActionName"] = "查看";
  85. rData.Rows.Add(seeRow);
  86. foreach (Control ctr in panelControl3.Controls)
  87. {
  88. if (ctr.Name == btnFilter.Name || ctr.Name == btnConfig.Name ||
  89. ctr.Name == btnSelect.Name || ctr.Name == btnCanSelect.Name ||
  90. ctr.Name == btnOutPut.Name ||
  91. ctr.Name == btnFalsh.Name || ctr.Name == btnExit.Name || ctr.Name == lblTitle.Name || ctr.Name == btnClose.Name)
  92. continue;
  93. DataRow dr = rData.NewRow();
  94. dr["BtnName"] = ctr.Name;
  95. dr["ActionName"] = ctr.Text;
  96. rData.Rows.Add(dr);
  97. }
  98. //List<Control> ControlList = new List<Control>();
  99. //ControlList.Add(btnConfig);
  100. //ControlList.Add(btnAdd);
  101. //ControlList.Add(btnEdit);
  102. //ControlList.Add(btnDelLable);
  103. //foreach (Control ctr in ControlList)
  104. //{
  105. // if (ctr.GetType() == typeof(SimpleButton))
  106. // {
  107. // DataRow dr = rData.NewRow();
  108. // dr["BtnName"] = ctr.Name;
  109. // dr["ActionName"] = ctr.Text;
  110. // rData.Rows.Add(dr);
  111. // }
  112. //}
  113. rData.AcceptChanges();
  114. return rData;
  115. }
  116. /// <summary>
  117. /// 数据权限
  118. /// </summary>
  119. /// <returns></returns>
  120. public DataTable RightOfData()
  121. {
  122. DataTable rData = new DataTable();
  123. rData.Columns.Add("BodyName");
  124. rData.Columns.Add("ControlName");
  125. rData.Columns.Add("ControlCaption");
  126. rData.AcceptChanges();
  127. return rData;
  128. }
  129. #endregion
  130. #region 退出
  131. private void btnClose_Click(object sender, EventArgs e)
  132. {
  133. AppConfig.CloseFormShow(this.Text);
  134. this.Close();
  135. }
  136. private void btnExit_Click(object sender, EventArgs e)
  137. {
  138. AppConfig.CloseFormShow(this.Text);
  139. this.Close();
  140. }
  141. #endregion
  142. #region 过滤
  143. private string tempTableName = "";
  144. private void btnFilter_Click(object sender, EventArgs e)
  145. {
  146. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  147. filter.OldTempTableName = tempTableName;
  148. if (filter.ShowDialog() == DialogResult.OK)
  149. {
  150. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  151. try
  152. {
  153. _wait.Show();
  154. tempTableName = filter.NewTempTableName;
  155. sqltxt = filter.SqlText;
  156. sqlconn = filter.FilterConnectString;
  157. dataSource = filter.FilterData.Tables[0];
  158. for (int i = 0; i < colIndex; i++)
  159. {
  160. dataSource.Columns[i + 1].ReadOnly = true;
  161. colNames[i] = dataSource.Columns[i + 1].ColumnName;
  162. }
  163. if (dataSource.Columns.Contains("pagerowindex"))
  164. dataSource.Columns.Remove("pagerowindex");
  165. grdDetail.DataSource = dataSource;
  166. grvDetail.BestFitColumns();
  167. _wait.Close();
  168. }
  169. catch (Exception ex)
  170. {
  171. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  172. _wait.Close();
  173. }
  174. }
  175. }
  176. #endregion
  177. #region 全选
  178. private void btnSelect_Click(object sender, EventArgs e)
  179. {
  180. for (int i = 0; i < dataSource.Rows.Count; i++)
  181. {
  182. dataSource.Rows[i][0] = true;
  183. }
  184. }
  185. #endregion
  186. #region 全消
  187. private void btnCanSelect_Click(object sender, EventArgs e)
  188. {
  189. for (int i = 0; i < dataSource.Rows.Count; i++)
  190. {
  191. dataSource.Rows[i][0] = false;
  192. }
  193. }
  194. #endregion
  195. #region 刷新
  196. private void btnFalsh_Click(object sender, EventArgs e)
  197. {
  198. if (sqlconn == null || sqlconn == "")
  199. {
  200. return;
  201. }
  202. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  203. try
  204. {
  205. _wait.Show();
  206. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  207. filter.OldTempTableName = tempTableName;
  208. //tempTableName = filter.NewTempTableName;
  209. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  210. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  211. grdDetail.DataSource = dataSource;
  212. _wait.Close();
  213. }
  214. catch (Exception ex)
  215. {
  216. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  217. _wait.Close();
  218. }
  219. }
  220. #endregion
  221. #region 列表
  222. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  223. {
  224. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  225. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  226. }
  227. #endregion
  228. #region 绑定数据源
  229. private void btnConfig_Click(object sender, EventArgs e)//绑定数据源
  230. {
  231. if (AppConfig.UserCode.ToLower() != "demo")
  232. {
  233. //ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  234. return;
  235. }
  236. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  237. fdata.ShowDialog();
  238. }
  239. #endregion
  240. #region 加载
  241. private void FormICSOPHours_Load(object sender, EventArgs e)
  242. {
  243. btnFilter_Click(sender, e);
  244. }
  245. #endregion
  246. #region 修改
  247. private void btnEdit_Click(object sender, EventArgs e)
  248. {
  249. SimpleButton btntemp = (SimpleButton)sender;
  250. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  251. {
  252. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  253. return;
  254. }
  255. try
  256. {
  257. if (dataSource == null || dataSource.Rows.Count <= 0)
  258. return;
  259. List<ICSHoursCost> infos = new List<ICSHoursCost>();
  260. for (int i = 0; i < dataSource.Rows.Count; i++)
  261. {
  262. DataRow dr = dataSource.Rows[i];
  263. if (!Convert.ToBoolean(dr["选择"]))
  264. continue;
  265. for (int j = colIndex + 1; j < dataSource.Columns.Count; j++)
  266. {
  267. ICSHoursCost info = new ICSHoursCost();
  268. info.Organization = dr[colNames[0]].ToString();
  269. info.CostCenter = dr[colNames[1]].ToString();
  270. info.Month = dr[colNames[2]].ToString();
  271. info.Hours = Convert.ToDecimal(dr[colNames[3]]);
  272. string name = dataSource.Columns[j].ColumnName;
  273. if (string.IsNullOrWhiteSpace(dr[name].ToString()))
  274. throw new Exception("选中行费用不能为空!");
  275. info.Type = name;
  276. info.Cost = Convert.ToDecimal(dr[name]);
  277. info.MUSERNAME = AppConfig.UserName;
  278. info.MUSER = AppConfig.UserCode;
  279. info.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  280. info.WorkPoint = AppConfig.WorkPointCode;
  281. infos.Add(info);
  282. }
  283. }
  284. if (infos.Count > 0)
  285. {
  286. ICSOPHoursBLL.AddList(infos, AppConfig.AppConnectString);
  287. btnFalsh_Click(null, null);
  288. }
  289. }
  290. catch (Exception ex)
  291. {
  292. //throw ex;
  293. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  294. }
  295. }
  296. #endregion
  297. #region 导出
  298. private void btnOutPut_Click(object sender, EventArgs e)
  299. {
  300. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  301. foe.ShowDialog();
  302. }
  303. #endregion
  304. //审核生效
  305. private void btnCheck_Click(object sender, EventArgs e)
  306. {
  307. SimpleButton btntemp = (SimpleButton)sender;
  308. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  309. {
  310. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  311. return;
  312. }
  313. try
  314. {
  315. if (dataSource == null || dataSource.Rows.Count <= 0)
  316. return;
  317. List<string> infos = new List<string>();
  318. for (int i = 0; i < dataSource.Rows.Count; i++)
  319. {
  320. DataRow dr = dataSource.Rows[i];
  321. if (!Convert.ToBoolean(dr["选择"]))
  322. continue;
  323. string ID = dr[colNames[0]].ToString() + dr[colNames[1]].ToString() + dr[colNames[2]].ToString();
  324. infos.Add(ID);
  325. }
  326. if (infos.Count > 0)
  327. {
  328. ICSOPHoursBLL.checkInfo(infos, true, AppConfig.AppConnectString);
  329. btnFalsh_Click(null, null);
  330. }
  331. }
  332. catch (Exception ex)
  333. {
  334. //throw ex;
  335. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  336. }
  337. }
  338. private void btnUnCheck_Click(object sender, EventArgs e)
  339. {
  340. SimpleButton btntemp = (SimpleButton)sender;
  341. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  342. {
  343. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  344. return;
  345. }
  346. try
  347. {
  348. if (dataSource == null || dataSource.Rows.Count <= 0)
  349. return;
  350. List<string> infos = new List<string>();
  351. for (int i = 0; i < dataSource.Rows.Count; i++)
  352. {
  353. DataRow dr = dataSource.Rows[i];
  354. if (!Convert.ToBoolean(dr["选择"]))
  355. continue;
  356. string ID = dr[colNames[0]].ToString() + dr[colNames[1]].ToString() + dr[colNames[2]].ToString();
  357. infos.Add(ID);
  358. }
  359. if (infos.Count > 0)
  360. {
  361. ICSOPHoursBLL.checkInfo(infos, false, AppConfig.AppConnectString);
  362. btnFalsh_Click(null, null);
  363. }
  364. }
  365. catch (Exception ex)
  366. {
  367. //throw ex;
  368. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  369. }
  370. }
  371. }
  372. }