SalarySet4.cpp 12 KB

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