// SalarySet4.cpp : implementation file // #include "stdafx.h" #include "ylgl.h" #include "SalarySet4.h" #include "SelExpendType.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // SalarySet4 dialog SalarySet4::SalarySet4(CWnd* pParent /*=NULL*/) : CDialog(SalarySet4::IDD, pParent) { //{{AFX_DATA_INIT(SalarySet4) m_money1 = 0; m_money2 = 0; m_rate = 0.0f; m_check1 = FALSE; m_testmoney = 0.0f; //}}AFX_DATA_INIT } void SalarySet4::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(SalarySet4) DDX_Control(pDX, IDC_EDIT8, m_numctrl4); DDX_Control(pDX, IDC_LIST1, m_list1); DDX_Control(pDX, IDC_EDIT3, m_numctrl3); DDX_Control(pDX, IDC_EDIT2, m_numctrl2); DDX_Control(pDX, IDC_EDIT1, m_numctrl1); DDX_Text(pDX, IDC_EDIT1, m_money1); DDX_Text(pDX, IDC_EDIT2, m_money2); DDX_Text(pDX, IDC_EDIT3, m_rate); DDX_Check(pDX, IDC_CHECK1, m_check1); DDX_Text(pDX, IDC_EDIT8, m_testmoney); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(SalarySet4, CDialog) //{{AFX_MSG_MAP(SalarySet4) ON_BN_CLICKED(IDC_BUTTON1, OnAdd) ON_BN_CLICKED(IDC_BUTTON3, OnButton3) ON_BN_CLICKED(IDC_BUTTON2, OnButton2) ON_BN_CLICKED(IDC_BUTTON14, OnButton14) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // SalarySet4 message handlers BOOL SalarySet4::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here if (IsHasRights2new(25) == 0) { GetDlgItem(IDOK)->EnableWindow(0); } CString str = g_cominfoarray.ElementAt(0).ElementAt(77); int pos = str.Find(m_header); int headleng = m_header.GetLength(); if (pos != -1) { str = str.Right(str.GetLength() - pos); str.Delete(0, headleng); pos = str.Find("$"); if (pos != -1) str = str.Left(pos); InitRule(str); } str = m_header; str.TrimLeft("$"); str.TrimRight(":"); SetWindowText("阶梯提成方案-" + str); ////////////////////////////////////////////////////// g_sendhead.bsql = 0; g_sendhead.code[0] = 160; g_sendhead.code[1] = 169; g_sendhead.tabcount = 2; g_pMainWnd->ProcessChatMessageRequest2(1); if (g_bSendOK == 0) { CDialog::OnCancel(); return 0; } CArrayexpendtypearray; CArraybaseexpendtypearray; DataToArray(&expendtypearray, &baseexpendtypearray); int i = 0; for ( i = 0; i < baseexpendtypearray.GetSize(); i++) { m_expendtypearray.Add(baseexpendtypearray.ElementAt(i).ElementAt(0)); } for (i = 0; i < expendtypearray.GetSize(); i++) { m_expendtypearray.Add(expendtypearray.ElementAt(i).ElementAt(0)); } m_expendtypearray.Add("摄影二销"); #ifdef CHILD_VERSION m_expendtypearray.Add("引导二销"); #else m_expendtypearray.Add("化妆二销"); #endif // CHILD_VERSION m_expendtypearray.Add("选片二销"); m_expendtypearray.Add("摄影选片二销"); #ifdef CHILD_VERSION m_expendtypearray.Add("引导选片二销"); #else m_expendtypearray.Add("化妆选片二销"); #endif // CHILD_VERSION CenterWindow(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void SalarySet4::OnAdd() { // TODO: Add your control notification handler code here UpdateData(); if (CheckRange() == 0) return; CString str, temp; if (m_money1 >= m_money2) { AfxMessageBox("业绩范围出错!", MB_ICONINFORMATION); return; } if (m_list1.GetCount() == 0 && m_money1 != 0) { AfxMessageBox("起始业绩应从0开始!", MB_ICONINFORMATION); return; } str.Format("%d-%d 提:%0.1f", m_money1, m_money2, m_rate); str += "%"; for (int i = 0; i < m_list1.GetCount(); i++) { m_list1.GetText(i, temp); if (str == temp) { AfxMessageBox("已有此规则!", MB_ICONINFORMATION); return; } } m_list1.AddString(str); } BOOL SalarySet4::CheckRange() { CString str, temp; int money1, money2; for (int i = 0; i < m_list1.GetCount(); i++) { m_list1.GetText(i, temp); int pos = temp.Find(" "); temp = temp.Left(pos); pos = temp.Find("-"); money1 = atoi(temp.Left(pos)); money2 = atoi(temp.Right(temp.GetLength() - pos - 1)); if (m_money1 >= money1 && m_money1 <= money2) { AfxMessageBox("起始业绩已包含在已有的规则中!", MB_ICONINFORMATION); return 0; } if (m_money2 >= money1 && m_money2 <= money2) { AfxMessageBox("终止业绩已包含在已有的规则中!", MB_ICONINFORMATION); return 0; } } if (m_list1.GetCount()) { m_list1.GetText(m_list1.GetCount() - 1, temp); int pos = temp.Find(" "); temp = temp.Left(pos); pos = temp.Find("-"); money2 = atoi(temp.Right(temp.GetLength() - pos - 1)); if (m_money1 != money2 + 1) { AfxMessageBox("业绩段不连续,起始业绩应比上一规则段终止业绩大1", MB_ICONINFORMATION); return 0; } } return 1; } void SalarySet4::OnButton3() { // TODO: Add your control notification handler code here if (AfxMessageBox("确定要删除全部规则吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return; m_list1.ResetContent(); } void SalarySet4::OnOK() { // TODO: Add extra validation here UpdateData(); CString str, temp; str = m_header; for (int i = 0; i < m_list1.GetCount(); i++) { m_list1.GetText(i, temp); str += temp; str += ";"; } temp.Format("%d", m_check1); str += temp; CString oldrule = g_cominfoarray.ElementAt(0).ElementAt(77); CString left, right; int pos = oldrule.Find(m_header); if (pos != -1) { left = oldrule.Left(pos); right = oldrule.Right(oldrule.GetLength() - pos - m_header.GetLength()); pos = right.Find("$"); if (pos != -1) right = right.Right(right.GetLength() - pos); else right.Empty(); str = left + str + right; } else str += oldrule; CString name; temp.Empty(); pos = str.Find("$"); while (pos != -1) { int pos2 = str.Find(":"); name = str.Mid(pos + 1, pos2 - pos - 1); BOOL bFind = 0; for (int i = 0; i < m_expendtypearray.GetSize(); i++) { if (name == m_expendtypearray.ElementAt(i)) { bFind = 1; break; } } if (bFind) { temp += str.Left(pos2); str = str.Right(str.GetLength() - pos2); pos = str.Find("$"); if (pos != -1) { temp += str.Left(pos); str = str.Right(str.GetLength() - pos); } else temp += str; pos = str.Find("$"); } else { str = str.Right(str.GetLength() - pos2); pos = str.Find("$"); if (pos != -1) { str = str.Right(str.GetLength() - pos); } pos = str.Find("$"); } } str = temp; //$摄影师前期:0-1000 提:1.0%;0$门市前期:0-1000 提:1.0%;0$摄影二消:0$前期:0$化妆二消:0$选片二消:1 // m_expendtypearray CString sql; sql.Format("update version set [salaryset]='%s'", str); g_sendhead.bsql = 1; g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return; AfxMessageBox("保存成功!", MB_ICONINFORMATION); g_cominfoarray.ElementAt(0).SetAt(77, str); CDialog::OnOK(); } float GetSalaryFromRule(float fmoney, CString rule) { float fresult = 0; int pos = rule.Find(":"); if (pos == -1)return 0; rule = rule.Right(rule.GetLength() - pos - 1); CStringArray rulearray; pos = rule.Find(";"); while (pos != -1) { rulearray.Add(rule.Left(pos)); rule = rule.Right(rule.GetLength() - pos - 1); pos = rule.Find(";"); } BOOL check1 = atoi(rule); if (rulearray.GetSize() == 0)return 0; CString str, temp; int money1, money2; float frate; if (check1 == 0) { for (int i = 0; i < rulearray.GetSize(); i++) { temp = rulearray.ElementAt(i); int pos = temp.Find(" "); temp = temp.Left(pos); pos = temp.Find("-"); money1 = atoi(temp.Left(pos)); money2 = atoi(temp.Right(temp.GetLength() - pos - 1)); if ((i == rulearray.GetSize() - 1) || (fmoney >= money1 && fmoney <= money2)) { temp = rulearray.ElementAt(i); pos = temp.Find(":"); temp = temp.Right(temp.GetLength() - pos - 1); temp.TrimRight("%"); frate = atof(temp) / 100.0; fresult = frate*fmoney; return fresult; } } } else////// { for (int i = 0; i < rulearray.GetSize(); i++) { temp = rulearray.ElementAt(i); int pos = temp.Find(" "); temp = temp.Left(pos); pos = temp.Find("-"); money1 = atoi(temp.Left(pos)); money2 = atoi(temp.Right(temp.GetLength() - pos - 1)); if ((i == rulearray.GetSize() - 1) || (fmoney >= money1 && fmoney <= money2)) { temp = rulearray.ElementAt(i); pos = temp.Find(":"); temp = temp.Right(temp.GetLength() - pos - 1); temp.TrimRight("%"); frate = atof(temp) / 100.0; float dtmoney = fmoney - money1; fresult += frate*dtmoney; if (i == 0)//只有一条规则 { fresult = frate*fmoney; return fresult; } while (i) { i--; temp = rulearray.ElementAt(i); pos = temp.Find(" "); temp = temp.Left(pos); pos = temp.Find("-"); money1 = atoi(temp.Left(pos)); money2 = atoi(temp.Right(temp.GetLength() - pos - 1)); temp = rulearray.ElementAt(i); pos = temp.Find(":"); temp = temp.Right(temp.GetLength() - pos - 1); temp.TrimRight("%"); frate = atof(temp) / 100.0; dtmoney = money2 - money1; fresult += frate*dtmoney; } return fresult; } } } return fresult; } /* float GetSalaryFromRule(float fmoney, CString rule) { float fresult=0; int pos=rule.Find (":"); if(pos==-1)return 0; rule=rule.Right (rule.GetLength ()-pos-1); CStringArray rulearray; pos=rule.Find (";"); while(pos!=-1) { rulearray.Add (rule.Left (pos)); rule=rule.Right (rule.GetLength ()-pos-1); pos=rule.Find (";"); } BOOL check1=atoi(rule); if(rulearray.GetSize ()==0)return 0; CString str,temp; int money1,money2; float frate; for(int i=0; i=money1 && fmoney<=money2) ) { temp=rulearray.ElementAt (i); pos=temp.Find (":"); temp=temp.Right (temp.GetLength ()-pos-1); temp.TrimRight ("%"); frate=atof(temp)/100.0; if(check1 && i>0) { temp=rulearray.ElementAt (i-1); pos=temp.Find (":"); temp=temp.Right (temp.GetLength ()-pos-1); temp.TrimRight ("%"); float frate2=atof(temp)/100.0; fresult=(money1-1)*frate2+frate*(fmoney-money1+1); } else { fresult=frate*fmoney; } return fresult; } } return fresult; } */ void SalarySet4::OnButton2() { // TODO: Add your control notification handler code here UpdateData(); if (m_testmoney < 1) { m_testmoney = 100000; UpdateData(0); } CString rule = GetRule(); float fresult = GetSalaryFromRule(m_testmoney, rule); CString temp; temp.Format("%0.2f", fresult); SetDlgItemText(IDC_EDIT4, temp); /* CString str,temp; int money1,money2; float frate; for(int i=0; i=money1 && m_testmoney<=money2) ) { m_list1.GetText (i, temp); pos=temp.Find (":"); temp=temp.Right (temp.GetLength ()-pos-1); temp.TrimRight ("%"); frate=atof(temp)/100.0; float fresult; if(m_check1 && i>0) { m_list1.GetText (i-1, temp); pos=temp.Find (":"); temp=temp.Right (temp.GetLength ()-pos-1); temp.TrimRight ("%"); float frate2=atof(temp)/100.0; fresult=(money1-1)*frate2+frate*(m_testmoney-money1+1); } else { fresult=frate*m_testmoney; } temp.Format ("%0.2f", fresult); SetDlgItemText(IDC_EDIT4, temp); return; } } AfxMessageBox("请先设规则!", MB_ICONINFORMATION);*/ } CString SalarySet4::GetRule() { CString str, temp; str = m_header;//"$前期:"; for (int i = 0; i < m_list1.GetCount(); i++) { m_list1.GetText(i, temp); str += temp; str += ";"; } temp.Format("%d", m_check1); str += temp; return str; } void SalarySet4::OnButton14() { // TODO: Add your control notification handler code here SelExpendType seldlg; seldlg.m_mode = 1; seldlg.m_bSecond = 1; if (seldlg.DoModal() != IDOK)return; CString oldrule = g_cominfoarray.ElementAt(0).ElementAt(77); CString header = "$" + seldlg.m_sel + ":"; CString left, right; int pos = oldrule.Find(header); if (pos != -1) { right = oldrule.Right(oldrule.GetLength() - pos - header.GetLength()); pos = right.Find("$"); if (pos != -1) right = right.Left(pos); InitRule(right); } else { AfxMessageBox(seldlg.m_sel + "未设置规则!", MB_ICONINFORMATION); } } void SalarySet4::InitRule(CString str) { m_list1.ResetContent(); int pos = str.Find(";"); while (pos != -1) { m_list1.AddString(str.Left(pos)); str = str.Right(str.GetLength() - pos - 1); pos = str.Find(";"); } m_check1 = atoi(str); UpdateData(false); }