华恒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.

388 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 ICSSoft.Frame.User.BLL;
  10. using ICSSoft.Base.Language.Tool;
  11. using ICSSoft.Base.UserControl.MessageControl;
  12. using ICSSoft.Frame.Data.BLL;
  13. using System.Data.SqlClient;
  14. using ICSSoft.Base.Config.AppConfig;
  15. using ICSSoft.Frame.Data.Entity;
  16. using ICSSoft.Base.Report.Filter;
  17. using ICSSoft.Base.Config.DBHelper;
  18. using ICSSoft.Base.UserControl.FormControl;
  19. using ICSSoft.Base.ReferForm.AppReferForm;
  20. using ICSSoft.Frame.APP;
  21. namespace ICSSoft.Frame.APP
  22. {
  23. public partial class FormICSDReport : DevExpress.XtraEditors.XtraForm
  24. {
  25. private string sqltxt = "";
  26. private string sqlconn = "";
  27. String guid = AppConfig.GetGuid();
  28. private DataTable dataSource = null;
  29. #region 构造函数
  30. public FormICSDReport()
  31. {
  32. InitializeComponent();
  33. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  34. this.WindowState = FormWindowState.Maximized;
  35. }
  36. #endregion
  37. #region 移动窗体
  38. private const int WM_NCHITTEST = 0x84;
  39. private const int HTCLIENT = 0x1;
  40. private const int HTCAPTION = 0x2;
  41. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  42. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  43. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  44. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  45. //重写窗体,使窗体可以不通过自带标题栏实现移动
  46. protected override void WndProc(ref Message m)
  47. {
  48. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  49. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  50. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  51. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  52. switch (m.Msg)
  53. {
  54. case WM_NCHITTEST:
  55. base.WndProc(ref m);
  56. if ((int)m.Result == HTCLIENT)
  57. m.Result = (IntPtr)HTCAPTION;
  58. return;
  59. }
  60. //拦截双击标题栏、移动窗体的系统消息
  61. if (m.Msg != 0xA3)
  62. {
  63. base.WndProc(ref m);
  64. }
  65. }
  66. #endregion
  67. #region SystemOptition
  68. /// <summary>
  69. /// 操作权限
  70. /// </summary>
  71. /// <returns></returns>
  72. public DataTable RightOfExute()
  73. {
  74. DataTable rData = new DataTable();
  75. rData.Columns.Add("BtnName");
  76. rData.Columns.Add("ActionName");
  77. //查看权限(必须有)
  78. DataRow seeRow = rData.NewRow();
  79. seeRow["BtnName"] = "see";
  80. seeRow["ActionName"] = "查看";
  81. rData.Rows.Add(seeRow);
  82. List<Control> ControlList = new List<Control>();
  83. //ControlList.Add(btnSelect);
  84. //ControlList.Add(btnCanSelect);
  85. //ControlList.Add(btnAdd);
  86. //ControlList.Add(btnEdit);
  87. //ControlList.Add(btnDelLable);
  88. ControlList.Add(btnOutPut);
  89. foreach (Control ctr in ControlList)
  90. {
  91. if (ctr.GetType() == typeof(SimpleButton))
  92. {
  93. DataRow dr = rData.NewRow();
  94. dr["BtnName"] = ctr.Name;
  95. dr["ActionName"] = ctr.Text;
  96. rData.Rows.Add(dr);
  97. }
  98. }
  99. rData.AcceptChanges();
  100. return rData;
  101. }
  102. /// <summary>
  103. /// 数据权限
  104. /// </summary>
  105. /// <returns></returns>
  106. public DataTable RightOfData()
  107. {
  108. DataTable rData = new DataTable();
  109. rData.Columns.Add("BodyName");
  110. rData.Columns.Add("ControlName");
  111. rData.Columns.Add("ControlCaption");
  112. rData.AcceptChanges();
  113. return rData;
  114. }
  115. #endregion
  116. #region 退出
  117. private void btnClose_Click(object sender, EventArgs e)
  118. {
  119. AppConfig.CloseFormShow(this.Text);
  120. this.Close();
  121. }
  122. private void btnExit_Click(object sender, EventArgs e)
  123. {
  124. AppConfig.CloseFormShow(this.Text);
  125. this.Close();
  126. }
  127. #endregion
  128. #region 过滤
  129. private string tempTableName = "";
  130. private void btnFilter_Click(object sender, EventArgs e)
  131. {
  132. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  133. filter.OldTempTableName = tempTableName;
  134. if (filter.ShowDialog() == DialogResult.OK)
  135. {
  136. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  137. try
  138. {
  139. grdDetail.DataSource = null;
  140. grvDetail.Columns.Clear();
  141. _wait.Show();
  142. tempTableName = filter.NewTempTableName;
  143. sqltxt = filter.SqlText;
  144. sqlconn = filter.FilterConnectString;
  145. dataSource = filter.FilterData.Tables[0];
  146. if (dataSource.Columns.Contains("pagerowindex"))
  147. dataSource.Columns.Remove("pagerowindex");
  148. grdDetail.DataSource = dataSource;
  149. grvDetail.BestFitColumns();
  150. rptPage.RecordNum = dataSource.Rows.Count;
  151. rptPage.PageSize = 499;
  152. rptPage.PageIndex = 1;
  153. rptPage.ReLoad();
  154. rptPage.PageSize = 500;
  155. rptPage.PageIndex = 1;
  156. rptPage.ReLoad();
  157. _wait.Close();
  158. }
  159. catch (Exception ex)
  160. {
  161. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  162. _wait.Close();
  163. }
  164. }
  165. }
  166. #endregion
  167. #region 绑定数据源
  168. private void btnConfig_Click(object sender, EventArgs e)//绑定数据源
  169. {
  170. if (AppConfig.UserCode.ToLower() != "demo")
  171. {
  172. //ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  173. return;
  174. }
  175. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  176. fdata.ShowDialog();
  177. }
  178. #endregion
  179. #region 分页
  180. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  181. {
  182. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  183. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  184. grdDetail.DataSource = data;
  185. }
  186. #endregion
  187. #region 刷新
  188. private void btnFalsh_Click(object sender, EventArgs e)
  189. {
  190. if (sqlconn == null || sqlconn == "")
  191. {
  192. return;
  193. }
  194. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  195. try
  196. {
  197. grdDetail.DataSource = null;
  198. grvDetail.Columns.Clear();
  199. _wait.Show();
  200. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  201. filter.OldTempTableName = tempTableName;
  202. //tempTableName = filter.NewTempTableName;
  203. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  204. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  205. if (dataSource.Columns.Contains("pagerowindex"))
  206. dataSource.Columns.Remove("pagerowindex");
  207. grdDetail.DataSource = dataSource;
  208. grvDetail.BestFitColumns();
  209. rptPage.RecordNum = dataSource.Rows.Count;
  210. rptPage.PageIndex = 1;
  211. rptPage.ReLoad();
  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 btnOutput_Click(object sender, EventArgs e)
  230. {
  231. FormOutExcel foe = new FormOutExcel();
  232. if (foe.ShowDialog() == DialogResult.OK)
  233. {
  234. try
  235. {
  236. string outtype = foe._OutType;
  237. string exceltype = foe._ExcelType;
  238. string filename = foe._FileName;
  239. string url = foe._Url;
  240. string sheetname = foe._SheetName;
  241. if (outtype.ToLower() == "excel")
  242. {
  243. DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions();
  244. op.SheetName = sheetname;
  245. grdDetail.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op);
  246. }
  247. else
  248. {
  249. grdDetail.MainView.ExportToPdf(url + "\\" + filename + ".pdf");
  250. }
  251. MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  252. }
  253. catch (Exception ex)
  254. {
  255. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  256. }
  257. }
  258. }
  259. #endregion
  260. #region 同步
  261. private void btnSelectERP_Click(object sender, EventArgs e)
  262. {
  263. grvDetail.PostEditor();
  264. this.Validate();
  265. SimpleButton btn = ((SimpleButton)sender);
  266. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btn.Name) == false)
  267. {
  268. ICSBaseSimpleCode.AppshowMessageBox(0, "对不起您没有:" + btn.Text + "权限,请联系系统管理员!");
  269. return;
  270. }
  271. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在同步请稍等...");
  272. try
  273. {
  274. ICSStorageBLL.SelectERP(ICSBaseSimpleCode.GetWorkPointErpData());
  275. //FormDataRefer reForm = new FormDataRefer();
  276. //reForm.FormTitle = "ERP库房信息";
  277. ////DataTable menuData = data;
  278. ////reForm.DataSource = menuData;
  279. //reForm.MSelectFlag = true;
  280. //reForm.RowIndexWidth = 35;
  281. //reForm.HideCols.Add("ID");
  282. //reForm.Width = 600;
  283. //reForm.Height = this.Height - 100;
  284. //reForm.FilterKey = "";
  285. //DialogResult result = reForm.ShowDialog();
  286. //if (result == DialogResult.OK)
  287. //{
  288. // DataTable retData = reForm.ReturnData;
  289. // if (retData.Rows.Count == 0)
  290. // {
  291. // ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  292. // return;
  293. // }
  294. // try
  295. // {
  296. //ICSStorageBLL.SaveInfo(retData, AppConfig.AppConnectString);
  297. _wait.Close();
  298. ICSBaseSimpleCode.AppshowMessageBox("同步成功");
  299. btnFalsh_Click(null, null);
  300. // }
  301. // catch (Exception ex)
  302. // {
  303. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  304. // return;
  305. // }
  306. //}
  307. }
  308. catch (Exception ex)
  309. {
  310. _wait.Close();
  311. ICSBaseSimpleCode.AppshowMessageBox(1, ex.Message);
  312. return;
  313. }
  314. }
  315. #endregion
  316. #region 过滤方法
  317. private void FormICSStorage_FormClosing(object sender, FormClosingEventArgs e)
  318. {
  319. AppConfig.DropTemTable(tempTableName);
  320. }
  321. #endregion
  322. private void FormICSStorage_Load_1(object sender, EventArgs e)
  323. {
  324. btnFilter_Click(null, null);
  325. //FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  326. //if (filter.ShowDialog() == DialogResult.OK)
  327. //{
  328. // DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  329. // try
  330. // {
  331. // grdDetail.DataSource = null;
  332. // _wait.Show();
  333. // sqltxt = filter.SqlText;
  334. // sqlconn = filter.FilterConnectString;
  335. // dataSource = filter.FilterData.Tables[0];
  336. // grdDetail.DataSource = dataSource;
  337. // grvDetail.BestFitColumns();
  338. // rptPage.RecordNum = dataSource.Rows.Count;
  339. // rptPage.PageSize = 499;
  340. // rptPage.PageIndex = 1;
  341. // rptPage.ReLoad();
  342. // rptPage.PageSize = 500;
  343. // rptPage.PageIndex = 1;
  344. // rptPage.ReLoad();
  345. // _wait.Close();
  346. // }
  347. // catch (Exception ex)
  348. // {
  349. // MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  350. // _wait.Close();
  351. // }
  352. //}
  353. }
  354. }
  355. }