SupportStaff.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. // SupportStaff.cpp: 实现文件
  2. //
  3. #include "pch.h"
  4. #include "ZGKJ.h"
  5. #include "afxdialogex.h"
  6. #include "SupportStaff.h"
  7. #include <afxinet.h>
  8. // SupportStaff 对话框
  9. IMPLEMENT_DYNAMIC(SupportStaff, CDialogEx)
  10. SupportStaff::SupportStaff(CWnd* pParent /*=nullptr*/)
  11. : CDialogEx(IDD_SUPPORTSTAFF, pParent)
  12. , ProValue(_T(""))
  13. , CityValue(_T(""))
  14. , CountyValue(_T(""))
  15. , ErrorDescription(_T(""))
  16. , CompanyName(_T(""))
  17. , ContactNumber(_T(""))
  18. , Linkman(_T(""))
  19. {
  20. }
  21. SupportStaff::~SupportStaff()
  22. {
  23. }
  24. void SupportStaff::DoDataExchange(CDataExchange* pDX)
  25. {
  26. CDialogEx::DoDataExchange(pDX);
  27. DDX_Control(pDX, IDC_PROVINCE, ProItem);
  28. DDX_CBString(pDX, IDC_PROVINCE, ProValue);
  29. DDX_Control(pDX, IDC_CITY, CityItem);
  30. DDX_CBString(pDX, IDC_CITY, CityValue);
  31. DDX_Control(pDX, IDC_COUNTY, CountyItem);
  32. DDX_CBString(pDX, IDC_COUNTY, CountyValue);
  33. DDX_Text(pDX, IDC_ERROR_DESCRIPTION, ErrorDescription);
  34. DDX_Text(pDX, IDC_EDIT1, CompanyName);
  35. DDX_Text(pDX, IDC_EDIT3, ContactNumber);
  36. DDX_Text(pDX, IDC_EDIT4, Linkman);
  37. }
  38. BEGIN_MESSAGE_MAP(SupportStaff, CDialogEx)
  39. ON_WM_TIMER()
  40. ON_CBN_SELCHANGE(IDC_PROVINCE, &SupportStaff::OnSelchangeProvince)
  41. ON_CBN_SELCHANGE(IDC_CITY, &SupportStaff::OnSelchangeCity)
  42. ON_BN_CLICKED(IDC_LOADIMAGE, &SupportStaff::OnBnClickedLoadimage)
  43. ON_WM_PAINT()
  44. ON_BN_CLICKED(IDC_CREATE_TICKET, &SupportStaff::OnBnClickedCreateTicket)
  45. ON_BN_CLICKED(IDC_BUTTON1, &SupportStaff::OnBnClickedButton1)
  46. END_MESSAGE_MAP()
  47. // SupportStaff 消息处理程序
  48. BOOL SupportStaff::OnInitDialog()
  49. {
  50. CDialogEx::OnInitDialog();
  51. // TODO: 在此添加额外的初始化
  52. LoadProvince();
  53. CityItem.EnableWindow(FALSE);
  54. CountyItem.EnableWindow(FALSE);
  55. SetTimer(1, 120000, NULL);
  56. return TRUE;
  57. return TRUE; // return TRUE unless you set the focus to a control
  58. // 异常: OCX 属性页应返回 FALSE
  59. }
  60. void SupportStaff::LoadProvince()
  61. {
  62. char order[STR_NUM];
  63. sprintf_s(order, STR_NUM - 1, "SELECT province.name FROM province");
  64. if (!theApp.sql->ExecutiveCommand(order))
  65. {
  66. MYSQL_RES* res = theApp.sql->GetResultSet();
  67. while (theApp.sql->row = mysql_fetch_row(res))
  68. {
  69. CString temp = theApp.MyAtoT(theApp.sql->row[0]);
  70. ProItem.AddString(temp);
  71. }
  72. }
  73. }
  74. void SupportStaff::OnTimer(UINT_PTR nIDEvent)
  75. {
  76. char order[STR_NUM] = "SELECT 1";
  77. if (nIDEvent == 1)
  78. {
  79. if (theApp.sql->ExecutiveCommand(order))
  80. {
  81. AfxMessageBox(theApp.MyAtoT(theApp.sql->GetErrorInformation()), MB_OK | MB_ICONERROR);
  82. }
  83. MYSQL_RES* res = theApp.sql->GetResultSet();
  84. }
  85. TRACE(_T("哈哈,我就是定时器\n"));
  86. CDialogEx::OnTimer(nIDEvent);
  87. }
  88. void SupportStaff::OnSelchangeProvince()
  89. {
  90. // TODO: 在此添加控件通知处理程序代码
  91. UpdateData();
  92. CityItem.ResetContent();
  93. char order[STR_NUM];
  94. sprintf_s(order, STR_NUM - 1, "SELECT city.name FROM city INNER JOIN province ON province.id = city.provinceid WHERE province.name='%s'", CZGKJApp::MyTtoA(ProValue));
  95. if (!theApp.sql->ExecutiveCommand(order))
  96. {
  97. MYSQL_RES* res = theApp.sql->GetResultSet();
  98. while (theApp.sql->row = mysql_fetch_row(res))
  99. {
  100. CString temp = theApp.MyAtoT(theApp.sql->row[0]);
  101. CityItem.AddString(temp);
  102. }
  103. }
  104. CityItem.EnableWindow(TRUE);
  105. }
  106. void SupportStaff::OnSelchangeCity()
  107. {
  108. // TODO: 在此添加控件通知处理程序代码
  109. UpdateData();
  110. CountyItem.ResetContent();
  111. char order[STR_NUM];
  112. sprintf_s(order, STR_NUM - 1, "SELECT area.name FROM area INNER JOIN city ON city.id = area.cityid WHERE city.name = '%s'", CZGKJApp::MyTtoA(CityValue));
  113. if (!theApp.sql->ExecutiveCommand(order))
  114. {
  115. MYSQL_RES* res = theApp.sql->GetResultSet();
  116. while (theApp.sql->row = mysql_fetch_row(res))
  117. {
  118. CString temp = theApp.MyAtoT(theApp.sql->row[0]);
  119. CountyItem.AddString(temp);
  120. }
  121. }
  122. CountyItem.EnableWindow(TRUE);
  123. }
  124. void SupportStaff::OnBnClickedLoadimage()
  125. {
  126. // TODO: 在此添加控件通知处理程序代码
  127. int i = 0;
  128. CFileDialog fileDlg(TRUE, NULL, _T("D:\\Pictruer\\"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT, _T("Text Files (*.jpg)|*.jpg||"), NULL);
  129. fileDlg.DoModal();
  130. fileNum = GetSelectedFileCount(fileDlg);
  131. if (fileNum > 4)
  132. {
  133. AfxMessageBox(_T("最多只能选中4张图片!"));
  134. return;
  135. }
  136. CString pathName = fileDlg.GetPathName(); // 获取第一个文件的完整路径(包括文件名)
  137. //CString fileName = fileDlg.GetFileName(); // 获取第一个文件的名称
  138. POSITION pos = fileDlg.GetStartPosition();
  139. while (pos != NULL)
  140. {
  141. pathName = fileDlg.GetNextPathName(pos);// 获取下一个文件的完整路径
  142. //TRACE(_T("哈哈,我是文件路径:") + pathName + _T("\n"));
  143. // 处理pathName,例如将其输出到列表控件或者其他控件
  144. FilePath.push_back(pathName);
  145. Image[i].Load(pathName);
  146. i++;
  147. }
  148. Invalidate();
  149. UpdateWindow();
  150. }
  151. void SupportStaff::OnPaint()
  152. {
  153. CPaintDC dc(this); // device context for painting
  154. // TODO: 在此处添加消息处理程序代码
  155. // 不为绘图消息调用 CDialogEx::OnPaint()
  156. int j = IDC_PICTURE;
  157. CRect rect;
  158. for (int i = 0; i < fileNum; i++)
  159. {
  160. if (!Image[i].IsNull())
  161. {
  162. GetDlgItem(j++)->GetWindowRect(rect);
  163. ScreenToClient(rect);
  164. Image[i].Draw(dc.m_hDC, rect);
  165. }
  166. }
  167. }
  168. int SupportStaff::GetSelectedFileCount(CFileDialog& fileDlg)
  169. {
  170. int FileCount = 0;
  171. POSITION filePosition = fileDlg.GetStartPosition();
  172. while (filePosition != nullptr)
  173. {
  174. fileDlg.GetNextPathName(filePosition);
  175. FileCount++;
  176. }
  177. return FileCount;
  178. }
  179. void SupportStaff::OnBnClickedCreateTicket()
  180. {
  181. UpdateData();
  182. //PreparedStatement* pstmt;
  183. char order[STR_NUM];
  184. CString str;
  185. CString str2;
  186. CString FileName;
  187. SYSTEMTIME localTime;
  188. GetLocalTime(&localTime);
  189. CTime lt(localTime);
  190. str += lt.Format(_T("%Y%m%d%H%M%S"));
  191. str2 = lt.Format(_T("%Y-%m-%d %H:%M:%S"));
  192. //"INSERT INTO tb_staff (phone,name,department_id,password,secret_key,post_id)VALUES ('%s','%s',%d,'%s',%d,%d)"
  193. sprintf_s(order, STR_NUM - 1, "INSERT INTO tb_after_sale_ticket (ticketid,error_description,time_begin,province,city,area,company_name,contact_number,linkman,Customer_call) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
  194. CZGKJApp::MyTtoA(str), CZGKJApp::MyTtoA(ErrorDescription), CZGKJApp::MyTtoA(str2), CZGKJApp::MyTtoA(ProValue), CZGKJApp::MyTtoA(CityValue), CZGKJApp::MyTtoA(CountyValue), CZGKJApp::MyTtoA(CompanyName), CZGKJApp::MyTtoA(ContactNumber), CZGKJApp::MyTtoA(Linkman), CZGKJApp::MyTtoA(theApp.Phone));
  195. if (theApp.sql->ExecutiveCommand(order))
  196. {
  197. AfxMessageBox(theApp.MyAtoT(theApp.sql->GetErrorInformation()), MB_OK | MB_ICONERROR);
  198. return;
  199. }
  200. else
  201. {
  202. if (!ConnectFtpServer(_T("118.24.178.150"), _T("htl"), _T("ycJDHC1602")))
  203. {
  204. int a = GetLastError();
  205. AfxMessageBox(_T("链接FTP服务器失败! 错误代码:") + CZGKJApp::MyItoT(a));
  206. return;
  207. }
  208. if (!pFtpConnection->CreateDirectory(str))
  209. {
  210. int a = GetLastError();
  211. AfxMessageBox(_T("文件夹创建错误!错误码:") + CZGKJApp::MyItoT(a));
  212. return;
  213. }
  214. if (!pFtpConnection->SetCurrentDirectory(str))
  215. {
  216. int a = GetLastError();
  217. AfxMessageBox(_T("当前路径错误!错误码:")+ CZGKJApp::MyItoT(a));
  218. return;
  219. }
  220. for (int i = 0; i < FilePath.size(); i++)
  221. {
  222. CString FileName = str;
  223. FileName += CZGKJApp::MyItoT(i) + _T(".jpg");
  224. if (!pFtpConnection->PutFile(FilePath[i],FileName ))
  225. {
  226. int a = GetLastError();
  227. AfxMessageBox(_T("文件上传错误!错误码:") + CZGKJApp::MyItoT(a));
  228. return;
  229. }
  230. }
  231. }
  232. AfxMessageBox(_T("售后工单已生成,工单编号:" + str));
  233. SetDlgItemText(IDC_ERROR_DESCRIPTION, _T(""));
  234. return;
  235. }
  236. void SupportStaff::OnBnClickedButton1()
  237. {
  238. }
  239. BOOL SupportStaff::ConnectFtpServer(CString ServerIP, CString UserName, CString PassWord)
  240. {
  241. pInternetSession = new CInternetSession;
  242. pFtpConnection = new CFtpConnection(pInternetSession, ServerIP,UserName, PassWord);
  243. if (!pFtpConnection)
  244. {
  245. return FALSE;
  246. }
  247. return TRUE;
  248. }