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

📄 ckfhdlg.cpp

📁 这是一套学校设备管理系统的源码 里面有树形结构使用的很棒的方法
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    b_pos = n * 280L;
    for (i=0;i<n;i++){
		fread(bu,1,280,fpe);
		fwrite(bu,1,280,tofpe);
    }
	l = (n+1)*280;
	fseek(fpe,l,SEEK_SET);
	for (i=n+1;i<num_of_recs;i++){
		fread(bu,1,280,fpe);
		fwrite(bu,1,280,tofpe);
    }
    fclose(fpe);
	fclose(tofpe);

    fpe = fopen("c:\\xxsbgl\\temp.dat","rb");
	tofpe = fopen("c:\\xxsbgl\\sbck.dat","wb");
	fseek(fpe,0L,SEEK_END);
	l = ftell(fpe);
	fseek(fpe,0L,SEEK_SET);
	num_of_recs = l / 280;
	for (i=0;i<num_of_recs;i++){
		fread(bu,1,280,fpe);
		fwrite(bu,1,280,tofpe);
    }
    fclose(fpe);
	fclose(tofpe);
	reload();
	m_sbck.SetRow(1L);
	old_sel_row = 0;
	if (end_recs > 0){
	  SetDlgItemText(IDC_ckfx,"");
      OnSelChangesbck();
	}
	else{
	  SetDlgItemText(IDC_sbmc,"");
	  SetDlgItemText(IDC_rkn,"");
	  SetDlgItemText(IDC_rky,"");
	  SetDlgItemText(IDC_rkr,"");
	  SetDlgItemText(IDC_jbr,"");
	  SetDlgItemText(IDC_gdbh,"");
	  SetDlgItemText(IDC_ckfs,"");
	  SetDlgItemText(IDC_cksl,"");
	  SetDlgItemText(IDC_ckfx,"");
    }
	}
}

void Cckfhdlg::reload() 
{
	long l;
	FILE *fpe;
	int num,i;
	char bu[500];
	char buf[20];

	end_recs = 0;
	m_sbck.SetRows(2L);
	m_sbck.SetRow(1L);
	for (l=0;l<=13;l++){
	  m_sbck.SetCol(l);
	  m_sbck.SetText("");
	}

	fpe = fopen("c:\\xxsbgl\\sbck.dat","rb");
	if (fpe != NULL){
		fseek(fpe,0L,SEEK_END);
		l = ftell(fpe);
		num = l/280;
        end_recs = num;;
		fseek(fpe,0L,SEEK_SET);
		l = num + 2;
        m_sbck.SetRows(l);
        for (i=0;i<num;i++){
		  fread(&(sbckunit.reserve[0]),sizeof(sbckstrt),1,fpe);
          order_of_recs[i] = i;
		  l = i + 2;
		  m_sbck.SetRow(l-1L);
		  m_sbck.SetCol(0L);
		  m_sbck.SetText(sbckunit.ckbh);
		  m_sbck.SetCol(1L);
		  m_sbck.SetText(sbckunit.wpdj);
		  m_sbck.SetCol(2L);
		  m_sbck.SetText(sbckunit.sbmc);
		  m_sbck.SetCol(3L);
		  m_sbck.SetText(sbckunit.cksl);
		  m_sbck.SetCol(4L);
		  m_sbck.SetText(sbckunit.ckfs);
		  m_sbck.SetCol(5L);
		  m_sbck.SetText(sbckunit.zje);
		  m_sbck.SetCol(6L);
		  strcpy(buf,sbckunit.ckn);
		  strcat(buf,"年");
		  strcat(buf,sbckunit.cky);
		  strcat(buf,"月");
		  strcat(buf,sbckunit.ckr);
		  strcat(buf,"日");
		  m_sbck.SetText(buf);
		  m_sbck.SetCol(7L);
		  m_sbck.SetText(sbckunit.jbr);
		  m_sbck.SetCol(8L);
		  m_sbck.SetText(sbckunit.yqdm);
		  m_sbck.SetCol(9L);
		  m_sbck.SetText(sbckunit.ssbm);
		  m_sbck.SetCol(10L);
		  m_sbck.SetText(sbckunit.gdbh);
		  m_sbck.SetCol(11L);
		  m_sbck.SetText(pyjx);
		  m_sbck.SetCol(12L);
		  m_sbck.SetText(sbckunit.ckfx);
		  m_sbck.SetCol(13L);
		  m_sbck.SetText(sbckunit.rkbh);
        } 
		fclose(fpe);
    }
}

void Cckfhdlg::Onqbhz() 
{
	// TODO: Add your control notification handler code here
	FILE *fpe;
	FILE *tofpe;
	long l;
	int num_of_recs,i;
	char bu[500];
	Cqrqbhz dlg;

	if (dlg.DoModal() == IDOK){
      fpe = fopen("c:\\xxsbgl\\sbck.dat","rb");
	  if (fpe == NULL)
		  return ;
	  tofpe = fopen("c:\\xxsbgl\\sbckzm.dat","a+b");
	  fseek(fpe,0L,SEEK_END);
	  l = ftell(fpe);
	  fseek(fpe,0L,SEEK_SET);
	  num_of_recs = l / 280;
	  for (i=0;i<num_of_recs;i++){
		fread(bu,1,280,fpe);
		fwrite(bu,1,280,tofpe);
	  }
	  fclose(fpe);
	  fclose(tofpe);
	  unlink("c:\\xxsbgl\\sbck.dat");
	  reload();
	}
}




void Cckfhdlg::Ondayin() 
{
	// TODO: Add your control notification handler code here
  FILE *fpe;
  FILE *fpe1;
  FILE *tofpe;
  char buf[200];
  int ret;
  long l;
  int num,i,j,k,m,w,h,n;
  char bu[500];
  int flag;
  char buf2[200];
  int t;
  float x,y,f;
  int pages;
  int num_of_recs_in_a_page;
  int order;
  CString str;
  float tjzsl;
  int year,month,day,segs;
  time_t ltime;    
  struct tm *pti;
  char tmpbuf[100];
  int num_of_recs_in_a_seg;
  long bh1,bh2;

  fpe = fopen("c:\\xxsbgl\\gdzczxd.txt","rb");
  ret = get_a_line(fpe,buf);
  i = 0;
  while (ret != -1){
    strcpy(prt_buf[i],buf);
	i ++;
    ret = get_a_line(fpe,buf);
  }
  end_prt_buf = i;
  tofpe = fopen("c:\\xxsbgl\\prttxt.txt","wb");
  pages = end_recs/12;
  if (end_recs%12 != 0){
	  pages ++;
  }
  order = 1;

  
  time(&ltime);    
  pti = gmtime(&ltime);
  year = pti->tm_year + 1900;
  month = 1 + pti->tm_mon;
  day = pti->tm_mday;
  if (pages == 0)
    pages = 1;
  order = 0;
  for (i=0;i<pages;i++){
	  if (i == pages-1){
          num_of_recs_in_a_page = end_recs%12;
		  if (num_of_recs_in_a_page == 0)
			  num_of_recs_in_a_page = 12;
		  if (end_recs == 0)
			  num_of_recs_in_a_page = 0;
      }
	  else{
		  num_of_recs_in_a_page = 12;
      }

      fprintf(tofpe,"newpage\r\n");

      segs = num_of_recs_in_a_page / 4;
	  if (num_of_recs_in_a_page % 4 != 0)
	    segs ++;
	  if (segs > 2)
		  segs = 3;
      for (j=0;j<segs;j++){
		  if (j == segs-1){
		    num_of_recs_in_a_seg = num_of_recs_in_a_page % 4;
			if (num_of_recs_in_a_seg == 0)
				num_of_recs_in_a_seg = 4;
          }
		  else{
			num_of_recs_in_a_seg = 4;
          }
		  for (k=0;k<end_prt_buf;k++){
			  if (strcmp(prt_buf[k],"text") == 0){
				  fprintf(tofpe,"%s\n",prt_buf[k]);
				  fprintf(tofpe,"%s\n",prt_buf[k+1]);
				  y = atof(prt_buf[k+2]);
				  y += 9.9*j;
				  fprintf(tofpe,"%f\n",y);
				  fprintf(tofpe,"%s\n",prt_buf[k+3]);
				  k += 3;
              }
			  else if (strcmp(prt_buf[k],"tab") == 0){
				  fprintf(tofpe,"%s\n",prt_buf[k]);
				  fprintf(tofpe,"%s\n",prt_buf[k+1]);
				  y = atof(prt_buf[k+2]);
				  y += 9.9*j;
				  fprintf(tofpe,"%f\n",y);
				  w = atoi(prt_buf[k+3]);
				  h = atoi(prt_buf[k+4]);
				  fprintf(tofpe,"%s\n",prt_buf[k+3]);
				  fprintf(tofpe,"%d\n",num_of_recs_in_a_seg+1);
				  for (m=0;m<w;m++){
				    fprintf(tofpe,"%s\n",prt_buf[k+5+m]);
                  }
				  fprintf(tofpe,"%s\n",prt_buf[k+5+w]);
				  for (m=0;m<num_of_recs_in_a_seg;m++)
				    fprintf(tofpe,"%s\n",prt_buf[k+6+w]);
                  k += 4 + w + h;
              }
			  else
				  fprintf(tofpe,"%s\n",prt_buf[k]);
          }

          if (j != 2){
				  fprintf(tofpe,"line\n");
				  fprintf(tofpe,"1\n");
                  y = (j+1)*9.9;
				  fprintf(tofpe,"%f\n",y);
				  fprintf(tofpe,"20\n");
				  fprintf(tofpe,"%f\n",y);
          }

		  for (m=0;m<num_of_recs_in_a_seg;m++){
		    fprintf(tofpe,"text\n");
			x = 2.9;
	        fprintf(tofpe,"%f\n",x);
			y = 3.6+j*9.9+0.8*m;
	        fprintf(tofpe,"%f\n",y);
            l = order + 1;
			m_sbck.SetRow(l);
			m_sbck.SetCol(10L);
			str = m_sbck.GetText();
			strcpy(bu,str.GetBuffer(20));
	        fprintf(tofpe,"%s\n",bu);

		    fprintf(tofpe,"text\n");
			x = 4.9;
	        fprintf(tofpe,"%f\n",x);
			y = 3.6+j*9.9+0.8*m;
	        fprintf(tofpe,"%f\n",y);
			m_sbck.SetCol(2L);
			str = m_sbck.GetText();
			strcpy(bu,str.GetBuffer(20));
	        fprintf(tofpe,"%s\n",bu);

			m_sbck.SetCol(1L);
			str = m_sbck.GetText();
			strcpy(bu,str.GetBuffer(20));
			l = atol(bu);
	        if (l > 10000){
		      l -= 10000;
		      fpe1 = fopen("c:\\xxsbgl\\sbrkzm.dat","rb");
			}
	        else{
		      fpe1 = fopen("c:\\xxsbgl\\qczm.dat","rb");
			}
			bh1 = l;
            fseek(fpe1,0L,SEEK_END);
            l = ftell(fpe1);
            fseek(fpe1,0L,SEEK_SET);
			for (n=0;n<l/sizeof(zmstrt);n++){
              fread((void *)(&(zmunit.reserve)),sizeof(zmstrt),1,fpe1);
			  bh2 = atol(zmunit.rkbh);
			  if (bh1 == bh2){
				  break;
              }
            }
			fclose(fpe1);

		    fprintf(tofpe,"text\n");
			x = 8.9;
	        fprintf(tofpe,"%f\n",x);
			y = 3.6+j*9.9+0.8*m;
	        fprintf(tofpe,"%f\n",y);
            zmunit.xhgg[40] = 0;
			trim(zmunit.xhgg);
			if (zmunit.xhgg[0] == '~')
				zmunit.xhgg[0] = 0;
	        fprintf(tofpe,"%s\n",zmunit.xhgg);

		    fprintf(tofpe,"text\n");
			x = 13;
	        fprintf(tofpe,"%f\n",x);
			y = 3.6+j*9.9+0.8*m;
	        fprintf(tofpe,"%f\n",y);
            zmunit.wpdj[12] = 0;
			trim(zmunit.wpdj);
			if (zmunit.wpdj[0] == '~')
				zmunit.wpdj[0] = 0;
	        fprintf(tofpe,"%s\n",zmunit.wpdj);

		    fprintf(tofpe,"text\n");
			x = 15.2;
	        fprintf(tofpe,"%f\n",x);
			y = 3.6+j*9.9+0.8*m;
	        fprintf(tofpe,"%f\n",y);
            zmunit.wpsl[14] = 0;
			trim(zmunit.wpsl);
			if (zmunit.wpsl[0] == '~')
				zmunit.wpsl[0] = 0;
	        fprintf(tofpe,"%s\n",zmunit.wpsl);

		    fprintf(tofpe,"text\n");
			x = 17.4;
	        fprintf(tofpe,"%f\n",x);
			y = 3.6+j*9.9+0.8*m;
	        fprintf(tofpe,"%f\n",y);
            zmunit.zje[14] = 0;
			trim(zmunit.zje);
			if (zmunit.zje[0] == '~')
				zmunit.zje[0] = 0;
	        fprintf(tofpe,"%s\n",zmunit.zje);

			fclose(fpe1);
			order ++;
          }
		  if (j != 0){
		    fprintf(tofpe,"text\n");
			x = 1;
	        fprintf(tofpe,"%f\n",x);
			y = 0.5+j*9.9;
	        fprintf(tofpe,"%f\n",y);
	        fprintf(tofpe,"%s\n",xiaoming);
          }
      }

      fprintf(tofpe,"endpage\r\n");
  }
  fclose(fpe);
  fclose(tofpe);

  fpe = fopen("c:\\prtset.txt","wb");
  fprintf(fpe,"2100\n");
  fprintf(fpe,"2970\n");
  fprintf(fpe,"1\n");
  fclose(fpe);

  _spawnl(_P_WAIT,"c:\\xxsbgl\\prt.exe","c:\\xxsbgl\\prt.exe",NULL);
		
}


void Cckfhdlg::OnBaocun() 
{
	// TODO: Add your control notification handler code here
   FILE *fpe;
   int num;
   long l;
   char buf[100];
   CString str;
   char b1[50],b2[50],b3[50],b4[50],b5[50],b6[50];
   CWnd *pwnd;
   char buf1[100];
   double sl;
   int mod_rec,i;
   char ckbh[20];
   
   l = m_sbck.GetRowSel();
   m_sbck.SetRow(l);
   m_sbck.SetCol(0L);
   str = m_sbck.GetText();
   strcpy(buf,str.GetBuffer(20));
   for (i=0;i<strlen(buf);i++){
	   if (buf[i] == '*')
		   buf[i] = ' ';
   }
   trim(buf);
   strcpy(ckbh,buf);
   mod_rec = l-1;
   m_sbck.SetCol(0L);
   str = m_sbck.GetText();
   strcpy(buf,str.GetBuffer(20));
   for (i=0;i<strlen(buf);i++){
	   if (buf[i] == '*')
		   buf[i] = ' ';
   }
   trim(buf);
   if (buf[0] == 0){
	   MessageBox("对不起,您没有选择要修改的纪录.","",MB_OK);
	   return ;
   }

	GetDlgItemText(IDC_sbmc,buf,50);
	if ((strlen(buf) == 0)||(strstr(buf,"其他") != NULL)||(strstr(buf,"其它") != NULL)){
		MessageBox("没有输入具体设备名称,不能保存.",MB_OK);
	    pwnd = GetDlgItem(IDC_sbmc);
	    pwnd->SetFocus();	
		return ;
    }
	float f;
	int t;

	GetDlgItemText(IDC_ckfs,str);
	strcpy(buf,str.GetBuffer(22));
	if ((strlen(buf) == 0)||(strlen(buf) >= 20)){
		MessageBox("出库方式错误.",MB_OK);
	    pwnd = GetDlgItem(IDC_rkfs);
	    pwnd->SetFocus();	
		return ;
    }
	GetDlgItemText(IDC_jbr,str);
	strcpy(buf,str.GetBuffer(12));
	if ((strlen(buf) == 0)||(strlen(buf) > 10)){
		MessageBox("经办人错误.",MB_OK);
	    pwnd = GetDlgItem(IDC_jbr);
	    pwnd->SetFocus();	
		return ;
    }
	GetDlgItemText(IDC_rkn,str);
	strcpy(buf,str.GetBuffer(6));
	t = atoi(buf);
	if ((t < 1990)||(t > 2100)){
		MessageBox("入库年份错误.",MB_OK);
	    pwnd = GetDlgItem(IDC_rkn);
	    pwnd->SetFocus();	
		return ;
    }
	GetDlgItemText(IDC_rky,str);
	strcpy(buf,str.GetBuffer(4));
	t = atoi(buf);
	if ((t < 1)||(t > 12)){
		MessageBox("入库月份错误.",MB_OK);
	    pwnd = GetDlgItem(IDC_rky);
	    pwnd->SetFocus();	
		return ;
    }
	GetDlgItemText(IDC_rkr,str);
	strcpy(buf,str.GetBuffer(4));    
	t = atoi(buf);
	if ((t < 1)||(t > 31)){
		MessageBox("入库日期错误.",MB_OK);
	    pwnd = GetDlgItem(IDC_rkr);
	    pwnd->SetFocus();	
		return ;
    }

   fpe = fopen("c:\\xxsbgl\\sbck.dat","r+b");
   if (fpe != NULL){
		fseek(fpe,0L,SEEK_END);
		l = ftell(fpe);
		num = l/280;
		l = order_of_recs[mod_rec] * 280L;
		fseek(fpe,l,SEEK_SET);
		strcpy(sbckunit.reserve,"");
	    GetDlgItemText(IDC_ckfx,str);
	    strcpy(buf,str.GetBuffer(20));
		strcpy(sbckunit.ckfx,buf);
	    m_sbck.SetCol(0L);
	    str = m_sbck.GetText();
        strcpy(buf,str.GetBuffer(11));
        for (i=0;i<strlen(buf);i++){
	      if (buf[i] == '*')
		    buf[i] = ' ';
		}
		trim(buf);
		strcpy(sbckunit.ckbh,buf);

	    GetDlgItemText(IDC_sbmc,str);
	    strcpy(buf,str.GetBuffer(50));
		strcpy(sbckunit.sbmc,buf);

	    GetDlgItemText(IDC_gdbh,str);
	    strcpy(buf,str.GetBuffer(10));
		strcpy(sbckunit.gdbh,buf);

	    GetDlgItemText(IDC_yqdm,str);
	    strcpy(buf,str.GetBuffer(20));
		strcpy(sbckunit.yqdm,buf);

	    GetDlgItemText(IDC_ckfx,str);
	    strcpy(buf,str.GetBuffer(20));
		strcpy(sbckunit.ckfx,buf);
	
	    GetDlgItemText(IDC_pyjx,str);
	    strcpy(buf,str.GetBuffer(10));
		strcpy(sbckunit.pyjx,buf);

	    GetDlgItemText(IDC_ckfs,str);
	    strcpy(buf,str.GetBuffer(20));
		strcpy(sbckunit.ckfs,buf);

	    GetDlgItemText(IDC_rkn,str);
	    strcpy(buf,str.GetBuffer(6));
		strcpy(sbckunit.ckn,buf);

	    GetDlgItemText(IDC_rky,str);
	    strcpy(buf,str.GetBuffer(3));
		strcpy(sbckunit.cky,buf);

	    GetDlgItemText(IDC_rkr,str);
	    strcpy(buf,str.GetBuffer(3));
		strcpy(sbckunit.ckr,buf);
    
	    GetDlgItemText(IDC_cksl,str);
	    strcpy(buf,str.GetBuffer(15));
		sl = atof(buf);
	    sprintf(buf,"%#.2lf",sl);
	    if ((buf[strlen(buf)-1] == '0') && (buf[strlen(buf)-2] == '0')){
          l = sl;
	      sprintf(buf,"%#ld",l);
		}
		strcpy(sbckunit.cksl,buf);

	    GetDlgItemText(IDC_jbr,str);
	    strcpy(buf,str.GetBuffer(50));
		strcpy(sbckunit.jbr,buf);

        m_sbck.SetCol(1L);
        str = m_sbck.GetText();
        strcpy(buf,str.GetBuffer(15));
		strcpy(sbckunit.wpdj,buf);

        m_sbck.SetCol(13L);
        str = m_sbck.GetText();
        strcpy(buf,str.GetBuffer(10));
		strcpy(sbckunit.rkbh,buf);
		
        m_sbck.SetCol(5L);
        str = m_sbck.GetText();
        strcpy(buf,str.GetBuffer(15));
		
//		double zje1,dj1,sl1;
//		zje1 = atof(buf);
//		dj1 = atof(sbckunit.wpdj);
//		sl1 = atof(sbckunit.cksl);
//		if (fabs(zje1 - dj1*sl1) > 0.1){
//			zje1 = dj1*sl1;
//			sprintf(buf,"%#.2lf",zje1);
//		}
		strcpy(sbckunit.zje,buf);

		fwrite(&(sbckunit.reserve[0]),sizeof(sbckstrt),1,fpe);

        fclose(fpe);
   }

   l = mod_rec + 1;
   m_sbck.SetRow(l);
   m_sbck.SetCol(4L);
   GetDlgItemText(IDC_ckfs,buf,40);
   m_sbck.SetText(buf);
   m_sbck.SetCol(6L);
   GetDlgItemText(IDC_rkn,buf,40);
   strcpy(buf1,buf);
   strcat(buf1,"年");
   GetDlgItemText(IDC_rky,buf,40);
   strcat(buf1,buf);
   strcat(buf1,"月");
   GetDlgItemText(IDC_rkr,buf,40);
   strcat(buf1,buf);
   strcat(buf1,"日");
   m_sbck.SetText(buf1);
   m_sbck.SetCol(7L);
   GetDlgItemText(IDC_jbr,buf,40);
   m_sbck.SetText(buf);
   m_sbck.SetCol(11L);
   GetDlgItemText(IDC_ckfx,buf,40);
   m_sbck.SetText(buf);
   pwnd = GetDlgItem(IDC_ckfs);
   pwnd->SetFocus();	
}

⌨️ 快捷键说明

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