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

📄 channel.cpp

📁 一个电视台专用的信息管理软件源代码
💻 CPP
字号:
// Channel.cpp: implementation of the CChannel class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"

#include "Channel.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CChannel::CChannel()
{

}

CChannel::~CChannel()
{

}
int CChannel::GetUID()
{
	return UID;
}

void CChannel::SetUID(int iUID)
{
	UID=iUID;
}

CString CChannel::GetName()
{
	return Name;
}

void CChannel::SetName(CString cName)
{
	Name = cName;
}


CString CChannel::GetDesc()
{
	return Desc;
}

void CChannel::SetDesc(CString cDesc)
{
	Desc = cDesc;
}


//数据库操作

	
void CChannel::sql_insert(CString cName,CString cDesc,long& iFlg,CString& cMessage)
{	

	try
	{
		m_pCommand.CreateInstance(__uuidof(Command));
		m_pCommand->ActiveConnection=m_pConnection;
		m_pCommand->CommandType=adCmdStoredProc;
		m_pCommand->CommandText=_bstr_t("ins_Channel");
		
		_variant_t vvar1,vvar2,vvar3,vvar4;
	
		vvar1=_variant_t(_bstr_t(cName));
		vvar2=_variant_t(_bstr_t(cDesc));

		vvar3=_variant_t(iFlg);
		vvar4=_variant_t(_bstr_t(cMessage));

		_ParameterPtr mp_var1,mp_var2,mp_var3,mp_var4;
		mp_var1.CreateInstance(__uuidof(Parameter));
		mp_var2.CreateInstance(__uuidof(Parameter));
		mp_var3.CreateInstance(__uuidof(Parameter));
		mp_var4.CreateInstance(__uuidof(Parameter));
	
		mp_var1=m_pCommand->CreateParameter
		(
		_bstr_t("var1"),
		adVarChar,
		adParamInput,
		50,
		vvar1
		);
		m_pCommand->Parameters->Append(mp_var1); 

		mp_var2=m_pCommand->CreateParameter
		(
		_bstr_t("var2"),
		adVarChar,
		adParamInput,
		200,
		vvar2
		);
		m_pCommand->Parameters->Append(mp_var2); 
		
		
	
		mp_var3=m_pCommand->CreateParameter
		(
		_bstr_t("var3"),
		adBigInt,
		adParamOutput,
		3,
		vvar3
		);
		m_pCommand->Parameters->Append(mp_var3); 

		mp_var4=m_pCommand->CreateParameter
		(
		_bstr_t("var4"),
		adVarChar,
		adParamOutput,
		200,
		vvar4
		);
		m_pCommand->Parameters->Append(mp_var4); 


		_variant_t vNull;
		vNull.vt=VT_ERROR;
		vNull.scode=DISP_E_PARAMNOTFOUND;
		m_pCommand->Execute(&vNull,&vNull,adCmdStoredProc);

		iFlg=mp_var3->Value;
		cMessage=mp_var4->Value.bstrVal;
		}
		catch(_com_error &error)
		{
			AfxMessageBox(error.ErrorMessage(),MB_OK,0);
			AfxMessageBox(error.Description(),MB_OK,0);
			AfxMessageBox("ADO错误!",MB_OK,0);
		}

}

void CChannel::sql_update(long iUID,CString cName,CString cDesc,long& iFlg,CString& cMessage)
{
	
	try
	{
		m_pCommand.CreateInstance(__uuidof(Command));
		m_pCommand->ActiveConnection=m_pConnection;
		m_pCommand->CommandType=adCmdStoredProc;
		m_pCommand->CommandText=_bstr_t("edt_Channel");
		
		_variant_t vvar1,vvar2,vvar3,vvar4,vvar5;
	
		vvar1=_variant_t(_bstr_t(cName));
		vvar2=_variant_t(_bstr_t(cDesc));
	
		vvar3=_variant_t(iUID);
		vvar4=_variant_t(iFlg);
		vvar5=_variant_t(_bstr_t(cMessage));

		_ParameterPtr mp_var1,mp_var2,mp_var3,mp_var4,mp_var5;
		mp_var1.CreateInstance(__uuidof(Parameter));
		mp_var2.CreateInstance(__uuidof(Parameter));
		mp_var3.CreateInstance(__uuidof(Parameter));
		mp_var4.CreateInstance(__uuidof(Parameter));
		mp_var5.CreateInstance(__uuidof(Parameter));
		
	
		mp_var1=m_pCommand->CreateParameter
		(
		_bstr_t("var1"),
		adVarChar,
		adParamInput,
		50,
		vvar1
		);
		m_pCommand->Parameters->Append(mp_var1); 

		mp_var2=m_pCommand->CreateParameter
		(
		_bstr_t("var2"),
		adVarChar,
		adParamInput,
		200,
		vvar2
		);
		m_pCommand->Parameters->Append(mp_var2); 
		
		

		mp_var3=m_pCommand->CreateParameter
		(
		_bstr_t("var3"),
		adBigInt,
		adParamInput,
		5,
		vvar3
		);
		m_pCommand->Parameters->Append(mp_var3); 
	
		mp_var4=m_pCommand->CreateParameter
		(
		_bstr_t("var4"),
		adBigInt,
		adParamOutput,
		3,
		vvar4
		);
		m_pCommand->Parameters->Append(mp_var4); 

		mp_var5=m_pCommand->CreateParameter
		(
		_bstr_t("var5"),
		adVarChar,
		adParamOutput,
		200,
		vvar5
		);
		m_pCommand->Parameters->Append(mp_var5); 


		_variant_t vNull;
		vNull.vt=VT_ERROR;
		vNull.scode=DISP_E_PARAMNOTFOUND;
		m_pCommand->Execute(&vNull,&vNull,adCmdStoredProc);

		iFlg=mp_var4->Value;
		cMessage=mp_var5->Value.bstrVal;
		}
		catch(_com_error &error)
		{
			AfxMessageBox(error.ErrorMessage(),MB_OK,0);
			AfxMessageBox(error.Description(),MB_OK,0);
			AfxMessageBox("ADO错误!",MB_OK,0);
		}

}

void CChannel::sql_delete(long iUID,long& iFlg,CString& cMessage)
{
	try
	{
		m_pCommand.CreateInstance(__uuidof(Command));
		m_pCommand->ActiveConnection=m_pConnection;
		m_pCommand->CommandType=adCmdStoredProc;
		m_pCommand->CommandText=_bstr_t("del_Channel");
		
		_variant_t vvar1,vvar2,vvar3;
	
		vvar1=_variant_t(iUID);
		
		vvar2=_variant_t(iFlg);
		vvar3=_variant_t(_bstr_t(cMessage));

		_ParameterPtr mp_var1,mp_var2,mp_var3;
		mp_var1.CreateInstance(__uuidof(Parameter));
		mp_var2.CreateInstance(__uuidof(Parameter));
		mp_var3.CreateInstance(__uuidof(Parameter));
		
	
		mp_var1=m_pCommand->CreateParameter
		(
		_bstr_t("var1"),
		adVarChar,
		adParamInput,
		20,
		vvar1
		);
		m_pCommand->Parameters->Append(mp_var1); 
	
		mp_var2=m_pCommand->CreateParameter
		(
		_bstr_t("var2"),
		adBigInt,
		adParamOutput,
		5,
		vvar2
		);
		m_pCommand->Parameters->Append(mp_var2); 

		mp_var3=m_pCommand->CreateParameter
		(
		_bstr_t("var3"),
		adVarChar,
		adParamOutput,
		200,
		vvar3
		);
		m_pCommand->Parameters->Append(mp_var3); 


		_variant_t vNull;
		vNull.vt=VT_ERROR;
		vNull.scode=DISP_E_PARAMNOTFOUND;
		m_pCommand->Execute(&vNull,&vNull,adCmdStoredProc);

		iFlg=mp_var2->Value;
		cMessage=mp_var3->Value.bstrVal;
		}
		catch(_com_error &error)
		{
			AfxMessageBox(error.ErrorMessage(),MB_OK,0);
			AfxMessageBox(error.Description(),MB_OK,0);
			AfxMessageBox("ADO错误!",MB_OK,0);
		}
}
	

//pass
//根据员工编号读取所有字段值
void CChannel::GetData(int UID)
{

	//设置SELECT语句
	CString strUID;
	strUID.Format("%d",UID);
	vSQL = "SELECT * FROM Channel WHERE UID=" + strUID;
	//执行SELETE语句
	m_pRecordset = GetRecordSet(vSQL);
	
	//返回各列的值
	if (m_pRecordset->adoEOF)
		CChannel();
	else
	{

		Name = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Name");
		
		Desc = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Description");
		
	}
}

//PASS
void CChannel:: GetAllChannel(CStringArray& allChannels,CString strSQL)
{
	//设置SELECT语句
	vSQL = "SELECT Name FROM Channel WHERE IsDelete =0 " + strSQL;
	//执行SELETE语句
	m_pRecordset = GetRecordSet(vSQL);

	while(!m_pRecordset->adoEOF)
	{
		allChannels.Add((_bstr_t)m_pRecordset->GetCollect("Name"));

		m_pRecordset->MoveNext();
	}
}


int CChannel::getUIDByChannelName(CString channelName)
{
	//设置SELECT语句
	_bstr_t vSQL;
	
	vSQL = "SELECT UID FROM Channel WHERE Name='"+channelName+"'";
	//执行SELETE语句

	m_pRecordset = GetRecordSet(vSQL);
	
	if (m_pRecordset->adoEOF)
	{
		CChannel();
	}
	else
	{
		
		UID = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("UID"));
		
	}
	return UID;
}
void CChannel::ShowList(CListCtrl& listctrl,CString strSQL)
{
	int i=0;
    LV_ITEM lvitem;
	lvitem.mask=LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
	lvitem.state=0;
	lvitem.stateMask=0;

	CString strUID,strDescription,strName;

	//设置SELECT语句
	vSQL = "SELECT * FROM Channel WHERE IsDelete = 0 " +strSQL;
	//执行SELETE语句
	m_pRecordset = GetRecordSet(vSQL);
    
	listctrl.DeleteAllItems();
	 while(!m_pRecordset->adoEOF)
	{   
		lvitem.iItem=i;
		lvitem.iSubItem=0;
		strUID=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("UID");
		lvitem.pszText=(LPTSTR)(LPCTSTR)strUID;  
		listctrl.InsertItem(&lvitem);

		strName =(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Name");
		listctrl.SetItemText(i,1,strName);

		_variant_t varDescription = m_pRecordset->GetCollect("Description");
		if(varDescription.vt != VT_NULL)
		{
			strDescription=(LPCTSTR)(_bstr_t)varDescription;
		}
		listctrl.SetItemText(i,2,strDescription);

		i++;
		m_pRecordset->MoveNext();
	}

}
int CChannel::GetIDByName(CString cName)
{
	int iUID=0;
	vSQL = "SELECT UID FROM Channel WHERE IsDelete=0 AND Name='" + cName+"'";
	//执行SELETE语句
	m_pRecordset = GetRecordSet(vSQL);
	
	//返回各列的值
	if (m_pRecordset->adoEOF)
	{
		CChannel();
	}
	else
	{
		
		iUID = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("UID"));
	
	}

	return iUID;

}

⌨️ 快捷键说明

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