华恒Mes鼎捷代码
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.

279 lines
10 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 ICSSoft.Base.Language.Tool;
  10. using ICSSoft.Base.UserControl.MessageControl;
  11. using ICSSoft.Frame.Data.BLL;
  12. using System.Data.SqlClient;
  13. using ICSSoft.Base.Config.AppConfig;
  14. using ICSSoft.Frame.Data.Entity;
  15. using ICSSoft.Base.Report.Filter;
  16. using ICSSoft.Base.Config.DBHelper;
  17. using ICSSoft.Base.UserControl.FormControl;
  18. using ICSSoft.Base.ReferForm.AppReferForm;
  19. namespace ICSSoft.Frame.MRP
  20. {
  21. public partial class FormICSReport : DevExpress.XtraEditors.XtraForm
  22. {
  23. private string sqltxt = "";
  24. private string sqlconn = "";
  25. String guid = AppConfig.GetGuid();
  26. private DataTable dataSource = null;
  27. #region 构造函数
  28. public FormICSReport()
  29. {
  30. InitializeComponent();
  31. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  32. this.WindowState = FormWindowState.Maximized;
  33. }
  34. #endregion
  35. #region 移动窗体
  36. private const int WM_NCHITTEST = 0x84;
  37. private const int HTCLIENT = 0x1;
  38. private const int HTCAPTION = 0x2;
  39. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  40. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  41. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  42. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  43. //重写窗体,使窗体可以不通过自带标题栏实现移动
  44. protected override void WndProc(ref Message m)
  45. {
  46. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  47. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  48. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  49. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  50. switch (m.Msg)
  51. {
  52. case WM_NCHITTEST:
  53. base.WndProc(ref m);
  54. if ((int)m.Result == HTCLIENT)
  55. m.Result = (IntPtr)HTCAPTION;
  56. return;
  57. }
  58. //拦截双击标题栏、移动窗体的系统消息
  59. if (m.Msg != 0xA3)
  60. {
  61. base.WndProc(ref m);
  62. }
  63. }
  64. #endregion
  65. #region SystemOptition
  66. /// <summary>
  67. /// 操作权限
  68. /// </summary>
  69. /// <returns></returns>
  70. public DataTable RightOfExute()
  71. {
  72. DataTable rData = new DataTable();
  73. rData.Columns.Add("BtnName");
  74. rData.Columns.Add("ActionName");
  75. //查看权限(必须有)
  76. DataRow seeRow = rData.NewRow();
  77. seeRow["BtnName"] = "see";
  78. seeRow["ActionName"] = "查看";
  79. rData.Rows.Add(seeRow);
  80. List<Control> ControlList = new List<Control>();
  81. ControlList.Add(btnOutPut);
  82. foreach (Control ctr in ControlList)
  83. {
  84. if (ctr.GetType() == typeof(SimpleButton))
  85. {
  86. DataRow dr = rData.NewRow();
  87. dr["BtnName"] = ctr.Name;
  88. dr["ActionName"] = ctr.Text;
  89. rData.Rows.Add(dr);
  90. }
  91. }
  92. rData.AcceptChanges();
  93. return rData;
  94. }
  95. /// <summary>
  96. /// 数据权限
  97. /// </summary>
  98. /// <returns></returns>
  99. public DataTable RightOfData()
  100. {
  101. DataTable rData = new DataTable();
  102. rData.Columns.Add("BodyName");
  103. rData.Columns.Add("ControlName");
  104. rData.Columns.Add("ControlCaption");
  105. rData.AcceptChanges();
  106. return rData;
  107. }
  108. #endregion
  109. #region 退出
  110. private void btnClose_Click(object sender, EventArgs e)
  111. {
  112. AppConfig.CloseFormShow(this.Text);
  113. this.Close();
  114. }
  115. private void btnExit_Click(object sender, EventArgs e)
  116. {
  117. AppConfig.CloseFormShow(this.Text);
  118. this.Close();
  119. }
  120. #endregion
  121. #region 过滤
  122. private string tempTableName = "";
  123. private void btnFilter_Click(object sender, EventArgs e)
  124. {
  125. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  126. filter.OldTempTableName = tempTableName;
  127. if (filter.ShowDialog() == DialogResult.OK)
  128. {
  129. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  130. try
  131. {
  132. _wait.Show();
  133. tempTableName = filter.NewTempTableName;
  134. sqltxt = filter.SqlText;
  135. sqlconn = filter.FilterConnectString;
  136. dataSource = filter.FilterData.Tables[0].Copy();
  137. DataSet ds = new DataSet();
  138. ds.Tables.Add(dataSource);
  139. ds.Tables.Add(filter.FilterData.Tables[1].Copy());
  140. DataRelation dr = new DataRelation("详情", new DataColumn[] { ds.Tables[0].Columns["cInvCode"] }, new DataColumn[] { ds.Tables[1].Columns["InvCode"] });
  141. ds.Relations.Add(dr);
  142. grdDetail.DataSource = dataSource;
  143. grvDetail.BestFitColumns();
  144. gridViewDetail.BestFitColumns();
  145. _wait.Close();
  146. }
  147. catch (Exception ex)
  148. {
  149. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  150. _wait.Close();
  151. }
  152. }
  153. }
  154. #endregion
  155. #region 绑定数据源
  156. private void btnConfig_Click(object sender, EventArgs e)//绑定数据源
  157. {
  158. if (AppConfig.UserCode.ToLower() != "demo")
  159. {
  160. //ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  161. return;
  162. }
  163. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  164. fdata.ShowDialog();
  165. }
  166. #endregion
  167. #region 刷新
  168. private void btnFalsh_Click(object sender, EventArgs e)
  169. {
  170. if (sqlconn == null || sqlconn == "")
  171. {
  172. return;
  173. }
  174. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  175. try
  176. {
  177. _wait.Show();
  178. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  179. filter.OldTempTableName = tempTableName;
  180. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  181. _wait.Close();
  182. }
  183. catch (Exception ex)
  184. {
  185. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  186. _wait.Close();
  187. }
  188. }
  189. #endregion
  190. #region 列表
  191. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  192. {
  193. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  194. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  195. }
  196. #endregion
  197. #region 过滤方法
  198. private void FormICSStack_FormClosing(object sender, FormClosingEventArgs e)
  199. {
  200. AppConfig.DropTemTable(tempTableName);
  201. }
  202. #endregion
  203. private void grdDetail_Click(object sender, EventArgs e)
  204. {
  205. DataTable dt = new DataTable();
  206. dt.Columns.Add();
  207. }
  208. private void FormICSSum_Manday_Load_1(object sender, EventArgs e)
  209. {
  210. btnFilter_Click(sender, e);
  211. }
  212. private void btnOutPut_Click(object sender, EventArgs e)
  213. {
  214. SimpleButton btntemp = (SimpleButton)sender;
  215. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  216. {
  217. MessageBox.Show("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  218. return;
  219. }
  220. FormOutExcel foe = new FormOutExcel();
  221. if (foe.ShowDialog() == DialogResult.OK)
  222. {
  223. try
  224. {
  225. string outtype = foe._OutType;
  226. string exceltype = foe._ExcelType;
  227. string filename = foe._FileName;
  228. string url = foe._Url;
  229. string sheetname = foe._SheetName;
  230. if (outtype.ToLower() == "excel")
  231. {
  232. DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions();
  233. op.SheetName = sheetname;
  234. grdDetail.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op);
  235. }
  236. else
  237. {
  238. grdDetail.MainView.ExportToPdf(url + "\\" + filename + ".pdf");
  239. }
  240. MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  241. }
  242. catch (Exception ex)
  243. {
  244. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  245. }
  246. }
  247. }
  248. }
  249. }