📄 program2dlg.cpp
字号:
for(j=tabelCols+1;j<=SS.GetTotalColumns();j++)
{
m_FlexGrid.SetCol(j-tabelCols);
s=Rows.GetAt(j-1);
if(s=="")
m_FlexGrid.SetText("0.0000");
if(IsNumber(s))
{
m_FlexGrid.SetText(s);
}
}
}
ShowWindow(SW_RESTORE);//显示窗口
}
}
}
}
}
/////////////////////////////////////////////////
///
///
///导出数据到Excel
void CProGram2Dlg::OnMENU1PutOut()
{
// TODO: Add your command handler code here
//导出标签列没有涉及
if(m_MeanRows==0||m_MeanCols==0)
{
MessageBox(" 不能保存空数据 ","出错啦");
return;
}
CFileDialog File(false,NULL,"数据.xls",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"表格(*.xls)|*.xls||");
if(File.DoModal()==IDOK)
{
int i,j;
CString s;
CString sPath=File.GetPathName();
CSpreadSheet SS(sPath, "Sheet1");
CStringArray sampleArray, testRow;
SS.BeginTransaction();
// MessageBox(sPath);
///
// s.Format("%d",m_IsDataFromExcel);
// MessageBox(s);//测试是否数据来自excel文件
///
if(m_IsDataHasTabel)//数据来自表格,有标题行
{
sampleArray.RemoveAll();
for(i=1;i<=m_MeanCols;i++)
{
sampleArray.Add(m_FlexGrid.GetTextMatrix(0,i));
}
SS.AddHeaders(sampleArray);
}
for(i=1;i<=m_MeanRows;i++)
{
sampleArray.RemoveAll();
for(j=1;j<=m_MeanCols;j++)
{
s=m_FlexGrid.GetTextMatrix(i,j);
sampleArray.Add(s);
}
SS.AddRow(sampleArray);
}
AfxMessageBox("文件写入成功!");
}
}
void CProGram2Dlg::OnMenu1Clearn()
{
// TODO: Add your command handler code here
ShowWindow(SW_MINIMIZE);//隐藏窗口,在后台录入数据
UpdateData(true);
m_IsDataHasTabel=0;
m_IsDataHasTabelOnCol=0;
m_MeanRows=0;//有效行列初始化
m_MeanCols=0;
UpdateData(false);
m_FlexGrid.Clear();
m_FlexGrid.SetCols(m_NumCols);
m_FlexGrid.SetRows(m_NumRows);
m_FlexGrid.SetRow(0);
m_FlexGrid.SetCol(0);
m_FlexGrid.SetText("品种\\性状");
m_FlexGrid.SetRow(0);
CString s;
for(int i=1;i<m_NumCols;i++)
{
m_FlexGrid.SetCol(i);
s.Format(" %d ",i);
m_FlexGrid.SetText(s);
}
m_FlexGrid.SetCol(0);
for(i=1;i<m_NumRows;i++)
{
m_FlexGrid.SetRow(i);
s.Format(" %d ",i);
m_FlexGrid.SetText(s);
}
m_Change.ShowWindow(SW_HIDE);
ShowWindow(SW_RESTORE);//显示窗口
}
void CProGram2Dlg::OnMenu1New()
{
// TODO: Add your command handler code here
ShowWindow(SW_MINIMIZE);//隐藏窗口,在后台录入数据
m_FlexGrid.Clear();
UpdateData(true);
m_IsDataHasTabel=0;
m_IsDataHasTabelOnCol=0;
m_MeanRows=0;//有效行列初始化
m_MeanCols=0;
UpdateData(false);
m_NumRows=300;
m_NumCols=100;
m_FlexGrid.SetCols(m_NumCols);
m_FlexGrid.SetRows(m_NumRows);
m_FlexGrid.SetRow(0);
m_FlexGrid.SetCol(0);
m_FlexGrid.SetText("品种\\性状");
m_FlexGrid.SetRow(0);
CString s;
for(int i=1;i<m_NumCols;i++)
{
m_FlexGrid.SetCol(i);
s.Format(" %d ",i);
m_FlexGrid.SetText(s);
}
m_FlexGrid.SetCol(0);
for(i=1;i<m_NumRows;i++)
{
m_FlexGrid.SetRow(i);
s.Format(" %d ",i);
m_FlexGrid.SetText(s);
}
m_Change.ShowWindow(SW_HIDE);
ShowWindow(SW_RESTORE);//显示窗口
}
void CProGram2Dlg::OnMenu1Exit()
{
// TODO: Add your command handler code here
CSureExit dlg;
if(dlg.DoModal()==IDOK)
OnMENU1PutOut();
else
exit(0);
}
void CProGram2Dlg::OnMenu2Main()
{ // TODO: Add your command handler code here
//数据更新测试
// CString s;
// s.Format("%d---%d;;;;%d---%d",m_MeanRows,m_MeanCols,m_lRow,m_lCol);
// MessageBox(s);
//
MainFactorsData dlg;
dlg.m_MeanRows=m_MeanRows;
dlg.m_MeanCols=m_MeanCols;
dlg.m_OfferRate=0.80;
if(dlg.DoModal()==IDOK)
{
if(dlg.m_MeanCols<=0||dlg.m_MeanRows<=0)
{
MessageBox(" 错误的有效行列数! ","出错啦");
return;
}
if(dlg.m_ModoKind==2)
{
MessageBox(" 没有选择分析模型! ","出错啦");
return;
}
//Add our program on Main here
/*
CMatrix m_Matrix2; //标准化样本数据
CMatrix m_Result1; //存放主成分的特征根,贡献率和累计贡献率
CMatrix m_Result2; //存放主成分系数
CMatrix m_Result3; //存放样品的主成分得分值
CMatrix m_Result4; //主成分载荷因子
*/
CMatrix Data(ReadDataToMatrix(dlg.m_MeanRows,dlg.m_MeanCols));
Data=Data.Transpose();
MainFactor mainfactor(Data,dlg.m_OfferRate,dlg.m_ModoKind);
mainfactor.Analyze1();
CMatrix *a;
a=new CMatrix[5];
a[0]=mainfactor.m_Matrix2;
a[1]=mainfactor.m_Result1;
a[2]=mainfactor.m_Result2;
a[3]=mainfactor.m_Result3;
a[4]=mainfactor.m_Result4;
int J[5]={1,mainfactor.m_mainNum,1,1,1};//5个矩阵均需要输出
CResultDlg result;
result.TranMemberNumber(1,a,5,J);
result.DoModal();
}
}
void CProGram2Dlg::OnMENU2ONorIN()
{// TODO: Add your command handler code here
ONorINData dlg;
dlg.m_MeanRows=m_MeanRows;
dlg.m_MeanCols=m_MeanCols;
dlg.m_OfferRate=0.80;
if(dlg.DoModal()==IDOK)
{
if(dlg.m_MeanCols<=0||dlg.m_MeanRows<=0)
{
MessageBox(" 错误的有效行列数! ","出错啦");
return;
}//Add our program on ONorIN here
CMatrix a(ReadDataToMatrix(dlg.m_MeanRows,dlg.m_MeanCols));
a=a.Transpose();
QR_analysis analysis;
analysis.run(a);
CMatrix *Data;
Data=new CMatrix[4];
Data[0]=analysis.result1;
Data[1]=analysis.result2;
Data[2]=analysis.result3;
Data[3]=analysis.result4;
int J[4]={1,1,1,1};
CResultDlg result;
result.TranMemberNumber(2,Data,4,J);
result.DoModal();
}
}
void CProGram2Dlg::OnMenu2Factors()
{// TODO: Add your command handler code here
FactorsData dlg;
dlg.m_MeanRows=m_MeanRows;
dlg.m_MeanCols=m_MeanCols;
dlg.m_OfferRate=0.80;
if(dlg.DoModal()==IDOK)
{
if(dlg.m_MeanCols<=0||dlg.m_MeanRows<=0)
{
MessageBox(" 错误的有效行列数! ","出错啦");
return;
}
//Add our program on Factors here
//在这里定义解决方法的类,并得到结果
///读和传输矩阵测试
CMatrix a;
a=ReadDataToMatrix(dlg.m_MeanRows,dlg.m_MeanCols);
Factor factor(a,dlg.m_OfferRate);
factor.Run();
CMatrix *Data;
Data=new CMatrix[7];
Data[0]=factor.X;//原数据,最后为标准化后的数据
Data[1]=factor.R;//相关矩阵P*P
Data[2]=factor.te_R;//特征值和特征矩阵
CMatrix A1((int)factor.p,(int)factor.m_ColsOfA+2);
for(int i=0;i<factor.p;i++)
{
for(int j=0;j<factor.m_ColsOfA;j++)
{
A1.SetElement(i,j,factor.A.GetElement(i,j));
}
double *t=factor.h2;
A1.SetElement(i,(int)factor.m_ColsOfA,t[i]*t[i]);
A1.SetElement(i,(int)factor.m_ColsOfA+1,1-t[i]*t[i]);
}
Data[3]=factor.A;//因子载荷阵p*p
Data[4]=A1;//因子载荷阵p*m+h2+a2
Data[5]=factor.B;//正交旋转后的主因子载荷阵p*m
Data[6]=factor.F;//因子得分m_ColsOfA*p
int J[7]={dlg.m_CHECK1,dlg.m_CHECK2,dlg.m_CHECK3,dlg.m_CHECK4,1,((factor.m_ColsOfA>=2)? 1:0),1};
CResultDlg result;
result.TranMemberNumber(3,Data,7,J);//结果传输
result.DoModal();
}
}
void CProGram2Dlg::OnMenu3Help()
{
// TODO: Add your command handler code here
ShellExecute(NULL, "open", "使用说明.pdf", NULL, NULL, SW_SHOWNORMAL);
ShowWindow(SW_MINIMIZE);
}
void CProGram2Dlg::OnMenu3About()
{
// TODO: Add your command handler code here
CAboutDlg dl;
dl.DoModal();
}
///////////////////////////////////////////////////////
///
///
///行列增减控制按钮
void CProGram2Dlg::OnBuntonRowDown()
{
// TODO: Add your control notification handler code here
if(m_NumRows>1)
{
m_NumRows-=1;
m_FlexGrid.SetRows(m_NumRows);
}
}
void CProGram2Dlg::OnButtonColDown()
{
// TODO: Add your control notification handler code here
if(m_NumCols>1)
{
m_NumCols-=1;
m_FlexGrid.SetCols(m_NumCols);
}
}
void CProGram2Dlg::OnButtonColUp()
{
// TODO: Add your control notification handler code here
m_NumCols+=1;
m_FlexGrid.SetCols(m_NumCols);
m_FlexGrid.SetRow(0);
m_FlexGrid.SetCol(m_NumCols-1);
CString s;
s.Format(" %d",m_NumCols-1);
m_FlexGrid.SetText(s);
}
void CProGram2Dlg::OnButtonRowUp()
{
// TODO: Add your control notification handler code here
m_NumRows+=1;
m_FlexGrid.SetRows(m_NumRows);
m_FlexGrid.SetCol(0);
m_FlexGrid.SetRow(m_NumRows-1);
CString s;
s.Format(" %d",m_NumRows-1);
m_FlexGrid.SetText(s);
}
/////////////////////////////////////////////////////////////////////
///
///
///对话框失去焦点,取值
void CProGram2Dlg::OnKillfocusEditChange()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if(m_sChange=="")
return;
if(IsNumber(m_sChange))
{
m_MeanRows=((m_lRow>m_MeanRows)? m_lRow:m_MeanRows);
m_MeanCols=((m_lCol>m_MeanCols)? m_lCol:m_MeanCols);
m_FlexGrid.SetText(m_sChange);
m_Change.ShowWindow(SW_HIDE);
m_sChange="";
}
else
{
MessageBox(" 请输入数值型数据! ","出错啦");
m_FlexGrid.SetText("");
}
UpdateData(false);
}
///
///
///判断CString是否为数据类型的
bool CProGram2Dlg::IsNumber(CString str)
{
if(!str.GetLength())
return false;
char ch;
for(int i=0;i<str.GetLength();i++)
{
ch=str[i];
if(ch!=45 && ch!=46 && ch<48 || ch>57)
return false;
}
return true;
}
///
///
///按照有效行列数读取数据
CMatrix CProGram2Dlg::ReadDataToMatrix(int Rows,int Cols)
{
int i,j;
CString s,c;
CMatrix result(Rows,Cols);
for(i=1;i<=Rows;i++)
{
for(j=1;j<=Cols;j++)
{
s=m_FlexGrid.GetTextMatrix(i,j);
// c.Format("%f",(double)atof(s));
// MessageBox(c);
result.SetElement(i-1,j-1,(double)atof(s));
}
}
// MessageBox("读数据完成");
return result;
}
void CProGram2Dlg::showMatrix(CMatrix a)
{
if(a.GetNumCols==0)
return;
CString s,c;
for(int i=0;i<a.GetNumRows();i++)
{
s="";
for(int j=0;j<a.GetNumCols();j++)
{
c.Format(" %f",(double)a.GetElement(i,j));
s=s+c;
}
MessageBox(s);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -