锐腾搅拌上料功能
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.

363 lines
14 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(this.Tag.ToString(), grdDetail);
  232. foe.ShowDialog();
  233. }
  234. #endregion
  235. #region 同步
  236. private void btnSelectERP_Click(object sender, EventArgs e)
  237. {
  238. grvDetail.PostEditor();
  239. this.Validate();
  240. SimpleButton btn = ((SimpleButton)sender);
  241. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btn.Name) == false)
  242. {
  243. ICSBaseSimpleCode.AppshowMessageBox(0, "对不起您没有:" + btn.Text + "权限,请联系系统管理员!");
  244. return;
  245. }
  246. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在同步请稍等...");
  247. try
  248. {
  249. ICSStorageBLL.SelectERP(ICSBaseSimpleCode.GetWorkPointErpData());
  250. //FormDataRefer reForm = new FormDataRefer();
  251. //reForm.FormTitle = "ERP库房信息";
  252. ////DataTable menuData = data;
  253. ////reForm.DataSource = menuData;
  254. //reForm.MSelectFlag = true;
  255. //reForm.RowIndexWidth = 35;
  256. //reForm.HideCols.Add("ID");
  257. //reForm.Width = 600;
  258. //reForm.Height = this.Height - 100;
  259. //reForm.FilterKey = "";
  260. //DialogResult result = reForm.ShowDialog();
  261. //if (result == DialogResult.OK)
  262. //{
  263. // DataTable retData = reForm.ReturnData;
  264. // if (retData.Rows.Count == 0)
  265. // {
  266. // ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  267. // return;
  268. // }
  269. // try
  270. // {
  271. //ICSStorageBLL.SaveInfo(retData, AppConfig.AppConnectString);
  272. _wait.Close();
  273. ICSBaseSimpleCode.AppshowMessageBox("同步成功");
  274. btnFalsh_Click(null, null);
  275. // }
  276. // catch (Exception ex)
  277. // {
  278. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  279. // return;
  280. // }
  281. //}
  282. }
  283. catch (Exception ex)
  284. {
  285. _wait.Close();
  286. ICSBaseSimpleCode.AppshowMessageBox(1, ex.Message);
  287. return;
  288. }
  289. }
  290. #endregion
  291. #region 过滤方法
  292. private void FormICSStorage_FormClosing(object sender, FormClosingEventArgs e)
  293. {
  294. AppConfig.DropTemTable(tempTableName);
  295. }
  296. #endregion
  297. private void FormICSStorage_Load_1(object sender, EventArgs e)
  298. {
  299. btnFilter_Click(null, null);
  300. //FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  301. //if (filter.ShowDialog() == DialogResult.OK)
  302. //{
  303. // DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  304. // try
  305. // {
  306. // grdDetail.DataSource = null;
  307. // _wait.Show();
  308. // sqltxt = filter.SqlText;
  309. // sqlconn = filter.FilterConnectString;
  310. // dataSource = filter.FilterData.Tables[0];
  311. // grdDetail.DataSource = dataSource;
  312. // grvDetail.BestFitColumns();
  313. // rptPage.RecordNum = dataSource.Rows.Count;
  314. // rptPage.PageSize = 499;
  315. // rptPage.PageIndex = 1;
  316. // rptPage.ReLoad();
  317. // rptPage.PageSize = 500;
  318. // rptPage.PageIndex = 1;
  319. // rptPage.ReLoad();
  320. // _wait.Close();
  321. // }
  322. // catch (Exception ex)
  323. // {
  324. // MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  325. // _wait.Close();
  326. // }
  327. //}
  328. }
  329. }
  330. }