SalarySet4.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. // SalarySet4.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "SalarySet4.h"
  6. #include "SelExpendType.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // SalarySet4 dialog
  14. SalarySet4::SalarySet4(CWnd* pParent /*=NULL*/)
  15. : CDialog(SalarySet4::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(SalarySet4)
  18. m_money1 = 0;
  19. m_money2 = 0;
  20. m_rate = 0.0f;
  21. m_check1 = FALSE;
  22. m_testmoney = 0.0f;
  23. //}}AFX_DATA_INIT
  24. }
  25. void SalarySet4::DoDataExchange(CDataExchange* pDX)
  26. {
  27. CDialog::DoDataExchange(pDX);
  28. //{{AFX_DATA_MAP(SalarySet4)
  29. DDX_Control(pDX, IDC_EDIT8, m_numctrl4);
  30. DDX_Control(pDX, IDC_LIST1, m_list1);
  31. DDX_Control(pDX, IDC_EDIT3, m_numctrl3);
  32. DDX_Control(pDX, IDC_EDIT2, m_numctrl2);
  33. DDX_Control(pDX, IDC_EDIT1, m_numctrl1);
  34. DDX_Text(pDX, IDC_EDIT1, m_money1);
  35. DDX_Text(pDX, IDC_EDIT2, m_money2);
  36. DDX_Text(pDX, IDC_EDIT3, m_rate);
  37. DDX_Check(pDX, IDC_CHECK1, m_check1);
  38. DDX_Text(pDX, IDC_EDIT8, m_testmoney);
  39. //}}AFX_DATA_MAP
  40. }
  41. BEGIN_MESSAGE_MAP(SalarySet4, CDialog)
  42. //{{AFX_MSG_MAP(SalarySet4)
  43. ON_BN_CLICKED(IDC_BUTTON1, OnAdd)
  44. ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
  45. ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
  46. ON_BN_CLICKED(IDC_BUTTON14, OnButton14)
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. /////////////////////////////////////////////////////////////////////////////
  50. // SalarySet4 message handlers
  51. BOOL SalarySet4::OnInitDialog()
  52. {
  53. CDialog::OnInitDialog();
  54. // TODO: Add extra initialization here
  55. if (IsHasRights2new(25) == 0)
  56. {
  57. GetDlgItem(IDOK)->EnableWindow(0);
  58. }
  59. CString str = g_cominfoarray.ElementAt(0).ElementAt(77);
  60. int pos = str.Find(m_header);
  61. int headleng = m_header.GetLength();
  62. if (pos != -1)
  63. {
  64. str = str.Right(str.GetLength() - pos);
  65. str.Delete(0, headleng);
  66. pos = str.Find("$");
  67. if (pos != -1)
  68. str = str.Left(pos);
  69. InitRule(str);
  70. }
  71. str = m_header;
  72. str.TrimLeft("$");
  73. str.TrimRight(":");
  74. SetWindowText("阶梯提成方案-" + str);
  75. //////////////////////////////////////////////////////
  76. g_sendhead.bsql = 0;
  77. g_sendhead.code[0] = 160;
  78. g_sendhead.code[1] = 169;
  79. g_sendhead.tabcount = 2;
  80. g_pMainWnd->ProcessChatMessageRequest2(1);
  81. if (g_bSendOK == 0)
  82. {
  83. CDialog::OnCancel();
  84. return 0;
  85. }
  86. CArray<CStringArray, CStringArray>expendtypearray;
  87. CArray<CStringArray, CStringArray>baseexpendtypearray;
  88. DataToArray(&expendtypearray, &baseexpendtypearray);
  89. for (int i = 0; i < baseexpendtypearray.GetSize(); i++)
  90. {
  91. m_expendtypearray.Add(baseexpendtypearray.ElementAt(i).ElementAt(0));
  92. }
  93. for (i = 0; i < expendtypearray.GetSize(); i++)
  94. {
  95. m_expendtypearray.Add(expendtypearray.ElementAt(i).ElementAt(0));
  96. }
  97. m_expendtypearray.Add("摄影二销");
  98. #ifdef CHILD_VERSION
  99. m_expendtypearray.Add("引导二销");
  100. #else
  101. m_expendtypearray.Add("化妆二销");
  102. #endif // CHILD_VERSION
  103. m_expendtypearray.Add("选片二销");
  104. m_expendtypearray.Add("摄影选片二销");
  105. #ifdef CHILD_VERSION
  106. m_expendtypearray.Add("引导选片二销");
  107. #else
  108. m_expendtypearray.Add("化妆选片二销");
  109. #endif // CHILD_VERSION
  110. CenterWindow();
  111. return TRUE; // return TRUE unless you set the focus to a control
  112. // EXCEPTION: OCX Property Pages should return FALSE
  113. }
  114. void SalarySet4::OnAdd()
  115. {
  116. // TODO: Add your control notification handler code here
  117. UpdateData();
  118. if (CheckRange() == 0)
  119. return;
  120. CString str, temp;
  121. if (m_money1 >= m_money2)
  122. {
  123. AfxMessageBox("业绩范围出错!", MB_ICONINFORMATION);
  124. return;
  125. }
  126. if (m_list1.GetCount() == 0 && m_money1 != 0)
  127. {
  128. AfxMessageBox("起始业绩应从0开始!", MB_ICONINFORMATION);
  129. return;
  130. }
  131. str.Format("%d-%d 提:%0.1f", m_money1, m_money2, m_rate); str += "%";
  132. for (int i = 0; i < m_list1.GetCount(); i++)
  133. {
  134. m_list1.GetText(i, temp);
  135. if (str == temp)
  136. {
  137. AfxMessageBox("已有此规则!", MB_ICONINFORMATION);
  138. return;
  139. }
  140. }
  141. m_list1.AddString(str);
  142. }
  143. BOOL SalarySet4::CheckRange()
  144. {
  145. CString str, temp;
  146. int money1, money2;
  147. for (int i = 0; i < m_list1.GetCount(); i++)
  148. {
  149. m_list1.GetText(i, temp);
  150. int pos = temp.Find(" ");
  151. temp = temp.Left(pos);
  152. pos = temp.Find("-");
  153. money1 = atoi(temp.Left(pos));
  154. money2 = atoi(temp.Right(temp.GetLength() - pos - 1));
  155. if (m_money1 >= money1 && m_money1 <= money2)
  156. {
  157. AfxMessageBox("起始业绩已包含在已有的规则中!", MB_ICONINFORMATION);
  158. return 0;
  159. }
  160. if (m_money2 >= money1 && m_money2 <= money2)
  161. {
  162. AfxMessageBox("终止业绩已包含在已有的规则中!", MB_ICONINFORMATION);
  163. return 0;
  164. }
  165. }
  166. if (m_list1.GetCount())
  167. {
  168. m_list1.GetText(m_list1.GetCount() - 1, temp);
  169. int pos = temp.Find(" ");
  170. temp = temp.Left(pos);
  171. pos = temp.Find("-");
  172. money2 = atoi(temp.Right(temp.GetLength() - pos - 1));
  173. if (m_money1 != money2 + 1)
  174. {
  175. AfxMessageBox("业绩段不连续,起始业绩应比上一规则段终止业绩大1", MB_ICONINFORMATION);
  176. return 0;
  177. }
  178. }
  179. return 1;
  180. }
  181. void SalarySet4::OnButton3()
  182. {
  183. // TODO: Add your control notification handler code here
  184. if (AfxMessageBox("确定要删除全部规则吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return;
  185. m_list1.ResetContent();
  186. }
  187. void SalarySet4::OnOK()
  188. {
  189. // TODO: Add extra validation here
  190. UpdateData();
  191. CString str, temp;
  192. str = m_header;
  193. for (int i = 0; i < m_list1.GetCount(); i++)
  194. {
  195. m_list1.GetText(i, temp);
  196. str += temp;
  197. str += ";";
  198. }
  199. temp.Format("%d", m_check1);
  200. str += temp;
  201. CString oldrule = g_cominfoarray.ElementAt(0).ElementAt(77);
  202. CString left, right;
  203. int pos = oldrule.Find(m_header);
  204. if (pos != -1)
  205. {
  206. left = oldrule.Left(pos);
  207. right = oldrule.Right(oldrule.GetLength() - pos - m_header.GetLength());
  208. pos = right.Find("$");
  209. if (pos != -1)
  210. right = right.Right(right.GetLength() - pos);
  211. else
  212. right.Empty();
  213. str = left + str + right;
  214. }
  215. else
  216. str += oldrule;
  217. CString name;
  218. temp.Empty();
  219. pos = str.Find("$");
  220. while (pos != -1)
  221. {
  222. int pos2 = str.Find(":");
  223. name = str.Mid(pos + 1, pos2 - pos - 1);
  224. BOOL bFind = 0;
  225. for (int i = 0; i < m_expendtypearray.GetSize(); i++)
  226. {
  227. if (name == m_expendtypearray.ElementAt(i))
  228. {
  229. bFind = 1;
  230. break;
  231. }
  232. }
  233. if (bFind)
  234. {
  235. temp += str.Left(pos2);
  236. str = str.Right(str.GetLength() - pos2);
  237. pos = str.Find("$");
  238. if (pos != -1)
  239. {
  240. temp += str.Left(pos);
  241. str = str.Right(str.GetLength() - pos);
  242. }
  243. else
  244. temp += str;
  245. pos = str.Find("$");
  246. }
  247. else
  248. {
  249. str = str.Right(str.GetLength() - pos2);
  250. pos = str.Find("$");
  251. if (pos != -1)
  252. {
  253. str = str.Right(str.GetLength() - pos);
  254. }
  255. pos = str.Find("$");
  256. }
  257. }
  258. str = temp;
  259. //$摄影师前期:0-1000 提:1.0%;0$门市前期:0-1000 提:1.0%;0$摄影二消:0$前期:0$化妆二消:0$选片二消:1
  260. // m_expendtypearray
  261. CString sql;
  262. sql.Format("update version set [salaryset]='%s'", str);
  263. g_sendhead.bsql = 1;
  264. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  265. AfxMessageBox("保存成功!", MB_ICONINFORMATION);
  266. g_cominfoarray.ElementAt(0).SetAt(77, str);
  267. CDialog::OnOK();
  268. }
  269. float GetSalaryFromRule(float fmoney, CString rule)
  270. {
  271. float fresult = 0;
  272. int pos = rule.Find(":");
  273. if (pos == -1)return 0;
  274. rule = rule.Right(rule.GetLength() - pos - 1);
  275. CStringArray rulearray;
  276. pos = rule.Find(";");
  277. while (pos != -1)
  278. {
  279. rulearray.Add(rule.Left(pos));
  280. rule = rule.Right(rule.GetLength() - pos - 1);
  281. pos = rule.Find(";");
  282. }
  283. BOOL check1 = atoi(rule);
  284. if (rulearray.GetSize() == 0)return 0;
  285. CString str, temp;
  286. int money1, money2;
  287. float frate;
  288. if (check1 == 0)
  289. {
  290. for (int i = 0; i < rulearray.GetSize(); i++)
  291. {
  292. temp = rulearray.ElementAt(i);
  293. int pos = temp.Find(" ");
  294. temp = temp.Left(pos);
  295. pos = temp.Find("-");
  296. money1 = atoi(temp.Left(pos));
  297. money2 = atoi(temp.Right(temp.GetLength() - pos - 1));
  298. if ((i == rulearray.GetSize() - 1) || (fmoney >= money1 && fmoney <= money2))
  299. {
  300. temp = rulearray.ElementAt(i);
  301. pos = temp.Find(":");
  302. temp = temp.Right(temp.GetLength() - pos - 1);
  303. temp.TrimRight("%");
  304. frate = atof(temp) / 100.0;
  305. fresult = frate*fmoney;
  306. return fresult;
  307. }
  308. }
  309. }
  310. else//////
  311. {
  312. for (int i = 0; i < rulearray.GetSize(); i++)
  313. {
  314. temp = rulearray.ElementAt(i);
  315. int pos = temp.Find(" ");
  316. temp = temp.Left(pos);
  317. pos = temp.Find("-");
  318. money1 = atoi(temp.Left(pos));
  319. money2 = atoi(temp.Right(temp.GetLength() - pos - 1));
  320. if ((i == rulearray.GetSize() - 1) || (fmoney >= money1 && fmoney <= money2))
  321. {
  322. temp = rulearray.ElementAt(i);
  323. pos = temp.Find(":");
  324. temp = temp.Right(temp.GetLength() - pos - 1);
  325. temp.TrimRight("%");
  326. frate = atof(temp) / 100.0;
  327. float dtmoney = fmoney - money1;
  328. fresult += frate*dtmoney;
  329. if (i == 0)//只有一条规则
  330. {
  331. fresult = frate*fmoney;
  332. return fresult;
  333. }
  334. while (i)
  335. {
  336. i--;
  337. temp = rulearray.ElementAt(i);
  338. pos = temp.Find(" ");
  339. temp = temp.Left(pos);
  340. pos = temp.Find("-");
  341. money1 = atoi(temp.Left(pos));
  342. money2 = atoi(temp.Right(temp.GetLength() - pos - 1));
  343. temp = rulearray.ElementAt(i);
  344. pos = temp.Find(":");
  345. temp = temp.Right(temp.GetLength() - pos - 1);
  346. temp.TrimRight("%");
  347. frate = atof(temp) / 100.0;
  348. dtmoney = money2 - money1;
  349. fresult += frate*dtmoney;
  350. }
  351. return fresult;
  352. }
  353. }
  354. }
  355. return fresult;
  356. }
  357. /*
  358. float GetSalaryFromRule(float fmoney, CString rule)
  359. {
  360. float fresult=0;
  361. int pos=rule.Find (":");
  362. if(pos==-1)return 0;
  363. rule=rule.Right (rule.GetLength ()-pos-1);
  364. CStringArray rulearray;
  365. pos=rule.Find (";");
  366. while(pos!=-1)
  367. {
  368. rulearray.Add (rule.Left (pos));
  369. rule=rule.Right (rule.GetLength ()-pos-1);
  370. pos=rule.Find (";");
  371. }
  372. BOOL check1=atoi(rule);
  373. if(rulearray.GetSize ()==0)return 0;
  374. CString str,temp;
  375. int money1,money2;
  376. float frate;
  377. for(int i=0; i<rulearray.GetSize (); i++)
  378. {
  379. temp=rulearray.ElementAt (i);
  380. int pos=temp.Find(" ");
  381. temp=temp.Left(pos);
  382. pos=temp.Find("-");
  383. money1=atoi(temp.Left(pos));
  384. money2=atoi(temp.Right(temp.GetLength()-pos-1));
  385. if( (i==rulearray.GetSize ()-1) || (fmoney>=money1 && fmoney<=money2) )
  386. {
  387. temp=rulearray.ElementAt (i);
  388. pos=temp.Find (":");
  389. temp=temp.Right (temp.GetLength ()-pos-1);
  390. temp.TrimRight ("%");
  391. frate=atof(temp)/100.0;
  392. if(check1 && i>0)
  393. {
  394. temp=rulearray.ElementAt (i-1);
  395. pos=temp.Find (":");
  396. temp=temp.Right (temp.GetLength ()-pos-1);
  397. temp.TrimRight ("%");
  398. float frate2=atof(temp)/100.0;
  399. fresult=(money1-1)*frate2+frate*(fmoney-money1+1);
  400. }
  401. else
  402. {
  403. fresult=frate*fmoney;
  404. }
  405. return fresult;
  406. }
  407. }
  408. return fresult;
  409. }
  410. */
  411. void SalarySet4::OnButton2()
  412. {
  413. // TODO: Add your control notification handler code here
  414. UpdateData();
  415. if (m_testmoney < 1)
  416. {
  417. m_testmoney = 100000;
  418. UpdateData(0);
  419. }
  420. CString rule = GetRule();
  421. float fresult = GetSalaryFromRule(m_testmoney, rule);
  422. CString temp;
  423. temp.Format("%0.2f", fresult);
  424. SetDlgItemText(IDC_EDIT4, temp);
  425. /* CString str,temp;
  426. int money1,money2;
  427. float frate;
  428. for(int i=0; i<m_list1.GetCount (); i++)
  429. {
  430. m_list1.GetText (i, temp);
  431. int pos=temp.Find(" ");
  432. temp=temp.Left(pos);
  433. pos=temp.Find("-");
  434. money1=atoi(temp.Left(pos));
  435. money2=atoi(temp.Right(temp.GetLength()-pos-1));
  436. if( (i==m_list1.GetCount ()-1) || (m_testmoney>=money1 && m_testmoney<=money2) )
  437. {
  438. m_list1.GetText (i, temp);
  439. pos=temp.Find (":");
  440. temp=temp.Right (temp.GetLength ()-pos-1);
  441. temp.TrimRight ("%");
  442. frate=atof(temp)/100.0;
  443. float fresult;
  444. if(m_check1 && i>0)
  445. {
  446. m_list1.GetText (i-1, temp);
  447. pos=temp.Find (":");
  448. temp=temp.Right (temp.GetLength ()-pos-1);
  449. temp.TrimRight ("%");
  450. float frate2=atof(temp)/100.0;
  451. fresult=(money1-1)*frate2+frate*(m_testmoney-money1+1);
  452. }
  453. else
  454. {
  455. fresult=frate*m_testmoney;
  456. }
  457. temp.Format ("%0.2f", fresult);
  458. SetDlgItemText(IDC_EDIT4, temp);
  459. return;
  460. }
  461. }
  462. AfxMessageBox("请先设规则!", MB_ICONINFORMATION);*/
  463. }
  464. CString SalarySet4::GetRule()
  465. {
  466. CString str, temp;
  467. str = m_header;//"$前期:";
  468. for (int i = 0; i < m_list1.GetCount(); i++)
  469. {
  470. m_list1.GetText(i, temp);
  471. str += temp;
  472. str += ";";
  473. }
  474. temp.Format("%d", m_check1);
  475. str += temp;
  476. return str;
  477. }
  478. void SalarySet4::OnButton14()
  479. {
  480. // TODO: Add your control notification handler code here
  481. SelExpendType seldlg;
  482. seldlg.m_mode = 1;
  483. seldlg.m_bSecond = 1;
  484. if (seldlg.DoModal() != IDOK)return;
  485. CString oldrule = g_cominfoarray.ElementAt(0).ElementAt(77);
  486. CString header = "$" + seldlg.m_sel + ":";
  487. CString left, right;
  488. int pos = oldrule.Find(header);
  489. if (pos != -1)
  490. {
  491. right = oldrule.Right(oldrule.GetLength() - pos - header.GetLength());
  492. pos = right.Find("$");
  493. if (pos != -1)
  494. right = right.Left(pos);
  495. InitRule(right);
  496. }
  497. else
  498. {
  499. AfxMessageBox(seldlg.m_sel + "未设置规则!", MB_ICONINFORMATION);
  500. }
  501. }
  502. void SalarySet4::InitRule(CString str)
  503. {
  504. m_list1.ResetContent();
  505. int pos = str.Find(";");
  506. while (pos != -1)
  507. {
  508. m_list1.AddString(str.Left(pos));
  509. str = str.Right(str.GetLength() - pos - 1);
  510. pos = str.Find(";");
  511. }
  512. m_check1 = atoi(str);
  513. UpdateData(false);
  514. }