1. C++常用代码总结(3)

 
// 为设备环境句柄设置颜色
HBRUSH CContentsSubmitDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
     {
         HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
         int ctrid=pWnd->GetDlgCtrlID();
         if(ctrid==IDC_EDIT4)// 则IDC_EDIT4的颜色为下面的颜色
              {            
                       pDC->SetTextColor(RGB(0,0,255));  
                       pDC->SetBkMode(OPAQUE); 
                       pDC->SetBkColor(RGB(255,255,255));
                       return   brushBlack;
               }  
         return hbr;
     }
 
// 组合框选中事件
void CContentsSubmitDlg::OnCbnSelchangeCombo1()
     {
         int nsel1=m_belong.GetCurSel();
         switch (nsel1)
         {
         case 0 :
              m_ProjectName.ResetContent();
              m_ProjectName.AddString(" 数据抓取程序开发");
              break;
         case 1:
              m_ProjectName.ResetContent();
              m_ProjectName.AddString(" 网络架设");
              break;
         default:
              m_ProjectName.ResetContent();
              m_ProjectName.AddString(" 您没有选择团队");
         }
      }
// 统计工作内容编辑框控件输入的行数 ( 回车符表示换行 ), 并将每行中以 - 号为分割符的内容写入到数据库中
void CContentsSubmitDlg::OnBnClickedButton1()
{    UpdateData(true);
CString workcontents,employees,scheduals,completedates,departments,teams,projects,
projecttimes ,weeks;
         workcontents=this->m_workcontents;
         employees=this->m_employee;
         projecttimes=this->m_projecttime;
         GetDlgItem(IDC_EDIT1)->GetWindowText(m_vdepartment);
         departments=m_vdepartment;
         //**************** 处理工作内容
         CString strSrc =m_workcontents,strSrc1=m_workcontents;
         strSrc.TrimLeft(" ");     
         strSrc.TrimRight(" ");
         strSrc.TrimRight(" ");
         strSrc.TrimRight(" ");
         strSrc.TrimRight("/t");
         int countn=0;// 统计工作内容的条数,以换行符号为标记
         int pos;///n 的位置      int pos1;//- 的位置
         int k;
         CString contents1[10];// 考虑到每个人提报最多内容不会超过10条,该数组用来存储每一行         for(int j=0;;j++)
         {
              pos=strSrc.FindOneOf("/n");
              if(pos!=-1)
              {
                   countn++;
              }
              else
              {                  break;
              }
              contents1[j]=strSrc.Left(pos);// 将值存储到该数组[]
              strSrc=strSrc.Right(strSrc.GetLength()-pos-1);
         }
         countn=countn+1;// 条数=count+1
         CString contents[10];
         CString resultcontents[10][3];// 用该2维数组存储每条中每项的值
         for(k=0;k<countn-1;k++)
         {
              pos=strSrc1.FindOneOf("/n");
              contents[k]=strSrc1.Left(pos);
              pos1=contents[k].FindOneOf("-");
              resultcontents[k][0]=contents[k].Left(pos1);
              contents[k]=contents[k].Right(contents[k].GetLength()-pos1-1);
              pos1=contents[k].FindOneOf("-");
              resultcontents[k][1]=contents[k].Left(pos1);
              contents[k]=contents[k].Right(contents[k].GetLength()-pos1-1);
              pos1=contents[k].FindOneOf("-");
              resultcontents[k][2]=contents[k];
              strSrc1=strSrc1.Right(strSrc1.GetLength()-pos-1);
         }
// 专门处理最后一行
         pos1=strSrc1.FindOneOf("-");
         resultcontents[k][0]=strSrc1.Left(pos1);
         strSrc1=strSrc1.Right(strSrc1.GetLength()-pos1-1);
         pos1=strSrc1.FindOneOf("-");
         resultcontents[k][1]=strSrc1.Left(pos1);
         strSrc1=strSrc1.Right(strSrc1.GetLength()-pos1-1);
         pos1=strSrc1.FindOneOf("-");
         resultcontents[k][2]=strSrc1;
         int nsel=m_belong.GetCurSel();
         if (nsel==CB_ERR)
         {   
              AfxMessageBox(" 没有选团队名称");
         return;
         }
         m_belong.GetLBText(nsel,m_vbelong);
         int nsel1=m_week.GetCurSel();
         if (nsel1==CB_ERR)
         {
              AfxMessageBox(" 没有选周会梯次");
              return;
         }
         m_week.GetLBText(nsel1,m_vweek);
 
         int nsel2=m_ProjectName.GetCurSel();
         if(nsel2==CB_ERR)
         {
              AfxMessageBox(" 没有选项目名称");
              return;
         }
         m_ProjectName.GetLBText(nsel2,m_vprojectname);
          if((workcontents=="")||(this->m_employee=="")||(projecttimes==""))
         {
              AfxMessageBox(" 您所提报的信息不完整");
              return;
         }
         else
         {                          
ADOconn m_conn;             _bstr_t vSQL="";
CString s_Conn="Provider=SQLOLEDB;Server=10.128.128.221;Database=Eink;uid=stone;pwd=stone";
for (int l=0;l<countn;l++)// 将每行分割后写入到数据库中
{
vSQL ="insert into contens(department,week,team,project,employee,projecttime,workcontents,
schedule,completedate) values('"+departments+"','"+m_vweek+"','"+m_vbelong+"','"
+m_vprojectname+"','"+employees+"','"+projecttimes+"','"+resultcontents[l][0]+"','"
+resultcontents[l][1]+"','"+resultcontents[l][2]+"')";
try
{m_conn.OnInitADOConn(s_Conn);            m_conn.ExcuteSQL(vSQL);              }
catch (...)
{    AfxMessageBox(" 数据库写入错误",MB_OK);                  }
}
m_conn .ExitConnect();
AfxMessageBox (" 补充周报内容成功",MB_OK);
}
}
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值