数据库开发(2)

#if !defined(AFX_GlobalFuntion_H__26B3816F_5D75_4DF4_BAD6_79DEB8624CAC__INCLUDED_)
#define AFX_GlobalFuntion_H__26B3816F_5D75_4DF4_BAD6_79DEB8624CAC__INCLUDED_
#include "ListReport.h"
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
//#include "MainFrm.h"
typedef CArray<int, int> IntArray;
typedef CArray<float, float> FloatArray;
/////////////////////////////////////////////////////////////////////////////
class GlobalFuntion{
public:
 GlobalFuntion();   // standard constructor
 void  GetErrorTitle(CString errorCode);
 void  GetFindData(CString& m_findSql,CStringArray& m_rtData);
 int   SetLabelText(HWND m_CurrWnd,CString& m_ModelCode);
 int   SetPmariKey(CString m_ModelCode,IntArray& m_primaryArry);
 int   UpdateData(CString& m_UpdateSql);
 void  SetMyMenu(CMenu* m_cMenu);
 void  SetTreeMenu();
 void  SetDataGridCaption(HWND m_hwnParent,CString& m_modelCode,UINT m_Id,int m_type,int beginCol=0,int endCol=0);
 void  SetDataGridCaption(CString& m_modelCode,CDataGrid* m_Id,int beginCol=0,int endCol=0);
 BOOL  InitListData(HWND m_hwnParent,CString&  m_initSql,UINT m_id) ;
 void  SetCtrEnable(HWND m_pHwnd, IntArray& m_ctrId, BOOL m_state,CStringArray& m_initValue);
 void  GetCtrText(HWND m_pHwnd, IntArray& m_ctrId,CStringArray& m_initValue);
 int InputFloat(char* buffer,int leng);
 int SetPopedMenu(UINT m_menuId);
 void SetMenuDisible(int m_index,int m_type,IntArray& m_menuArray);
 void SetListCaption(CString& m_modelCode,CMyListCheckBox *m_pList,IntArray& m_colWidth,int beginCol=0,int endCol=0);
 BOOL InitListData(CStringArray&  m_Array,CMyListCheckBox *m_pList,IntArray& m_checkBoxArray) ;
 int  CheckData(_RecordsetPtr retSet,IntArray& m_col);
 void  GetColTotleData(_RecordsetPtr retSet,int m_col,FloatArray& refloatArray);

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_GlobalFuntion_H__26B3816F_5D75_4DF4_BAD6_79DEB8624CAC__INCLUDED_)
};

#include "stdafx.h"
#include "GlobalFuntion.h"
#include "HoKaiTps.h"
#include "MainFrm.h"
#include <afxwin.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CC3DDlgProperty dialog
/*
rs.CursorLocation = adUseClient
//m_Grid.SetRefDataSource(NULL);  
//  m_Grid.SetRefDataSource((LPUNKNOWN)m_pRecordset);  
//  m_Grid.Refresh();  
*/

extern CHoKaiTpsApp theApp;
GlobalFuntion::GlobalFuntion()
{
}
void  GlobalFuntion::SetCtrEnable(HWND m_pHwnd, IntArray& m_ctrId, BOOL m_state,CStringArray& m_initValue)
{
 for(int loop=0;loop<m_ctrId.GetSize();loop++)
   {
  CWnd* m_ctrWnd=CWnd::FromHandle(GetDlgItem(m_pHwnd,m_ctrId.GetAt(loop)));
  if(m_initValue.GetSize()>0 && loop<m_initValue.GetSize())
  m_ctrWnd->SetWindowText(m_initValue.GetAt(loop));
     m_ctrWnd->EnableWindow(m_state);
   }
  
}
int GlobalFuntion::InputFloat(char* buffer,int leng)
{
  int sign = 0;
  int judgeDot = 0;
  if (buffer[0] == '-')    // 判断是否有负号
    sign = 1;
  for (int i = sign;i<leng; i++)                   // 判断小数点的个数,是多只能有一个
  {
    if (buffer[i] == '.')
    {
      if(++judgeDot>1)
      {
        return 1;
      }
    }
  }
  for (int i = sign;i<leng; i++)                   // 只能输入数字和小数点
  {
    if(!((buffer[i] >= '0' && buffer[i]<= '9') || buffer[i] == '.' || buffer[i] == '/0'))
    {
      return 2;
    }
  }
  //if ((float)atof(buffer) > 10.0 || (float)atof(buffer) < -10.0)    //取值范围
  //{
  //  return 3;
 // }
  if(sign==1)
   return 2;
  else
    return 0;
} //判断输入是否为浮点数
//
void  GlobalFuntion::GetCtrText(HWND m_pHwnd, IntArray& m_ctrId,CStringArray& m_initValue)
{
   m_initValue.RemoveAll();
   for(int loop=0;loop<m_ctrId.GetSize();loop++)
   {
  CWnd* m_ctrWnd=CWnd::FromHandle(GetDlgItem(m_pHwnd,m_ctrId.GetAt(loop)));
  CString m_currValue;
  m_ctrWnd->GetWindowText(m_currValue);
  m_initValue.Add(m_currValue);
   }
  
}
//
void  GlobalFuntion::GetErrorTitle(CString errorCode)
{
    _RecordsetPtr m_pSet;
 CString   m_errValue;
 _variant_t  m_VerrValue;
 CString sql="select error_title,error_name  from  error where error_code='"+errorCode+"'";
 m_pSet.CreateInstance("ADODB.Recordset");
 m_pSet->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConn,true),adOpenStatic,adLockOptimistic,adCmdText);
 if (!m_pSet->adoEOF)
 {
 
 // m_VerrValue=(LPCTSTR)(_bstr_t)m_pSet->GetCollect("error_title");
  theApp.m_errArray[0]=(LPCTSTR)(_bstr_t)m_pSet->GetCollect("error_title");
 // m_VerrValue=m_pSet->GetCollect("");
 // m_errValue.Format("%s",m_VerrValue->pbstrVal);
  theApp.m_errArray[1]=(LPCTSTR)(_bstr_t)m_pSet->GetCollect("error_name");
 }
 else
 {
  AfxMessageBox("没有找到错误码代码!");
 }
 m_pSet->Close();
// m_pSet->Release();
}

void   GlobalFuntion::GetFindData(CString& m_findSql,CStringArray& m_rtData)
{
    try
 {
  int  m_colCount=0;
  _variant_t m_colValue;
  _RecordsetPtr m_pSet;
  CString  m_null="";
  m_pSet.CreateInstance("ADODB.Recordset");
  m_pSet->Open((_variant_t)m_findSql,_variant_t((IDispatch*)theApp.m_pConn,true),adOpenStatic,adLockOptimistic,adCmdText);
  m_colCount=m_pSet->Fields->GetCount();
  while (!m_pSet->adoEOF)
  {
   for(int loop=0;loop<m_colCount;loop++)
   {
    m_colValue=m_pSet->Fields->Item[(long)loop]->Value;
    if (m_colValue.vt!=VT_NULL)
    {
    // CString strTrans;
    // strTrans.Format("%s",m_colValue.bstrVal);
     m_rtData.Add((LPCSTR)(_bstr_t)m_colValue);
    }
    else
    {
     m_rtData.Add((LPCSTR)m_null);
    }
   }
   m_pSet->MoveNext();
  }
  m_pSet->Close();
  m_pSet=NULL;
 // m_pSet->Release();
 }
 catch(_com_error e)///捕捉异常
 {
  CString temp;
  temp.Format("查找数据错误:%s",e.ErrorMessage());
  AfxMessageBox(temp);
 //   if   (e.Number   ==   2627)  
    //    Message.InnerHtml   =   "错误:已存在具有相同主键的记录";  

 }
}


int   GlobalFuntion::UpdateData(CString& m_UpdateSql)
{
    int  m_ruturn=0;
 try
 {
  variant_t RecordsAffected;
  theApp.m_pConn->Execute((_bstr_t)m_UpdateSql,&RecordsAffected,adCmdText);
  VariantClear (&RecordsAffected);
  m_ruturn=1;
 }
 catch(_com_error e)///捕捉异常
 {
  CString temp;
  temp.Format("%s",e.ErrorMessage());
  AfxMessageBox(temp);
  m_ruturn=0;
 }
 return m_ruturn;
}
int   GlobalFuntion::SetPmariKey(CString m_ModelCode,IntArray& m_primaryArry)
{
 _RecordsetPtr m_pSetText;
 /*and  ( ctr_isTable='1') and*/
 try
 {
  CString sql="select ctr_id  from  base_model_ctr where parent_model_code='"+m_ModelCode+"' and (ctr_isPrimary='1' or ctr_isNUll='1')";
  m_pSetText.CreateInstance("ADODB.Recordset");
  m_pSetText->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConn,true),adOpenStatic,adLockOptimistic,adCmdText);
     while (!m_pSetText->adoEOF)
  {
   m_primaryArry.Add((long)m_pSetText->GetCollect("ctr_id"));
   m_pSetText->MoveNext();
  }
  m_pSetText->Close();
  
  //m_pSetText->Release();
 } 
 catch(_com_error e)///捕捉异常
 {
   CString temp;
   temp.Format("读取用户名和密码错误:%s",e.ErrorMessage());
   AfxMessageBox(temp);
   return 0;
 }
 return 1;
}

int   GlobalFuntion::SetLabelText(HWND m_CurrWnd,CString& m_ModelCode)
{
 _RecordsetPtr m_pSetText;
 try
 {
  CString sql="select ctr_id,ctr_name,ctr_type,ctr_disp_format,ctr_align  from  base_model_ctr where parent_model_code='"+m_ModelCode+"'";
  m_pSetText.CreateInstance("ADODB.Recordset");
  m_pSetText->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConn,true),adOpenStatic,adLockOptimistic,adCmdText);
     while (!m_pSetText->adoEOF)
  {
   int m_CtrId=(long)m_pSetText->GetCollect("ctr_id");
   int m_ctrType=(long)m_pSetText->GetCollect("ctr_type");
   CString m_LabelText=(LPCSTR)(_bstr_t)m_pSetText->GetCollect("ctr_name");
   HWND aa=GetDlgItem(m_CurrWnd,m_CtrId);
   SetDlgItemText(m_CurrWnd,m_CtrId,m_LabelText);
   m_pSetText->MoveNext();
  }
  m_pSetText->Close();
  
  //m_pSetText->Release();
 } 
 catch(_com_error e)///捕捉异常
 {
   CString temp;
   temp.Format("读取用户名和密码错误:%s",e.ErrorMessage());
   AfxMessageBox(temp);
   return 0;
 }
 return 1;
}    
void GlobalFuntion::SetMyMenu(CMenu* m_cMenu)
{
 ((CMainFrame*)theApp.m_pMainWnd)->GetMenu()->DeleteMenu(0,MF_BYPOSITION);
 ((CMainFrame*)theApp.m_pMainWnd)->GetMenu()->DeleteMenu(0,MF_BYPOSITION);
 /////////////////
 CStringArray m_menuArrayStr;
 CString   m_menuSql;
 CStringArray m_sonMenuArrayStr;
 int    m_pCount;
 int    m_sCount;
 int    m_pMenuId;
 CString   m_sonMenuStr;
 CString   m_sonMenuCode;
    CString         m_pMenuStr;
 int             m_indexMenu=0;
 CString         m_subType;
 m_menuSql="SELECT son_name, son_code FROM base_Menu WHERE parent_code='00000'";
    GetFindData(m_menuSql,m_menuArrayStr);
 m_pCount=m_menuArrayStr.GetSize();
 for (int loop=0;loop<m_pCount;loop++)
 {
  m_cMenu->CreatePopupMenu();
  m_pMenuStr=m_menuArrayStr.GetAt(loop);
 // theApp.m_pMainWnd->GetMenu()->InsertMenu(m_indexMenu,MF_BYPOSITION|MF_POPUP,(UINT)m_cMenu->m_hMenu,m_pMenuStr);
  ((CMainFrame*)theApp.m_pMainWnd)->GetMenu()->AppendMenu(MF_POPUP,(UINT)m_cMenu->m_hMenu,m_pMenuStr);
  m_sonMenuCode=m_menuArrayStr.GetAt(loop+1);
  loop=loop+1;
  m_menuSql="select son_name,son_id,menu_type  from base_menu  where  parent_code='"+m_sonMenuCode+"'";
  GetFindData(m_menuSql,m_sonMenuArrayStr);
  m_sCount=m_sonMenuArrayStr.GetSize();
  for (int m_index=0;m_index<m_sCount;m_index++)
  {
   m_sonMenuStr=m_sonMenuArrayStr.GetAt(m_index);
   m_pMenuId=atoi(m_sonMenuArrayStr.GetAt(m_index+1));
   m_index=m_index+2;
   m_subType=m_sonMenuArrayStr.GetAt(m_index);
   
   if(m_sonMenuStr=="-")
   {
    m_cMenu->AppendMenu(MF_SEPARATOR);
   }
   else if (m_subType=="8")
   {
    m_cMenu->AppendMenu(MF_STRING|MF_CHECKED,m_pMenuId,m_sonMenuStr);
   }
   else if (m_subType=="7")
   {
    m_cMenu->AppendMenu(MF_STRING|MF_UNCHECKED,m_pMenuId,m_sonMenuStr);
   }
   else
   {
    m_cMenu->AppendMenu(MF_STRING,m_pMenuId,m_sonMenuStr);
   }
   
  }
  ((CMainFrame*)theApp.m_pMainWnd)->DrawMenuBar();
  m_cMenu->Detach();
  m_cMenu->DestroyMenu();
  m_sonMenuArrayStr.RemoveAll(); 
  m_indexMenu++;
 }
 m_menuArrayStr.RemoveAll();
}
void GlobalFuntion::SetTreeMenu()
{
 CString         m_topTreeStr;
 HTREEITEM  m_hTopTree;
 HTREEITEM  m_hSonTree;
 CStringArray m_menuArrayStr;
 CString   m_menuSql;
 CString   m_pMenuStr;
 CStringArray m_sonMenuArrayStr;
 int    m_sCount;
 int    m_pCount;
 CString   m_sonMenuCode;
 m_menuSql="SELECT son_name, son_code FROM base_tree_Menu WHERE parent_code='00000'";
    GetFindData(m_menuSql,m_menuArrayStr);
 m_pCount=m_menuArrayStr.GetSize();
 AfxGetMainWnd()->SetWindowText("和佳放射治疗计划系统");
 m_topTreeStr="和佳TPS";
 m_hTopTree= ((CMainFrame*)AfxGetMainWnd())->m_wndOutput.m_TreeMenuCtrl.InsertItem(m_topTreeStr);
 for (int loopTree=0;loopTree<m_pCount;loopTree++)
 {
 
  m_pMenuStr=m_menuArrayStr.GetAt(loopTree);
  m_hSonTree=((CMainFrame*)AfxGetMainWnd())->m_wndOutput.m_TreeMenuCtrl.InsertItem(m_pMenuStr,1,1,m_hTopTree,TVI_LAST);
  m_sonMenuCode=m_menuArrayStr.GetAt(loopTree+1);
  loopTree=loopTree+1;
  m_menuSql="select son_name,menu_type  from base_tree_menu  where  parent_code='"+m_sonMenuCode+"'";
  GetFindData(m_menuSql,m_sonMenuArrayStr);
  m_sCount=m_sonMenuArrayStr.GetSize();
  ((CMainFrame*)AfxGetMainWnd())->m_wndOutput.SetTreeData(m_hSonTree,m_sonMenuArrayStr);
  m_sonMenuArrayStr.RemoveAll(); 

 }
 m_menuArrayStr.RemoveAll();
 ((CMainFrame*)AfxGetMainWnd())->m_wndOutput.m_TreeMenuCtrl.SetItemState( m_hTopTree, TVIS_BOLD, TVIS_BOLD);
 ((CMainFrame*)AfxGetMainWnd())->m_wndOutput.m_TreeMenuCtrl.ModifyStyle(0,TVS_LINESATROOT|TVS_HASLINES|
    TVS_HASBUTTONS|TVS_SHOWSELALWAYS);
}

//////////////////
void  GlobalFuntion::SetDataGridCaption(HWND m_hwnParent,CString& m_modelCode,UINT m_Id,int m_type,int beginCol,int endCol)
{
 
 CStringArray  m_CaptionArray;
 CWnd* m_ptempDataGrid;
 CString sql="SELECT ctr_name,ctr_disp_format,ctr_align, ctr_isPrimary, ctr_isNUll FROM base_model_ctr  where parent_model_code='"+m_modelCode+"' and ctr_isTable='1' ORDER BY ctr_index";
 theApp.m_gfuntion->GetFindData(sql,m_CaptionArray);
 switch(m_type)
 {
 case 0:

  m_ptempDataGrid=CWnd::FromHandle(GetDlgItem(m_hwnParent,m_Id));
  ((CDataGrid*)m_ptempDataGrid)->SetColCaption(m_CaptionArray,beginCol,endCol);
  break;
 case 1:
  int m_colCount=m_CaptionArray.GetSize()/5;
  LV_COLUMN lvc;
  lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  lvc.iSubItem = 0;
  lvc.fmt = LVCFMT_LEFT; 
  for(int loop=0;loop<m_colCount;loop++)
     {
   lvc.cx = 110+loop*120;
   lvc.pszText = (char*)LPCSTR(m_CaptionArray.GetAt(loop+4*loop));
   m_ptempDataGrid=CWnd::FromHandle(GetDlgItem(m_hwnParent,m_Id));
   ((CListCtrl*)m_ptempDataGrid)->InsertColumn(loop,&lvc);
//   ((CListCtrl*)GetDlgItem(m_Id))->InsertColumn(loop,m_CaptionArray.GetAt(loop+4*loop),LVCFMT_CENTER,10+loop*120,0 );
  }
  break;
 }
}
void  GlobalFuntion::SetDataGridCaption(CString& m_modelCode,CDataGrid* m_Id,int beginCol,int endCol)
{
 
 CStringArray  m_CaptionArray;
 CString sql="SELECT ctr_name,ctr_disp_format,ctr_align, ctr_isPrimary, ctr_isNUll FROM base_model_ctr  where parent_model_code='"+m_modelCode+"' and ctr_isTable='1' ORDER BY ctr_index";
 theApp.m_gfuntion->GetFindData(sql,m_CaptionArray);
 m_Id->SetColCaption(m_CaptionArray,beginCol,endCol);
 
}

BOOL GlobalFuntion::InitListData(HWND m_hwnParent,CString&  m_initSql,UINT m_id)
{
 BOOL m_rtValue=false;
 try{
   CStringArray  m_popGroup;
   CWnd* m_pList=CWnd::FromHandle(GetDlgItem(m_hwnParent,m_id));
   ((CListCtrl*)m_pList)->DeleteAllItems();
   theApp.m_gfuntion->GetFindData(m_initSql,m_popGroup);
   int m_colCount=((CListCtrl*)m_pList)->GetHeaderCtrl()->GetItemCount();
   int m_rowCount=m_popGroup.GetSize()/m_colCount;
   int m_arrayIndex=0;
   for(int loop=0;loop<m_rowCount;loop++)
   {
    LV_ITEM lvi;
    lvi.mask = LVIF_TEXT ;
    lvi.iSubItem = 0;
    lvi.pszText = "";
    lvi.iItem = loop;
   // insert an new line

    int m_colIndex=((CListCtrl*)m_pList)->InsertItem(&lvi);
   // set item text for additional columns  
    for (int x=0; x<m_colCount; x++)
    {
     ((CListCtrl*)m_pList)->SetItemText(m_colIndex,x,(char*)LPCSTR(m_popGroup.GetAt(m_arrayIndex)) );
     m_arrayIndex++;
    }
   }
  }
  catch(_com_error e)///捕捉异常
  {
   CString temp;
   temp.Format("查找数据错误:%s",e.ErrorMessage());
   AfxMessageBox(temp);
   m_rtValue=false;
  }
 return m_rtValue;
}
int GlobalFuntion::SetPopedMenu(UINT m_menuId)
{
 CString m_menuCodeStr;
 m_menuCodeStr.Format("%d",m_menuId);
 IntArray m_subArray;
 m_subArray.Add(0);
 m_subArray.Add(1);
 m_subArray.Add(2);
 m_subArray.Add(3);
 m_subArray.Add(4);
 m_subArray.Add(6);
 CStringArray m_groupCodeArray;
 CString m_findSql="select DISTINCT base_user_popedom.user_popedom_code from base_user_popedom,base_login where base_login.user_code='"+theApp.m_userCode+"'";
 theApp.m_gfuntion->GetFindData(m_findSql,m_groupCodeArray);

 m_findSql="select son_code  from base_menu where  son_id="+m_menuCodeStr;
 CStringArray m_menuArray;
 theApp.m_gfuntion->GetFindData(m_findSql,m_menuArray);
 if(m_groupCodeArray.GetSize()>0 && m_menuArray.GetSize()>0 )
 {
  CString m_popStr="select is_change,is_search  from user_popedom_deatil where  user_popedom_code='"+m_groupCodeArray.GetAt(0)+"' and menu_code='"+m_menuArray.GetAt(0)+"'";
  CStringArray m_popArray;
  theApp.m_gfuntion->GetFindData(m_popStr,m_popArray);
//  CString asdf=(m_popArray.GetAt(0));
//  CString asdf1=(m_popArray.GetAt(1));
  if(m_popArray.GetSize()>0)
  {
   if((m_popArray.GetAt(0)).Compare("0")==0 && (m_popArray.GetAt(1)).Compare("0")==0)
//   {
//    theApp.m_gfuntion->GetErrorTitle("21");
//    AfxMessageBox(theApp.m_errArray[1]);
    return 0;
/*   }*/
   else if ((m_popArray.GetAt(0)).Compare("0")==0 && (m_popArray.GetAt(1)).Compare("1")==0)
   {
//    if(((CMainFrame*)AfxGetMainWnd())->GetActiveFrame()->GetActiveView()->GetSafeHwnd()<=0)
//     SetMenuDisible(2,0,m_subArray);
//    else
/*     SetMenuDisible(3,0,m_subArray);*/
    return 1;
   }
//   else
//    return 2;
//   {
////    if(((CMainFrame*)AfxGetMainWnd())->GetActiveFrame()->GetActiveView()->GetSafeHwnd()<=0)
////     SetMenuDisible(2,1,m_subArray);
////    else
////     SetMenuDisible(3,1,m_subArray);
//   
//   }
  }
 }
 return 2;

}
void GlobalFuntion::SetMenuDisible(int m_index,int m_type,IntArray& m_menuArray)
{
 UINT m_menuState;
 if(m_type==0)
    m_menuState=MF_BYPOSITION | MF_DISABLED |MF_GRAYED;
 else
   m_menuState=MF_BYPOSITION & ~MF_DISABLED & ~MF_GRAYED;
 for(int loop=0;loop<m_menuArray.GetSize();loop++)
  ((CMainFrame*)AfxGetMainWnd())->GetMenu()->GetSubMenu(m_index)->EnableMenuItem(m_menuArray.GetAt(loop), m_menuState);

}
void  GlobalFuntion::SetListCaption(CString& m_modelCode,CMyListCheckBox *m_pList,IntArray& m_colWidth,int beginCol,int endCol)
{
 CStringArray  m_CaptionArray;
 CString sql="SELECT ctr_name,ctr_disp_format,ctr_align, ctr_isPrimary, ctr_isNUll FROM base_model_ctr  where parent_model_code='"+m_modelCode+"' and ctr_isTable='1' ORDER BY ctr_index";
 theApp.m_gfuntion->GetFindData(sql,m_CaptionArray);
 int m_colCount;
 m_colCount=m_CaptionArray.GetSize()/5;
 for(int loop=0;loop<m_colCount;loop++)
  m_pList->AddColumn(m_CaptionArray.GetAt(loop+4*loop),loop,m_colWidth.GetAt(loop));
 
}

BOOL GlobalFuntion::InitListData(CStringArray&  m_Array,CMyListCheckBox *m_pList,IntArray& m_checkBoxArray)
{
 BOOL m_rtValue=false;
 CString m_checkStr="0";
 try{
   m_pList->DeleteAllItems();
   int m_colCount=m_pList->GetHeaderCtrl()->GetItemCount();
   int m_rowCount=m_Array.GetSize()/m_colCount;
   int m_arrayIndex=0;
   for(int loop=0;loop<m_rowCount;loop++)
   {
   /* LV_ITEM lvi;
    lvi.mask = LVIF_TEXT ;
    lvi.iSubItem = 0;
    lvi.pszText = "";
    lvi.iItem = loop;*/
   // insert an new line
   // int m_colIndex=((CListCtrl*)GetDlgItem(m_id))->InsertItem(&lvi);
   // set item text for additional columns 
    int m_isCheckbox=0;
    for (int x=0; x<m_colCount; x++)
    {
     int m_checkCount=m_checkBoxArray.GetSize();
//     ((CListCtrl*)GetDlgItem(m_id))->SetItemText(m_colIndex,x,(char*)LPCSTR(m_popGroup.GetAt(m_arrayIndex)) );
     for(int m_y=0;m_y<m_checkCount;m_y++)
     {
      if(x==m_checkBoxArray.GetAt(m_y))
      {
       m_isCheckbox=1;
       if(m_Array.GetAt(m_arrayIndex).GetLength()==0 || m_Array.GetAt(m_arrayIndex)=="0")
        m_checkStr="0";
       else
          m_checkStr="1";
             break;
      }
     }
     
//     ((CListCtrl*)GetDlgItem(m_id))->SetItemText(m_colIndex,x,(char*)LPCSTR(m_popGroup.GetAt(m_arrayIndex)));

     if(m_isCheckbox==1)
      m_pList->AddListItem(loop,x,m_checkStr, CListItemCheckBox::GenerateProperty());
     else
      m_pList->AddListItem(loop,x,m_Array.GetAt(m_arrayIndex));
         m_isCheckbox=0;
      m_arrayIndex++;
    }
   }
  }
  catch(_com_error e)///捕捉异常
  {
   CString temp;
   temp.Format("查找数据错误:%s",e.ErrorMessage());
   AfxMessageBox(temp);
   m_rtValue=false;
  }
 return m_rtValue;
}
int  GlobalFuntion::CheckData(_RecordsetPtr retSet,IntArray& m_col)
{
    int rowCount=retSet->GetRecordCount();
 CString insertValue;
 retSet->MoveFirst();
 for(int m_row=0;m_row<rowCount;m_row++)
 {
        for(int col=0;col<m_col.GetSize();col++)
  {
   _variant_t aa=retSet->GetCollect(_variant_t((long)(m_col.GetAt(col))));
   if(aa.vt==VT_NULL)
    insertValue="";
   else
    insertValue=(LPCSTR)(_bstr_t)aa;
   int retInt=theApp.m_gfuntion->InputFloat((LPSTR)(LPCTSTR)insertValue,insertValue.GetLength());
            if(retInt!=0)
   {
    theApp.m_gfuntion->GetErrorTitle("35");//第 %d 行 第 %d 列记录为空,请重新输入!
    AfxMessageBox(theApp.m_errArray[1],MB_ICONERROR|MB_OK);
    return 0;
   }
   
      
  }
  retSet->MoveNext();
 }
 return 1; 
}
void GlobalFuntion::GetColTotleData(_RecordsetPtr retSet,int m_col,FloatArray& refloatArray)
{
 float  m_totole=0.0;
 int rowCount=retSet->GetRecordCount();
 CString insertValue;
 retSet->MoveFirst();
 for(int m_row=0;m_row<rowCount;m_row++)
 {
         _variant_t aa=retSet->GetCollect(_variant_t((long)m_col));
   if(aa.vt==VT_NULL)
    insertValue="0";
   else
    insertValue=(LPCSTR)(_bstr_t)aa;
   if(atof((LPSTR)(LPCTSTR)insertValue)>0)
   { 
        refloatArray.Add(atof((LPSTR)(LPCTSTR)insertValue));
     m_totole+=atof((LPSTR)(LPCTSTR)insertValue);
   }
  retSet->MoveNext();
   
 }
 refloatArray.Add(m_totole);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值