📄 sttooldlg.cpp
字号:
// StToolDlg.cpp : implementation file
//
#include "stdafx.h"
#include "StTool.h"
#include "StToolDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
#define MaxDirLength 256
#define MaxLength 512
#define MAXNAMELength 20
#define N 60
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static char SName[MaxLength][MAXNAMELength]=
{"兴业银行","万科A","招商银行","中国石化","苏宁电器","华夏银行","武钢股份","中国人寿","中信证券","大秦铁路",
"华能国际","长安汽车","深赤湾","中联重科","铜陵有色","晋西车轴","安徽合力","天津港","上港集团","青岛海尔",
"中国平安","唐钢股份","锡业股份","蓝星新材","云南铜业","泸州老窖","深发展A","金地集团","南方航空","浦发银行",
"广陆数测","中国船舶","东方锅炉","华侨城A","招商地产","岳阳纸业","太钢不锈","鞍钢股份","贵州茅台","广船国际",
"云天化","宝钢股份","安阳钢铁","济南钢铁","FUY股份","潞安环能","中国国航","中国神华","中国远洋","盐湖钾肥",
"山东黄金","保利地产","神火股份","潍柴动力","宝钛股份","火箭股份","烟台万华","海螺水泥","焦作万方","中国联通"
};
static double headdata[MaxLength]=
{7.01, 58.8343, 47.1144, 84.9903, 9.7612, 16.8660,31.3520,15.00,27.9156,35.1130,
28.7798,5.5510,1.1731,4.1701,5.5750,0.6112,2.3452,8.6814,79.9241,7.5569,
8.0500,11.0573,2.5736,1.5600,3.6497,3.7500,15.5019,5.6269,10.0000,32.6061,
0.1450,1.3478,1.2825, 4.8987,3.1715,1.7127,10.1894,10.5304,4.0793,1.6063,
2.1021,56.1108,10.0792,4.9150,4.6137,2.1250,11.6613,12.6000 ,12.4887,3.9069,
0.7755,5.2594,3.116,1.7551,1.7890,3.6780,8.2343,2.6278 ,2.8421,83.2228
};
int GetData(char *filename, char * str,int n,int * code ,double * value,int * length);
int GetData(char *filename, char * str,int n,int * code ,double * value,int * length)
{
FILE * stream;
char *p;
char *endptr;
char string[MaxDirLength];
*length=0;
stream=fopen(filename,"r");
while(fgets(string,MaxDirLength,stream))
{
if(strstr(string,"CD")!=NULL)
{
p = strtok(string, " ");
p = strtok(NULL, " ");
*code++ = strtol(p, &endptr, 10);
*length=*length+1;
*value++ =0;
}
else if(strstr(string,str)!=NULL)
{
code--;
value--;
*length=*length-1;
p = strtok(string, "|");
p = strtok(NULL, "|");
p = strtok(NULL, "|");
*value++ = strtod(p, &endptr);
code++;
*length=*length+1;
}
}
fclose(stream);
return n;
}
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStToolDlg dialog
CStToolDlg::CStToolDlg(CWnd* pParent /*=NULL*/)
: CDialog(CStToolDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CStToolDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CStToolDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStToolDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStToolDlg, CDialog)
//{{AFX_MSG_MAP(CStToolDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTONData, OnBUTTONData)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStToolDlg message handlers
BOOL CStToolDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CStToolDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CStToolDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CStToolDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CStToolDlg::OnBUTTONData()
{
// TODO: Add your control notification handler code here
int i,j,m;
int Code1[MaxLength];
double Value1[MaxLength];
int Code2[MaxLength];
double Value2[MaxLength];
int Ne,Nl,Na,Ns;
CString s;
CString s2;
CString Str;
char filename1[]="200709.urt";
char filename2[]="200712.urt";
int Length;
double sum1;
double sum2;
double sume;
double suml;
double suma;
double sums;
char s1[MaxDirLength];
FILE * stream=NULL;
for(j=0;j<N;j++)
{
Str.Empty();
Str+=SName[j];
Str+=".urt";
Ne=0;
Nl=0;
Na=0;
Ns=0;
sum1=0;
sum2=0;
sume=0;
suml=0;
suma=0;
sums=0;
for(i=0;i<Str.GetLength();i++)
{
s1[i]=Str.GetAt(i);
}
s1[i]=0;
stream=fopen(s1,"w");
s.Format(" 2007年9月 \n");
fwrite(s,sizeof(char),s.GetLength(),stream);
s.Format("代 码 持股数(万股) \n");
fwrite(s,sizeof(char),s.GetLength(),stream);
GetData(filename1,SName[j],1,&Code1[0],&Value1[0],&Length);
m=0;
for( i=0; i<Length;i++)
{
if(Value1[i]!=0)
{
s.Format("%d %10.2f\n", Code1[i], Value1[i]);
// s.Format("%d \n", Code1[i]);
fwrite(s,sizeof(char),s.GetLength(),stream);
sum1+=Value1[i];
m++;
}
}
// s.Format("N=%d sum=%10.2f %10.2f \n", m,sum1,(sum1/headdata[j])/100);
s.Format("持有家数%d 共持股%10.2f 流通股数%10.2f(亿股) 占流通A比%6.2f \n", m,sum1,headdata[j],(sum1/headdata[j])/100);
fwrite(s,sizeof(char),s.GetLength(),stream);
s.Format(" \n 2007年12月 \n");
fwrite(s,sizeof(char),s.GetLength(),stream);
s.Format("代 码 持股数(万股) \n");
fwrite(s,sizeof(char),s.GetLength(),stream);
GetData(filename2,SName[j],1,&Code2[0],&Value2[0],&Length);
m=0;
for( i=0; i<Length;i++)
{
if(Value2[i]!=0)
{
s.Format("%d %10.2f \n", Code2[i], Value2[i]);
// s.Format("%d \n", Code2[i]);
fwrite(s,sizeof(char),s.GetLength(),stream);
sum2+=Value2[i];
m++;
}
}
s.Format("持有家数%d 共持股%10.2f 流通股数%8.2f(亿股) 占流通A比%6.2f 增加股数%10.2f 增加比%6.2f \n\n", m,sum2,headdata[j],(sum2/headdata[j])/100,sum2-sum1,((sum2-sum1)/headdata[j])/100);
fwrite(s,sizeof(char),s.GetLength(),stream);
s.Format(" 数据分析 \n");
fwrite(s,sizeof(char),s.GetLength(),stream);
for( i=0; i<Length;i++)
{
if(Value2[i]!=0||Value1[i]!=0)
{
s.Format("%d %10.2f %10.2f %10.2f", Code2[i],Value1[i], Value2[i],Value2[i]-Value1[i]);
if(Value1[i]==0)
{
s2=" 新进 \n";
Ne++;
sume+=Value2[i];
}
else if(Value2[i]==0) {
s2=" 退出 \n";
Nl++;
suml+=Value1[i];
}
else if(Value1[i]>Value2[i])
{
Ns++;
sums+=Value1[i]-Value2[i];
s2.Format(" 减持 减持比%6.2f\n",(Value1[i]-Value2[i])/Value1[i]);
}
else if(Value2[i]>Value1[i])
{
Na++;
suma+=Value2[i]-Value1[i];
s2.Format(" 增持 增持比%6.2f\n",(Value2[i]-Value1[i])/Value1[i]);
}
else s2=" \n";
s+=s2;
fwrite(s,sizeof(char),s.GetLength(),stream);
// sum+=Value2[i];
m++;
}
}
s.Format("\n新进%d 退出%d 新进股数 %10.2f 退出股数 %10.2f \n\n", Ne,Nl,sume,suml);
fwrite(s,sizeof(char),s.GetLength(),stream);
s.Format("增持%d 减持%d 增持股数 %10.2f 减持股数 %10.2f \n\n", Na,Ns,suma,sums);
fwrite(s,sizeof(char),s.GetLength(),stream);
fclose(stream);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -