SalarySet4.cpp 12 KB

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