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

📄 cms_editdlg.cpp

📁 文本处理软件
💻 CPP
字号:
// CMS_editDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CMS_edit.h"
#include "CMS_editDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define   D_Max   5157
int Max = 5157;

char Variables[128];

char * pVariables[100];
static int line;
static CSV_Store  CSV_Store_Obj[1000];
static CSV_Store  CTX_Store_Obj[4];
static int CSV_Read;

static 	char main_head[20][128] ;
static 	char main_mid[120][128] ;
static 	char main_end[120][128] ;
static 	main_head_line;
static 	main_mid_line;
static 	main_end_line;

	CStringArray   strarray_H; 
	CStringArray   strarray_M; 
	CStringArray   strarray_E; 
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
char*Replace(const   char*sourcestr,const   char*replacesourcestr,const   char*   replacedestinedstr,char*destinedstr); 
void CMS_edit();
void CMS_Copy();

void Read_file_to_Array_H(CString   m_strPathIndex);
void Read_file_to_Array_M(CString   m_strPathIndex);
void Read_file_to_Array_E(CString   m_strPathIndex);
/////////////
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()

/////////////////////////////////////////////////////////////////////////////
// CCMS_editDlg dialog

CCMS_editDlg::CCMS_editDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCMS_editDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCMS_editDlg)
	m_TEXT = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CCMS_editDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCMS_editDlg)
	DDX_Text(pDX, IDC_TEXT, m_TEXT);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCMS_editDlg, CDialog)
	//{{AFX_MSG_MAP(CCMS_editDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON2, LOAD_CSV)
	ON_BN_CLICKED(IDC_BUTTON5, On_H_M_E_load)
	ON_BN_CLICKED(IDC_BUTTON6, On_Mix)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCMS_editDlg message handlers

BOOL CCMS_editDlg::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 CCMS_editDlg::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 CCMS_editDlg::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 CCMS_editDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}


void CCMS_editDlg::LOAD_CSV() 
{
    char na1[50] = "CSV.csv";
    
    line=0;

	FILE *f_csv_L;
    int i;
    f_csv_L = fopen(na1,"r");
    if(f_csv_L==NULL)
	{//读写文件为空时候的处理
       return;
	}
	i=0;

	//按行读取
	for(i=0;i<=Max-1;i++)
	{//MessageBox(0,"Hello","Welcome Message",1);
		if( !feof (f_csv_L))
		{
			line++;
			CSV_Store_Obj[i].Row_Id = line ;

		    //MessageBox(0,"Hello","Welcome Message",0);
		    fscanf(f_csv_L,"%s\n",&Variables);
		   	CString strCmdLine  = Variables;

			//分割符号为“,”
         	CString strSub = _T(",");

        	int nFind = strCmdLine.Find(strSub);
			//得到1排的值
			CSV_Store_Obj[i].First_Id = strCmdLine.Left(nFind);

			int mFind = strCmdLine.GetLength();
			//得到2排的值
			CSV_Store_Obj[i].Sec_Id = strCmdLine.Right(mFind-nFind-1);

            CString aaa;
			aaa.Format("%d",nFind);
			//AfxMessageBox(aaa, 0, 0);

			//AfxMessageBox(CSV_Store_Obj[0].First_Id, 0, 0);
            //AfxMessageBox(CSV_Store_Obj[0].Sec_Id  , 0, 0);
		}
	}
    fclose(f_csv_L);
	CString line_str;
	line_str.Format("%d",line);
	AfxMessageBox("行数:"+line_str, 0, 0);
	AfxMessageBox(CSV_Store_Obj[3 - 1].First_Id, 0, 0); 
    AfxMessageBox(CSV_Store_Obj[3 - 1].Sec_Id  , 0, 0);
}


void CCMS_editDlg::On_H_M_E_load() 
{
 	Read_file_to_Array_H("demo//demo_head.ctx");
	Read_file_to_Array_M("demo//demo_mid.ctx");
	Read_file_to_Array_E("demo//demo_end.ctx");


/*	CStringArray   strarray;   //边读边写的临时变量
	CStdioFile   file;   
	CString   m_strPathIndex   =   "Feeding.ctx";   
	if(   !file.Open(m_strPathIndex,   CFile::modeRead)   )   
	{   
		return;   
	}   
	CString   strLine;   
	while(file.ReadString(strLine))   
	{   
		strarray.Add(strLine);   
	}   
	file.Close();   
	CString   str;   
	int   nCount=strarray.GetSize();   
	DeleteFile(m_strPathIndex);   
	if(   !file.Open(m_strPathIndex,   CFile::modeCreate|CFile::modeWrite)   )   
	{   
		return;   
	}   
	for(int   i=1;   i<strarray.GetSize();   i++)   //删除第一行
	{   
		str   =   strarray[i]   ;  
		//str =  "qqqqqqq";
		file.WriteString(str);   
		file.WriteString("\n");   
	}   
	file.Close();*/
}

void CCMS_editDlg::On_Mix() 
{
	CStdioFile   file;   
	CString   m_strPathIndex   =   "demo.ctx";   

	CString   str;   
	int   nCount_H=strarray_H.GetSize();  
	int   nCount_M=strarray_M.GetSize();  
	int   nCount_E=strarray_E.GetSize(); 
	int   i,j;
	
	DeleteFile(m_strPathIndex);   
	if(   !file.Open(m_strPathIndex,   CFile::modeCreate|CFile::modeWrite)   )   
	{   
		return;
	}
	for( i=0;   i<nCount_H;   i++)  
	{   
		str   =   strarray_H[i]   ;
		file.WriteString(str);
		file.WriteString("\n");
	}   
	for( i=0;   i<nCount_M;   i++)  
	{   
		str   =   strarray_M[i]   ;
		file.WriteString(str);
		file.WriteString("\n");
	}  

	CSV_Read = 0;
	for(j=0;j<=line-1;j++)
	{
		for( i=0;   i<nCount_M;   i++) 
		{   
			if(i==14-1)         //14行 有一个点的名字
			{
				//获得当前行的串
				CString CSR_dame_mid = strarray_M[i];
		    	CString str_point = _T("POINT_NAME_CWL");
		     	int nFind_point = CSR_dame_mid.Find(str_point);
		    	if(nFind_point!=-1)
				{
					//获得左边串部分
			        CString Mid_Left = CSR_dame_mid.Left(nFind_point);
			        int m_Length = CSR_dame_mid.GetLength();
					int m_point_Length  = str_point.GetLength();
					//获得左边串部分
			        CString Mid_Right = CSR_dame_mid.Right(m_Length-nFind_point-m_point_Length);
				    CString Show_Str = Mid_Left + CSV_Store_Obj[CSV_Read].First_Id + Mid_Right;

			        file.WriteString(Show_Str);
			        file.WriteString("\n");

					//CSV_Read++;
				}
				else
				{
					AfxMessageBox(" piont write out", 0, 0);
				}

			}
			else if(i==158-1)
			{
				//获得当前行的串
				CString CSR_dame_mid = strarray_M[i];
		    	CString str_TEXT = _T("TEXT_NAME_CWL");
		     	int nFind_TEXT = CSR_dame_mid.Find(str_TEXT);
		    	if(nFind_TEXT!=-1)
				{
					//获得左边串部分
			        CString Mid_Left = CSR_dame_mid.Left(nFind_TEXT);
			        int m_Length = CSR_dame_mid.GetLength();
					int m_point_Length  = str_TEXT.GetLength();
					//获得左边串部分
			        CString Mid_Right = CSR_dame_mid.Right(m_Length-nFind_TEXT-m_point_Length);
				    CString Show_Str = Mid_Left + CSV_Store_Obj[CSV_Read].Sec_Id + Mid_Right;

			        file.WriteString(Show_Str);
			        file.WriteString("\n");

					CSV_Read++;
				}
				else
				{
					AfxMessageBox(" name write out", 0, 0);
				}

			}
			else
			{
		    	str   =   strarray_M[i]   ;
		    	file.WriteString(str);
		    	file.WriteString("\n");
			}
		}  
	}

	for( i=0;   i<nCount_E;   i++)   //删除第一行
	{   
		str   =   strarray_E[i]   ;
		file.WriteString(str);
		file.WriteString("\n");
	}  
	file.Close();
}

void Read_file_to_Array_H(CString   m_strPathIndex)
{
    //CStringArray   strarray_H;   //边读边写的临时变量
	CStdioFile   file;   
	//CString   m_strPathIndex   =   "Feeding.ctx";   
	if(   !file.Open(m_strPathIndex,   CFile::modeRead)   )   
	{   
		return;   
	}   
	CString   strLine;   
	while(file.ReadString(strLine))   
	{   
		strarray_H.Add(strLine);   
	}   
	file.Close(); 
}
void Read_file_to_Array_M(CString   m_strPathIndex)
{
    //CStringArray   strarray_H;   //边读边写的临时变量
	CStdioFile   file;   
	//CString   m_strPathIndex   =   "Feeding.ctx";   
	if(   !file.Open(m_strPathIndex,   CFile::modeRead)   )   
	{   
		return;   
	}   
	CString   strLine;   
	while(file.ReadString(strLine))   
	{   
		strarray_M.Add(strLine);   
	}   
	file.Close(); 
}
void Read_file_to_Array_E(CString   m_strPathIndex)
{
    //CStringArray   strarray_H;   //边读边写的临时变量
	CStdioFile   file;   
	//CString   m_strPathIndex   =   "Feeding.ctx";   
	if(   !file.Open(m_strPathIndex,   CFile::modeRead)   )   
	{   
		return;   
	}   
	CString   strLine;   
	while(file.ReadString(strLine))   
	{   
		strarray_E.Add(strLine);   
	}   
	file.Close(); 
}

⌨️ 快捷键说明

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