⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 paitxtdata.cpp

📁 一个详细的学籍管理系统源码,支持数据查找、排序、导入、导出
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			//初始化完毕
			int r=2,no=0;
			while(records.Find('/',0)>=0)
			{
				//获取记录
				temp=records.Left(records.Find('/',0)+1);
				records=records.Right(records.GetLength()-temp.GetLength());
				temp=temp.Left(temp.GetLength()-1);
				//将获取的一条记录以分隔符为标志拆分开并填入表中
				if(m_list1.GetRows()>3)//大于初始行数时增加1行,行高为320
				{
					m_list1.SetRows(m_list1.GetRows()+1);
					m_list1.SetRowHeight(m_list1.GetRows()-1,320);
				}
				//填序号
				no++;
				CString nostr;
				nostr.Format("%d",no);
				m_list1.SetTextMatrix(m_list1.GetRows()-1,0,nostr);

				CString strleft;
				for(int c=0;c<m_list1.GetCols();c++)
				{
					m_list1.SetRow(r);
					m_list1.SetCol(c);
					m_list1.SetCellAlignment(4);
					if(c>0)//开始从已获取的字符串变量(temp)中获取单个以分号分隔的子串填充相应单元格
					{
						if(temp.Find(';',0)>0)//找到分隔符并且不位于首端
						{
							strleft=temp.Left(temp.Find(';',0)+1);//截取左子串(包含找到的分隔符)
							m_list1.SetTextMatrix(r,c,strleft.Left(strleft.Find(';')));//对相应单元格赋值为左子串(但不含分隔符)
							temp=temp.Right(temp.GetLength()-strleft.GetLength());//迭代改变本身值为右串
						}
						else
							if(temp.Find(';',0)==0)
								temp=temp.Right(temp.GetLength()-1);//分隔符位于首端时不截取左串,迭代改变本身值为去除首端分隔符后的右串,此时不对相应单元格赋值。
							else
								m_list1.SetTextMatrix(r,c,temp);//此时没找到分隔符,说明已经是末尾字串,所以对相应单元格直接用其赋值之
					}
				}
				m_list1.SetRows(m_list1.GetRows()+1);
				m_list1.SetRowHeight(m_list1.GetRows()-1,0);//增加一行高为0的空行
				r+=2;
			}
			m_list1.ShowWindow(SW_SHOW);
		}
		else
			MessageBox("["+path.Left(path.GetLength()-1)+"] 目录下不存在文件 <"+temp+">","提示",MB_OK|MB_ICONASTERISK|MB_DEFBUTTON2);
	}
	else
	{
		MessageBox("请选择班级后再进行!","提示",MB_OK|MB_ICONASTERISK);
		return;
	}
}

BOOL CPaiTxtData::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
	if(m_list1.GetRows()>3)
	{
		int nPos = m_list1.GetScrollPos(SB_VERT);         //获得当前垂直滚动条位置
		int nMax = m_list1.GetScrollLimit(SB_VERT);      //获得当前垂直滚动条位置范围的最大值
		if(zDelta < 0)         //判断滚动方向为向下滚动
		{
			nPos += 3;
			(nPos >= nMax) ? (nPos = nMax-1) : NULL;
		}
		else
		{
			nPos -= 3;
			(nPos <= 1) ? (nPos = 1) : NULL;
		}
		m_list1.SetTopRow(nPos+1);
	}

	return CDialog::OnMouseWheel(nFlags, zDelta, pt);
}

void CPaiTxtData::OnShowWindow(BOOL bShow, UINT nStatus)
{
	CDialog::OnShowWindow(bShow, nStatus);

	if(bShow)
	{
		////从ini文件中构造班级字串////
		if(theApp.bExist)
		{
			int rcount,ccount;
			theApp.IniFile.GetItemInt("SCHOOL","row",rcount);//获到行数
			theApp.IniFile.GetItemInt("SCHOOL","col",ccount);//获取列数,不含序号列
			CString strvar,stritem,strleft,temp;//sstrvar为字符串变量,stritem为字符串变量的值,strleft为待截取的左子串
			int f;//记录分号出现的次数
			for(int r=1;r<=rcount;r++)
			{
				f=0;//每次查找之前将其置为0
				strvar.Format("var%d",r);//构造列号
				theApp.IniFile.GetItemString("CLASS",strvar,stritem);//获取字符串变量的值
				for(int c=0;c<ccount;c++)
				{
					if(stritem.Find(";")>=0)
					{
						f++;//找到时将出现次数自加1.
						if(stritem.Find(";",0)>0)//找到分隔符并且不位于首端
						{
							strleft=stritem.Left(stritem.Find(";",0)+1);//截取左子串(包含找到的分隔符)
							if(f==2)
								temp=strleft.Left(strleft.GetLength()-1);
							if(f==4)
								m_class.AddString(temp+strleft.Left(strleft.GetLength()-1));//此时构造完一个班级字符串,将其添加进班级下拉框
							stritem=stritem.Right(stritem.GetLength()-strleft.GetLength());//迭代改变本身值为右串
						}
						else
							if(stritem.Find(";",0)==0)
							stritem=stritem.Right(stritem.GetLength()-1);//分隔符位于首端时不截取左串,迭代改变本身值为去除首端分隔符后的右串。
					}
				}
			}
			CheckRadioButton(IDC_RADIO1,IDC_RADIO2,IDC_RADIO1);
		}
		////构造完毕////
	}
	else
	{
		for(int r=m_list1.GetRows()-1;r>1;r--)//表头不清除
		{
			for(int c=0;c<m_list1.GetCols();c++)
				m_list1.SetTextMatrix(r,c,"");
			if(r>2)
				m_list1.RemoveItem(r);
		}
	}
}

void CPaiTxtData::OnCbnSelchangeClass()
{
	if(!(m_list1.GetTextMatrix(2,1).IsEmpty()))
		if(MessageBox("在重新选择班级之前请确认数据是否保存!","提示",MB_YESNO|MB_ICONASTERISK|MB_DEFBUTTON2)==IDNO)
		{
			m_class.SetCurSel(m_class.FindString(0,m_list1.GetTextMatrix(2,2)+m_list1.GetTextMatrix(2,3)));//还原班级
			return;
		}
	if(theApp.bExist)
	{
		CString temp,gradename,xiname,classname;
		if(m_class.GetCurSel()>=0)//如果选择了具体的项则分别构造年级和班学符串并进行一系列初始化
		{
			m_index.ResetContent();
			m_index.AddString("系别");
			m_index.AddString("学籍号");
			m_index.AddString("姓名");
			m_index.AddString("姓别");
			m_index.AddString("年龄");

			m_class.GetLBText(m_class.GetCurSel(),temp);
			gradename=temp.Left(temp.Find("级")+2);
			classname=temp.Right(temp.GetLength()-temp.Find("级")-2);
			int rcount;
			theApp.IniFile.GetItemInt("SCHOOL","row",rcount);//获到行数
			CString strvar,stritem;//strvar为字符串变量,stritem为字符串变量的值
			for(int r=1;r<=rcount;r++)
			{
				strvar.Format("var%d",r);//构造列号
				theApp.IniFile.GetItemString("CLASS",strvar,stritem);//获取字符串变量的值
				if(stritem.Find(gradename)>0 && stritem.Find(classname)>0)
				//找到时值返回值大于或等于0,但在具体设计文件时这两项不可能出现在首部,所以取大于0
				//找到后便获取该行的系别及学科字串,学科字串必须分解,因为是以逗号分隔的。
				//再根据学科数在网格控件中增加列并对其进行格式初始化
				{
					//截取stritem中“班”字串后面的字串
					temp=stritem.Right(stritem.GetLength()-stritem.Find("班",0)-3);
					//截取学科字串
					temp=temp.Left(temp.Find(";",0));
					//截取完毕,开始拆分字串以构造各个学科的字串并填入学科下拉框
					if(!temp.IsEmpty())//开始从已获取的字符串变量(temp)中获取单个以分号分隔的子串填充相应单元格
					{
						CString strleft;
						int c=0;//学科数
						while(temp.Find(",",0)>=0)
						{
							if(temp.Find(",",0)>0)//找到分隔符并且不位于首端
							{
								strleft=temp.Left(temp.Find(",",0)+1);//截取左子串(包含找到的分隔符)
								m_index.AddString(strleft.Left(strleft.Find(",",0)));//用左子串填充分下拉框(但不含逗号分隔符)
								temp=temp.Right(temp.GetLength()-strleft.GetLength());//迭代改变本身值为右串
							}
							else
								if(temp.Find(",",0)==0)
									temp=temp.Right(temp.GetLength()-1);//分隔符位于首端时不截取左串,迭代改变本身值为去除首端分隔符后的右串,此时不对学科下拉框填充。
							c++;
						}
						m_index.AddString(temp);//此时没的temp已经被迭代以逗号分隔的最末个子串了,所以对学科下拉框直拉用其填充之
						c++;
						//清空表格内数据,但不包含第1行
						for(int r=1;r<m_list1.GetRows();r++)
							for(int c=0;c<m_list1.GetCols();c++)
								m_list1.SetTextMatrix(r,c,"");
						UpdateFlexGrid(3,9,2,1);//还原网格为初始状态
						m_list1.SetCols(m_list1.GetCols()+c+1);//设置为初始列加c个学科列及1个备注列
						//对新增单元格进行初始化
						for(int r=0;r<m_list1.GetRows();r++)
						{
							for(int c=9;c<m_list1.GetCols();c++)
							{
								m_list1.SetRow(long(r));
								m_list1.SetCol(long(c));
								m_list1.SetCellAlignment(4);
							}
						}
						//设定第一列可见
						m_list1.SetLeftCol(1);
						//补充表头
						int n,x=5;//在关键字排行中从第8开努为学科
						for(n=9;n<c+10;n++)
						{
							if(n<c+9)
							{
								m_list1.SetTextMatrix(0,n,"学        科");
								m_index.GetLBText(x,temp);
								m_list1.SetTextMatrix(1,n,temp);
								x++;
							}
							else
							{
								m_list1.SetTextMatrix(0,n,"备注");
								m_list1.SetTextMatrix(1,n,"备注");
							}
						}
						m_list1.SetMergeCol(n-1,TRUE);//此时的变量n在上面循环结束时也自加1,故需减1
						m_list1.SetMergeRow(0,TRUE);
						m_index.AddString("备注");
					}
				}
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -