SalarySet4.cpp 13 KB

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