123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- // SupportStaff.cpp: 实现文件
- //
- #include "pch.h"
- #include "ZGKJ.h"
- #include "afxdialogex.h"
- #include "SupportStaff.h"
- #include <afxinet.h>
- // SupportStaff 对话框
- IMPLEMENT_DYNAMIC(SupportStaff, CDialogEx)
- SupportStaff::SupportStaff(CWnd* pParent /*=nullptr*/)
- : CDialogEx(IDD_SUPPORTSTAFF, pParent)
- , ProValue(_T(""))
- , CityValue(_T(""))
- , CountyValue(_T(""))
- , ErrorDescription(_T(""))
- , CompanyName(_T(""))
- , ContactNumber(_T(""))
- , Linkman(_T(""))
- {
-
- }
- SupportStaff::~SupportStaff()
- {
- }
- void SupportStaff::DoDataExchange(CDataExchange* pDX)
- {
- CDialogEx::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_PROVINCE, ProItem);
- DDX_CBString(pDX, IDC_PROVINCE, ProValue);
- DDX_Control(pDX, IDC_CITY, CityItem);
- DDX_CBString(pDX, IDC_CITY, CityValue);
- DDX_Control(pDX, IDC_COUNTY, CountyItem);
- DDX_CBString(pDX, IDC_COUNTY, CountyValue);
- DDX_Text(pDX, IDC_ERROR_DESCRIPTION, ErrorDescription);
- DDX_Text(pDX, IDC_EDIT1, CompanyName);
- DDX_Text(pDX, IDC_EDIT3, ContactNumber);
- DDX_Text(pDX, IDC_EDIT4, Linkman);
- }
- BEGIN_MESSAGE_MAP(SupportStaff, CDialogEx)
- ON_WM_TIMER()
- ON_CBN_SELCHANGE(IDC_PROVINCE, &SupportStaff::OnSelchangeProvince)
- ON_CBN_SELCHANGE(IDC_CITY, &SupportStaff::OnSelchangeCity)
- ON_BN_CLICKED(IDC_LOADIMAGE, &SupportStaff::OnBnClickedLoadimage)
- ON_WM_PAINT()
- ON_BN_CLICKED(IDC_CREATE_TICKET, &SupportStaff::OnBnClickedCreateTicket)
- ON_BN_CLICKED(IDC_BUTTON1, &SupportStaff::OnBnClickedButton1)
- END_MESSAGE_MAP()
- // SupportStaff 消息处理程序
- BOOL SupportStaff::OnInitDialog()
- {
- CDialogEx::OnInitDialog();
- // TODO: 在此添加额外的初始化
- LoadProvince();
- CityItem.EnableWindow(FALSE);
- CountyItem.EnableWindow(FALSE);
- SetTimer(1, 120000, NULL);
- return TRUE;
- return TRUE; // return TRUE unless you set the focus to a control
- // 异常: OCX 属性页应返回 FALSE
- }
- void SupportStaff::LoadProvince()
- {
- char order[STR_NUM];
- sprintf_s(order, STR_NUM - 1, "SELECT province.name FROM province");
- if (!theApp.sql->ExecutiveCommand(order))
- {
- MYSQL_RES* res = theApp.sql->GetResultSet();
- while (theApp.sql->row = mysql_fetch_row(res))
- {
- CString temp = theApp.MyAtoT(theApp.sql->row[0]);
- ProItem.AddString(temp);
- }
- }
- }
- void SupportStaff::OnTimer(UINT_PTR nIDEvent)
- {
- char order[STR_NUM] = "SELECT 1";
- if (nIDEvent == 1)
- {
- if (theApp.sql->ExecutiveCommand(order))
- {
- AfxMessageBox(theApp.MyAtoT(theApp.sql->GetErrorInformation()), MB_OK | MB_ICONERROR);
- }
- MYSQL_RES* res = theApp.sql->GetResultSet();
- }
- TRACE(_T("哈哈,我就是定时器\n"));
- CDialogEx::OnTimer(nIDEvent);
- }
- void SupportStaff::OnSelchangeProvince()
- {
- // TODO: 在此添加控件通知处理程序代码
- UpdateData();
- CityItem.ResetContent();
- char order[STR_NUM];
- 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));
- if (!theApp.sql->ExecutiveCommand(order))
- {
- MYSQL_RES* res = theApp.sql->GetResultSet();
- while (theApp.sql->row = mysql_fetch_row(res))
- {
- CString temp = theApp.MyAtoT(theApp.sql->row[0]);
- CityItem.AddString(temp);
- }
- }
- CityItem.EnableWindow(TRUE);
- }
- void SupportStaff::OnSelchangeCity()
- {
- // TODO: 在此添加控件通知处理程序代码
- UpdateData();
- CountyItem.ResetContent();
- char order[STR_NUM];
- 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));
- if (!theApp.sql->ExecutiveCommand(order))
- {
- MYSQL_RES* res = theApp.sql->GetResultSet();
- while (theApp.sql->row = mysql_fetch_row(res))
- {
- CString temp = theApp.MyAtoT(theApp.sql->row[0]);
- CountyItem.AddString(temp);
- }
- }
- CountyItem.EnableWindow(TRUE);
- }
- void SupportStaff::OnBnClickedLoadimage()
- {
- // TODO: 在此添加控件通知处理程序代码
- int i = 0;
- CFileDialog fileDlg(TRUE, NULL, _T("D:\\Pictruer\\"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT, _T("Text Files (*.jpg)|*.jpg||"), NULL);
- fileDlg.DoModal();
- fileNum = GetSelectedFileCount(fileDlg);
- if (fileNum > 4)
- {
- AfxMessageBox(_T("最多只能选中4张图片!"));
- return;
- }
- CString pathName = fileDlg.GetPathName(); // 获取第一个文件的完整路径(包括文件名)
- //CString fileName = fileDlg.GetFileName(); // 获取第一个文件的名称
- POSITION pos = fileDlg.GetStartPosition();
- while (pos != NULL)
- {
- pathName = fileDlg.GetNextPathName(pos);// 获取下一个文件的完整路径
- //TRACE(_T("哈哈,我是文件路径:") + pathName + _T("\n"));
- // 处理pathName,例如将其输出到列表控件或者其他控件
- FilePath.push_back(pathName);
- Image[i].Load(pathName);
- i++;
- }
- Invalidate();
- UpdateWindow();
- }
- void SupportStaff::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- // TODO: 在此处添加消息处理程序代码
- // 不为绘图消息调用 CDialogEx::OnPaint()
- int j = IDC_PICTURE;
- CRect rect;
- for (int i = 0; i < fileNum; i++)
- {
- if (!Image[i].IsNull())
- {
- GetDlgItem(j++)->GetWindowRect(rect);
- ScreenToClient(rect);
- Image[i].Draw(dc.m_hDC, rect);
- }
- }
- }
- int SupportStaff::GetSelectedFileCount(CFileDialog& fileDlg)
- {
- int FileCount = 0;
- POSITION filePosition = fileDlg.GetStartPosition();
- while (filePosition != nullptr)
- {
- fileDlg.GetNextPathName(filePosition);
- FileCount++;
- }
- return FileCount;
- }
- void SupportStaff::OnBnClickedCreateTicket()
- {
-
- UpdateData();
- //PreparedStatement* pstmt;
- char order[STR_NUM];
- CString str;
- CString str2;
- CString FileName;
- SYSTEMTIME localTime;
- GetLocalTime(&localTime);
- CTime lt(localTime);
- str += lt.Format(_T("%Y%m%d%H%M%S"));
- str2 = lt.Format(_T("%Y-%m-%d %H:%M:%S"));
- //"INSERT INTO tb_staff (phone,name,department_id,password,secret_key,post_id)VALUES ('%s','%s',%d,'%s',%d,%d)"
- 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')",
- 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));
- if (theApp.sql->ExecutiveCommand(order))
- {
- AfxMessageBox(theApp.MyAtoT(theApp.sql->GetErrorInformation()), MB_OK | MB_ICONERROR);
- return;
- }
- else
- {
- if (!ConnectFtpServer(_T("118.24.178.150"), _T("htl"), _T("ycJDHC1602")))
- {
- int a = GetLastError();
- AfxMessageBox(_T("链接FTP服务器失败! 错误代码:") + CZGKJApp::MyItoT(a));
- return;
- }
- if (!pFtpConnection->CreateDirectory(str))
- {
- int a = GetLastError();
- AfxMessageBox(_T("文件夹创建错误!错误码:") + CZGKJApp::MyItoT(a));
- return;
- }
- if (!pFtpConnection->SetCurrentDirectory(str))
- {
- int a = GetLastError();
- AfxMessageBox(_T("当前路径错误!错误码:")+ CZGKJApp::MyItoT(a));
- return;
- }
- for (int i = 0; i < FilePath.size(); i++)
- {
- CString FileName = str;
- FileName += CZGKJApp::MyItoT(i) + _T(".jpg");
- if (!pFtpConnection->PutFile(FilePath[i],FileName ))
- {
- int a = GetLastError();
- AfxMessageBox(_T("文件上传错误!错误码:") + CZGKJApp::MyItoT(a));
- return;
- }
- }
- }
- AfxMessageBox(_T("售后工单已生成,工单编号:" + str));
- SetDlgItemText(IDC_ERROR_DESCRIPTION, _T(""));
- return;
- }
- void SupportStaff::OnBnClickedButton1()
- {
- }
- BOOL SupportStaff::ConnectFtpServer(CString ServerIP, CString UserName, CString PassWord)
- {
- pInternetSession = new CInternetSession;
- pFtpConnection = new CFtpConnection(pInternetSession, ServerIP,UserName, PassWord);
- if (!pFtpConnection)
- {
- return FALSE;
- }
- return TRUE;
- }
|