std::string ForexConnectWrapper::getTradesAsYAML() {
    std::string rv;
    IO2GTableManager *tableManager = getLoadedTableManager();

    IO2GTradesTable *tradesTable = (IO2GTradesTable *)tableManager->getTable(Trades);
    IO2GTradeTableRow *tradeRow = NULL;
    IO2GTableIterator tableIterator;
    while (tradesTable->getNextRow(tableIterator, tradeRow)) {
        bool isLong = (strncmp(tradeRow->getBuySell(), "B", 1) == 0);
        double d = tradeRow->getOpenTime();
        std::string openDateTime;
        formatDate(d, openDateTime);

        IO2GOfferRow *offer = getTableRow<IO2GOfferRow, IO2GOffersTableResponseReader>(Offers, tradeRow->getOfferID(), &findOfferRowByOfferId, &getOffersReader);

        rv.append("- symbol: ").append(offer->getInstrument()).append("\n");
        offer->release();
        rv.append("  id: ").append(tradeRow->getTradeID()).append("\n");
        rv.append("  direction: ").append(isLong ? "long" : "short").append("\n");
        rv.append("  openPrice: ").append(double2str(tradeRow->getOpenRate())).append("\n");
        rv.append("  size: ").append(int2str(tradeRow->getAmount())).append("\n");
        rv.append("  openDate: ").append(openDateTime).append("\n");
        rv.append("  pl: ").append(double2str(tradeRow->getGrossPL())).append("\n");

        tradeRow->release();
    }

    tradesTable->release();
    tableManager->release();

    return rv;
}
void CPMSProductSupplyPlan::OnExportSelect(){
	CMainFrame_E10 *pMF = (CMainFrame_E10*) AfxGetMainWnd();
	UpdateData(true);
	CRecord rs(&pMF->m_db);
	CExcel xls;
	CString szSQL, tmpStr;
	double nTmp = 0;
	int nIdx = 1, nRow = 0;
	szSQL = GetQueryString();
	rs.ExecSQL(szSQL);
	if (rs.IsEOF())
	{
		AfxMessageBox(_T("No Data."));
		return;
	}
	xls.CreateSheet(1);
	xls.SetWorksheet(0);
	xls.SetColumnWidth(0, 8);
	xls.SetColumnWidth(1, 30);
	xls.SetColumnWidth(2, 30);
	xls.SetCellMergedColumns(0, 0, 2);
	xls.SetCellMergedColumns(0, 1, 2);
	xls.SetCellMergedColumns(0, 2, 6);
	xls.SetCellMergedColumns(0, 3, 6);
	xls.SetCellText(0, 0, pMF->m_szHealthService, 4098, true);
	xls.SetCellText(0, 1, pMF->m_szHospitalName, 4098, true);
	//TODO: Write Excel Name
	tmpStr = _T("\x42\xC1O \x43\xC1O \x44\x1EF0 TR\xD9 MU\x41 THU\x1ED0\x43");
	xls.SetCellText(0, 2, tmpStr, 4098, true);
	tmpStr.Format(_T("T\x1EEB ng\xE0y %s \x111\x1EBFn ng\xE0y %s"), CDate::Convert(m_szFromDate, yyyymmdd, ddmmyyyy), CDate::Convert(m_szToDate, yyyymmdd, ddmmyyyy));
	xls.SetCellText(0, 3, tmpStr, 4098, true);
	//TODO: Write Column Header
	nRow = 4;
	xls.SetCellText(0, nRow, _T("STT"), 4098, true);
	xls.SetCellText(1, nRow, _T("T\xEAn thu\x1ED1\x63, h\xE0m l\x1B0\x1EE3ng"), 4098, true);
	xls.SetCellText(2, nRow, _T("T\xEAn ho\x1EA1t \x63h\x1EA5t"), 4098, true);
	xls.SetCellText(3, nRow, _T("\x110VT"), 4098, true);
	xls.SetCellText(4, nRow, _T("\x58u\x1EA5t trong k\x1EF3"), 4098, true);
	xls.SetCellText(5, nRow, _T("T\x1ED3n \x63u\x1ED1i k\x1EF3"), 4098, true);
	xls.SetCellText(6, nRow, _T("\x44\x1EF1 tr\xF9 mu\x61"), 4098, true);
	nRow = 6;
	while (!rs.IsEOF())
	{
		xls.SetCellText(0, nRow, int2str(nIdx++), FMT_TEXT | FMT_RIGHT);
		xls.SetCellText(1, nRow, rs.GetValue(_T("name")), FMT_TEXT);
		xls.SetCellText(2, nRow, rs.GetValue(_T("generic")), FMT_TEXT);
		xls.SetCellText(3, nRow, rs.GetValue(_T("unit")), FMT_TEXT);
		rs.GetValue(_T("expqty"), nTmp);
		xls.SetCellText(4, nRow, double2str(nTmp), FMT_NUMBER1);
		rs.GetValue(_T("instockqty"), nTmp);
		xls.SetCellText(5, nRow, double2str(nTmp), FMT_NUMBER1);
		rs.GetValue(_T("plan_qty"), nTmp);
		xls.SetCellText(6, nRow, double2str(nTmp), FMT_NUMBER1);
		nRow++;
		rs.MoveNext();
	}
	xls.Save(_T("Exports\\Bao cao du tru mua thuoc.xls"));
} 
/*void CEMPatientStatbyLocation::OnVillageAddNew(){
	CMainFrame_E10 *pMF = (CMainFrame_E10*) AfxGetMainWnd();
	
} */
void CEMPatientStatbyLocation::OnExportSelect(){
	CMainFrame_E10 *pMF = (CMainFrame_E10*) AfxGetMainWnd();
	UpdateData(true);
	CExcel xls;
	CRecord rs(&pMF->m_db);
	CString szSQL, tmpStr;
	int nCol = 0, nRow = 0, nIdx = 1;
	double nCount = 0, nTotal = 0;
	
	szSQL = GetQueryString();
	rs.ExecSQL(szSQL);
	if (rs.IsEOF())
	{
		AfxMessageBox(_T("No Data."), MB_OK|MB_ICONSTOP);
		return;
	}
	xls.CreateSheet(1);
	xls.SetWorksheet(0);
	xls.SetColumnWidth(0, 5);
	xls.SetColumnWidth(1, 30);
	xls.SetColumnWidth(2, 10);
	xls.SetCellMergedColumns(0, 0, 2);
	xls.SetCellMergedColumns(0, 1, 2);
	xls.SetCellMergedColumns(0, 2, 3);
	xls.SetCellMergedColumns(0, 3, 3);
	xls.SetCellText(0, 0, pMF->m_szHealthService, FMT_TEXT | FMT_CENTER, true);
	xls.SetCellText(0, 1, pMF->m_szHospitalName, FMT_TEXT | FMT_CENTER, true);
	xls.SetCellText(0, 2, _T("TH\x1ED0NG K\xCA \x42\x1EC6NH NH\xC2N T\x1EEANG \x110\x1ECA\x41 PH\x1AF\x1A0NG"), FMT_TEXT | FMT_CENTER, true);
	tmpStr.Format(_T("T\x1EEB ng\xE0y %s \x111\x1EBFn ng\xE0y %s"), m_szFromDate, m_szToDate);
	xls.SetCellText(0, 3, tmpStr, FMT_TEXT | FMT_CENTER, true);
	xls.SetCellText(1, 4, _T("T\x1ED5ng s\x1ED1:"), FMT_TEXT, true);
	xls.SetCellText(0, 5, _T("STT"), FMT_TEXT | FMT_CENTER, true);
	xls.SetCellText(1, 5, _T("T\xEAn"), FMT_TEXT | FMT_CENTER, true);
	xls.SetCellText(2, 5, _T("S\x1ED1 l\x1B0\x1EE3ng"), FMT_TEXT | FMT_CENTER, true);
	nRow = 6;
	while (!rs.IsEOF())
	{
		xls.SetCellText(nCol, nRow, int2str(nIdx++), FMT_TEXT | FMT_RIGHT);
		xls.SetCellText(nCol + 1, nRow, rs.GetValue(_T("locationame")), FMT_TEXT);
		rs.GetValue(_T("cnt"), nCount);
		nTotal += nCount;
		xls.SetCellText(nCol + 2, nRow, double2str(nCount), FMT_NUMBER1);
		nRow++;
		rs.MoveNext();
	}
	xls.SetCellText(nCol + 2, 4, double2str(nTotal), FMT_NUMBER1);
	xls.Save(_T("Exports\\Thong Ke BN theo que quan.xls"));
} 
/*void CPMSExportSheetList::OnStockAddNew(){
	CMainFrame_E10 *pMF = (CMainFrame_E10*) AfxGetMainWnd();
	
} */
void CPMSExportSheetList::OnPrintPreviewSelect(){
	CMainFrame_E10 *pMF = (CMainFrame_E10*) AfxGetMainWnd();
	UpdateData(true);
	CReport rpt;
	CString szSQL, tmpStr, szSysDate, szPrice, szRptName;
	CRecord rs(&pMF->m_db);
	szSQL = GetQueryString();
	int nIdx = 0;
	double nAmount = 0, nTotal = 0;
	int nCount = rs.ExecSQL(szSQL);
	if (nCount <= 0)
	{
		ShowMessage(150, MB_ICONSTOP);
		return;
	}
	szRptName.Format(_T("Reports/HMS/PM_BANGKEPHIEUXUAT.RPT"));
	if (!rpt.Init(szRptName))
		return;
	rpt.GetReportHeader()->SetValue(_T("HealthService"), pMF->m_szHealthService);
	rpt.GetReportHeader()->SetValue(_T("HospitalName"), pMF->m_szHospitalName);
	tmpStr.Format(rpt.GetReportHeader()->GetValue(_T("ReportDate")), CDateTime::Convert(m_szFromDate, yyyymmdd|hhmmss, ddmmyyyy|hhmmss), CDateTime::Convert(m_szToDate, yyyymmdd|hhmmss, ddmmyyyy|hhmmss));
	rpt.GetReportHeader()->SetValue(_T("ReportDate"), tmpStr);
	if (!m_szStockKey.IsEmpty())
		rpt.GetReportHeader()->SetValue(_T("StockName"), m_wndStock.GetCurrent(1));
	CReportSection *rptDetail;
	szPrice = _T("vatamount");
	if (m_nByServPrice)
		szPrice = _T("servamount");
	while (!rs.IsEOF()){
		rptDetail = rpt.AddDetail();
		nIdx++;
		tmpStr.Format(_T("%d"), nIdx);
		rptDetail->SetValue(_T("1"), tmpStr);
		rs.GetValue(_T("orderid"), tmpStr);
		rptDetail->SetValue(_T("2"), tmpStr);
		rs.GetValue(_T("expdate"), tmpStr);
		rptDetail->SetValue(_T("3"), CDate::Convert(tmpStr, yyyymmdd, ddmmyyyy));
		tmpStr.Empty();
		rs.GetValue(_T("patname"), tmpStr);
		rptDetail->SetValue(_T("4"), tmpStr);
		rs.GetValue(_T("id"), tmpStr);
		rptDetail->SetValue(_T("5"), tmpStr);
		rs.GetValue(_T("doctype"), tmpStr);
		rptDetail->SetValue(_T("6"), tmpStr);
		rs.GetValue(szPrice, nAmount);
		nTotal += nAmount;
		rptDetail->SetValue(_T("7"), double2str(nAmount));
		rs.MoveNext();
	}
	rptDetail = rpt.AddDetail(rpt.GetGroupFooter(1));
	tmpStr.Format(_T("%s"), _T("T\x1ED5ng \x63\x1ED9ng"));
	rptDetail->SetValue(_T("TotalAmount"), tmpStr);
	tmpStr.Format(_T("%f"), nTotal);
	rptDetail->SetValue(_T("s7"), tmpStr);
	szSysDate = pMF->GetSysDate();
	tmpStr.Format(rpt.GetReportFooter()->GetValue(_T("PrintDate")), szSysDate.Right(2), szSysDate.Mid(5, 2), szSysDate.Left(4));
	rpt.GetReportFooter()->SetValue(_T("PrintDate"), tmpStr);
	rpt.PrintPreview();
} 
void DriveSubsystem::PrintEncoders() 
{
	try 
	{
		DriverStationLCD::GetInstance()->PrintfLine( DriverStationLCD::kUser_Line1, double2str( m_drive->GetEncoders() ).c_str() );
		DriverStationLCD::GetInstance()->UpdateLCD();
	} 
	catch ( int ex ) 
	{
		std::cerr << "An exception occurred. Exception Nr. " << ex << '\n';
	}
}
Esempio n. 6
0
void WorkloadSynthetic::buildConfigStr()
{
    m_workload_config = "";

    m_workload_config += "  self-similar: ";
    m_workload_config += g_cfg.wkld_synth_ss ? "Yes\n" : "No\n";

    m_workload_config += "  injection load(flit/cycle/core): " + double2str(g_cfg.wkld_synth_load, 4) + "\n";

    m_workload_config += "  injection load(pkt/cycle/core): " + double2str(g_cfg.wkld_synth_load/g_cfg.wkld_synth_num_flits_pkt, 4) + "\n";

    m_workload_config += "  packet inter-arrival time(cycle): " + double2str(m_pkt_inter_arrv_time, 4) + "\n";

    m_workload_config += "  #flits per packet: " + int2str(g_cfg.wkld_synth_num_flits_pkt) + "\n";

    m_workload_config += "  packet length bimodality: ";
    m_workload_config += g_cfg.wkld_synth_bimodal ? string("Yes") : string("No");

    m_workload_config += "  single_flit_pkt_rate: " + double2str(g_cfg.wkld_synth_bimodal_single_pkt_rate, 4) + "\n";

    m_workload_config += "  multicast ratio: " + double2str(g_cfg.wkld_synth_multicast_ratio, 4) + "\n";
    m_workload_config += "  #multicast destinations: " + int2str(g_cfg.wkld_synth_multicast_destnum) + "\n";
}
Esempio n. 7
0
/* returns zero on success, nonzero on error */
static int append_format(
	struct string_builder *bld,
	const struct format_args *args,
	void *argv,
	int *argidx,
	int isval,
	char **errmsg
)
{
	switch (args->spec) {
	case '%':
		append_string(bld, "%", 1);
		break;
	case 's': {
		const char *str;
		size_t len;

		if (isval) {
			SpnString *strobj;

			/* must be a string */
			SpnValue *val = getarg_val(argv, argidx);
			if (!isstring(val)) {
				format_errmsg(
					errmsg,
					TYPE_MISMATCH,
					*argidx,
					SPN_TYPE_STRING,
					val->type
				);
				return -1;
			}

			strobj = stringvalue(val);
			str = strobj->cstr;
			len = strobj->len;
		} else {
			str = getarg_raw(argv, argidx);
			len = strlen(str);
		}

		if (args->precision >= 0 && args->precision < len) {
			len = args->precision;
		}

		if (args->width >= 0 && args->width > len) {
			size_t pad = args->width - len;
			expand_buffer(bld, pad);

			while (pad-- > 0) {
				bld->buf[bld->len++] = ' ';
			}
		}

		append_string(bld, str, len);
		break;
	}
	case 'i':
	case 'd':
	case 'b':
	case 'o':
	case 'u':
	case 'x':
	case 'X': {
		char *buf, *end, *begin;
		size_t len = PR_LONG_DIGITS;
		enum format_flags flags = args->flags;
		unsigned base = base_for_specifier(args->spec);
		long n;
		unsigned long u;

		if (isval) {
			/* must be a number */
			SpnValue *val = getarg_val(argv, argidx);
			if (!isnum(val)) {
				format_errmsg(
					errmsg,
					TYPE_MISMATCH,
					*argidx,
					SPN_TTAG_NUMBER,
					val->type
				);
				return -1;
			}

			if (isint(val)) {
				n = intvalue(val);
			} else {
				n = floatvalue(val); /* truncate */
			}
		} else {
			/* "%i" expects an int, others expect a long */
			if (args->spec == 'i') {
				n = *(const int *)getarg_raw(argv, argidx);
			} else {
				n = *(const long *)getarg_raw(argv, argidx);
			}
		}

		if (args->spec == 'i' || args->spec == 'd') {
			/* signed conversion specifiers */
			if (n < 0) {
				flags |= FLAG_NEGATIVE;
				u = -n;
			} else {
				u = n;
			}
		} else {
			/* unsigned conversion specifiers */
			u = n;
		}

		if (args->spec == 'X') {
			flags |= FLAG_CAPS;
		}

		if (args->width >= 0 && args->width > len) {
			len = args->width;
		}

		buf = spn_malloc(len);
		end = buf + len;
		begin = ulong2str(end, u, base, args->width, flags);

		assert(buf <= begin);
		append_string(bld, begin, end - begin);
		free(buf);

		break;
	}
	case 'c': {
		unsigned char ch;
		int len = 1; /* one character is one character long... */

		if (isval) {
			/* must be an integer */
			SpnValue *val = getarg_val(argv, argidx);

			if (!isnum(val)) {
				format_errmsg(
					errmsg,
					TYPE_MISMATCH,
					*argidx,
					SPN_TTAG_NUMBER,
					val->type
				);
				return -1;
			}

			if (isfloat(val)) {
				format_errmsg(errmsg, EXPECT_INTEGER, *argidx);
				return -1;
			}

			ch = intvalue(val);
		} else {
			ch = *(const long *)getarg_raw(argv, argidx);
		}

		if (args->width > len) {
			len = args->width;
		}

		expand_buffer(bld, len);

		while (len-- > 1) {
			bld->buf[bld->len++] = ' ';
		}

		bld->buf[bld->len++] = ch;

		break;
	}
	case 'f':
	case 'F': {
		char *buf, *end, *begin;
		size_t len;
		int prec;
		double x;
		enum format_flags flags = args->flags;

		if (isval) {
			SpnValue *val = getarg_val(argv, argidx);
			if (!isnum(val)) {
				format_errmsg(
					errmsg,
					TYPE_MISMATCH,
					*argidx,
					SPN_TTAG_NUMBER,
					val->type
				);
				return -1;
			}

			if (isfloat(val)) {
				x = floatvalue(val);
			} else {
				x = intvalue(val);
			}
		} else {
			x = *(const double *)getarg_raw(argv, argidx);
		}

		if (args->spec == 'F') {
			flags |= FLAG_CAPS;
		}

		/* handle special cases */
		if (+1.0 / x == +1.0 / -0.0) {
			/* negative zero: set sign flag and carry on */
			flags |= FLAG_NEGATIVE;
		} else if (
			x != x		/*  NaN */
		     || x == +1.0 / 0.0	/* +inf */
		     || x == -1.0 / 0.0	/* -inf */
		) {
			print_special_fp(bld, flags, args->width, x);
			break;
		}

		if (x < 0.0) {
			flags |= FLAG_NEGATIVE;
			x = -x;
		}

		/* at this point, `x' is non-negative or -0 */

		if (x >= 1.0) {
			len = ceil(log10(x)) + 1; /* 10 ^ n is n + 1 digits long */
		} else {
			len = 1; /* leading zero needs exactly one character */
		}

		prec = args->precision < 0 ? DBL_DIG : args->precision;

		len += prec + 3; /* decimal point, sign, leading zero */

		if (args->width >= 0 && args->width > len) {
			len = args->width;
		}

		buf = spn_malloc(len);
		end = buf + len;
		begin = double2str(end, x, args->width, prec, flags);

		assert(buf <= begin);
		append_string(bld, begin, end - begin);
		free(buf);

		break;
	}
	case 'B': {
		int boolval;
		const char *str;
		size_t len;

		if (isval) {
			/* must be a boolean */
			SpnValue *val = getarg_val(argv, argidx);
			if (!isbool(val)) {
				format_errmsg(
					errmsg,
					TYPE_MISMATCH,
					*argidx,
					SPN_TTAG_BOOL,
					val->type
				);
				return -1;
			}

			boolval = boolvalue(val);
		} else {
			boolval = *(const int *)getarg_raw(argv, argidx);
		}

		str = boolval ? "true" : "false";
		len = strlen(str);

		if (args->precision >= 0 && args->precision < len) {
			len = args->precision;
		}

		if (args->width >= 0 && args->width > len) {
			size_t pad = args->width - len;
			expand_buffer(bld, pad);

			while (pad-- > 0) {
				bld->buf[bld->len++] = ' ';
			}
		}

		append_string(bld, str, len);
		break;
	}
	default:
		format_errmsg(errmsg, INVALID_SPECIFIER, ++*argidx, args->spec);
		return -1;
	}

	return 0;
}
Esempio n. 8
0
void plotFile_timing() {

	// Data file
	TString input = "data/SingleGEM/time_0.0.root";
	
	// Output filename
	TString output = "data/SingleGEM/time_0.0.pdf";	
	
	// Settings
	TString title = "";
	TString xaxis = "Time [ns]";
	TString yaxis = "signal [fC / ns]";
	

	TFile *File = new TFile(input, "READ");
	if(!File->IsOpen()) {
		std::cout << "Problem while opening the file" << std::endl;
		exit();
	}

	File->ls(); // List root file contents
	

	TCanvas *c1 = (TCanvas *)File->Get("c1");
	TH1D *h1= (TH1D*)c1->FindObject("hSignal");
	

	
	TCanvas *c2 = new TCanvas("c1", "plot", 750, 500);
	c2->cd();
	h1->GetXaxis()->SetTitle(xaxis);
	h1->GetYaxis()->SetTitle(yaxis);
	TString rmstitle;
	rmstitle = "RMS: " + double2str(h1->GetRMS());
	h1->SetTitle(rmstitle);
	h1->Scale(-1);
	h1->GetXaxis()->SetRange(0., 300.);

	
	// Style
	h1->SetLineColor(kRed);
	h1->SetLabelSize(0.04, "xyz");
	h1->SetTitleSize(0.04, "xyz");
	h1->SetTitleOffset(1.6, "y");
	
	gStyle->SetPadLeftMargin(0.12);
	gStyle->SetOptStat(0);
	gStyle->SetTitleAlign(33);
	gStyle->SetTitleX(0.925);
	gStyle->SetTitleY(0.95);

	
	h1->Draw();

	
	c2->Update();
	c2->SaveAs(output);
	
	
	//File->Close();


	
}
void CEMStatisticsMajorDiseasesReport::OnExportSelect(){
	_debug(_T("%s"), CString(typeid(this).name()));
	CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd();
	UpdateData(true);
	CRecord rs(&pMF->m_db);
	CString szSQL, szTemp, tmpStr;
	CExcel xls;
	szSQL = GetQueryString();
	BeginWaitCursor();
	rs.ExecSQL(szSQL);
	if (rs.IsEOF())
	{
		ShowMessage(150, MB_ICONSTOP);
		return;
	}
	xls.CreateSheet(1);
	xls.SetWorksheet(0);

	xls.SetColumnWidth(0, 7);
	xls.SetColumnWidth(1, 10);
	xls.SetColumnWidth(2, 78);
	xls.SetColumnWidth(3, 12);

	int nRow = 0, nCol = 0;
	xls.SetCellMergedColumns(nCol, nRow + 2, 4);

	xls.SetCellText(nCol+2, nRow, pMF->m_CompanyInfo.sc_pname, FMT_TEXT | FMT_CENTER, true, 10);
	xls.SetCellText(nCol+2, nRow + 1, pMF->m_CompanyInfo.sc_name, FMT_TEXT | FMT_CENTER, true, 10);
	xls.SetCellMergedColumns(nCol, nRow + 2, 4);
	xls.SetCellMergedColumns(nCol, nRow + 3, 4);
	xls.SetCellText(nCol, nRow + 2, _T("TH\x1ED0NG K\xCA M\x1EB6T \x42\x1EC6NH \x43H\xCDNH"), FMT_TEXT | FMT_CENTER, true, 13);	
	tmpStr.Format(_T("T\x1EEB ng\xE0y %s \x110\x1EBFn ng\xE0y %s"), 
		          CDateTime::Convert(m_szFromDate, yyyymmdd|hhmmss, ddmmyyyy|hhmmss),
				  CDateTime::Convert(m_szToDate, yyyymmdd|hhmmss, ddmmyyyy|hhmmss));
	xls.SetCellText(nCol, nRow + 3, tmpStr, FMT_TEXT | FMT_CENTER, true, 11);
	
	xls.SetCellText(nCol, nRow + 4, _T("STT"), FMT_TEXT | FMT_CENTER, true, 11);

	xls.SetCellText(nCol + 1, nRow + 4, _T("M\xE3 \x62\x1EC7nh"), FMT_TEXT | FMT_CENTER, true, 11);

	xls.SetCellText(nCol + 2, nRow + 4, _T("T\xEAn m\x1EB7t \x62\x1EC7nh"), FMT_TEXT | FMT_CENTER, true, 11);

	xls.SetCellText(nCol + 3, nRow + 4, _T("S\x1ED1 l\x1B0\x1EE3ng"), FMT_TEXT | FMT_CENTER, true, 11);

	nRow += 5;
	int nIndex = 1;
	long double nTotal = 0.0;
	while (!rs.IsEOF())
	{
		szTemp.Format(_T("%d"), nIndex);
		xls.SetCellText(nCol, nRow, szTemp, FMT_INTEGER);

		szTemp = rs.GetValue(_T("hi_icd"));
		xls.SetCellText(nCol + 1, nRow, szTemp, FMT_TEXT);

		szTemp = rs.GetValue(_T("ICDName"));
		xls.SetCellText(nCol + 2, nRow, szTemp, FMT_TEXT);

		szTemp = rs.GetValue(_T("total"));
		nTotal += ToDouble(szTemp);
		xls.SetCellText(nCol + 3, nRow, szTemp, FMT_INTEGER);
		nIndex++;
		nRow++;
		rs.MoveNext();
	}
	xls.SetCellMergedColumns(nCol, nRow, 3);
	xls.SetCellText(nCol, nRow, _T("T\x1ED5ng \x63\x1ED9ng"), FMT_TEXT | FMT_CENTER, true, 12);
	xls.SetCellText(nCol + 3, nRow, double2str(nTotal), FMT_NUMBER1, true, 12 );
	EndWaitCursor();
	xls.Save(_T("Exports\\THONG KE MAT BENH CHINH.XLS"));
} 
void CTMOperationFosteringList::OnExportSelect(){
	CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd();
	UpdateData(true);
	CRecord rs(&pMF->m_db);
	CString szSQL, tmpStr, szMoneyInWord, szTemp;
	int nIdx = 1, nRow = 0;
	double nAmount = 0, nTotalAmount = 0;
	CStringArray arrCol;
	szSQL = GetQueryString();
	rs.ExecSQL(szSQL);
	if (rs.IsEOF())
	{
		AfxMessageBox(_T("No Data."));
		return;
	}
	CExcel xls;
	xls.CreateSheet(1);
	xls.SetWorksheet(0);
	//Header
	xls.SetColumnWidth(0, 5);
	xls.SetColumnWidth(1, 10);
	xls.SetColumnWidth(3, 20);
	xls.SetColumnWidth(4, 20);
	xls.SetColumnWidth(5, 20);
	xls.SetColumnWidth(6, 30);
	xls.SetColumnWidth(7, 10);
	xls.SetColumnWidth(8, 15);
	xls.SetColumnWidth(9, 15);
	xls.SetColumnWidth(10, 15);
	xls.SetColumnWidth(11, 15);
	xls.SetCellMergedColumns(0, 0, 3);
	xls.SetCellMergedColumns(0, 1, 3);
	xls.SetCellMergedColumns(0, 2, 3);
	xls.SetCellMergedColumns(0, 3, 11);
	xls.SetCellMergedColumns(0, 4, 11);
	xls.SetCellText(0, 0, pMF->m_CompanyInfo.sc_pname, 4098, true);
	xls.SetCellText(0, 1, pMF->m_CompanyInfo.sc_name, 4098, true);
	xls.SetCellText(0, 2, pMF->GetCurrentDepartmentName(), 4098, true);
	TranslateString(_T("Operation Fostering List"), szTemp);
	StringUpper(szTemp, tmpStr); 
	xls.SetCellText(0, 3, tmpStr, 4098, true, 12);
	tmpStr.Format(_T("T\x1EEB ng\xE0y %s \x111\x1EBFn ng\xE0y %s"), m_szFromDate, m_szToDate);
	xls.SetCellText(0, 4, tmpStr, 4098, true);
	arrCol.Add(_T("STT"));
	arrCol.Add(_T("S\x1ED1 h\x1ED3 s\x1A1"));
	arrCol.Add(_T("S\x1ED1 BA"));
	arrCol.Add(_T("H\x1ECD v\xE0 t\xEAn"));
	arrCol.Add(_T("N\x103m sinh"));
	arrCol.Add(_T("Th\x1EBB/Qu\xE2n h\xE0m"));
	arrCol.Add(_T("\x44\x61nh m\x1EE5\x63 PTTT"));
	arrCol.Add(_T("T\xEAn PTTT"));
	arrCol.Add(_T("Ph\xE2n lo\x1EA1i PT, TT"));
	//arrCol.Add(_T("K\xEDp th\x1EF1\x63 hi\x1EC7n"));
	arrCol.Add(_T("\x43h\xEDnh"));
	arrCol.Add(_T("Ph\x1EE5"));
	arrCol.Add(_T("Gi\xFAp vi\x1EC7\x63"));
	arrCol.Add(_T("S\x1ED1 l\x1B0\x1EE3ng"));
	arrCol.Add(_T("S\x1ED1 ti\x1EC1n"));
	for (int i = 0; i < arrCol.GetCount(); i++)
		xls.SetCellText(i, 5, arrCol.GetAt(i), 4098, true);
	//Detail
	nRow = 6;
	while (!rs.IsEOF())
	{
		xls.SetCellText(0, nRow, int2str(nIdx++), FMT_TEXT | FMT_RIGHT);
		xls.SetCellText(1, nRow, rs.GetValue(_T("doc_no")), 4098);
		xls.SetCellText(2, nRow, rs.GetValue(_T("record_no")), 4098);
		xls.SetCellText(3, nRow, rs.GetValue(_T("patient_name")), FMT_TEXT);
		xls.SetCellText(4, nRow, rs.GetValue(_T("yob")), 4098);
		xls.SetCellText(5, nRow, rs.GetValue(_T("extra_info")), FMT_TEXT);
		xls.SetCellText(6, nRow, rs.GetValue(_T("operation_name1")), FMT_TEXT);
		xls.SetCellText(7, nRow, rs.GetValue(_T("operation_name")), FMT_TEXT);
		xls.SetCellText(8, nRow, rs.GetValue(_T("operation_type")), 4098);
		xls.SetCellText(9, nRow, rs.GetValue(_T("practitioner")), FMT_TEXT);
		xls.SetCellText(10, nRow, rs.GetValue(_T("assistant")), FMT_TEXT);
		xls.SetCellText(11, nRow, rs.GetValue(_T("anethetist")), FMT_TEXT);
		xls.SetCellText(12, nRow, rs.GetValue(_T("quantity")), FMT_NUMBER1);
		rs.GetValue(_T("amount"), nAmount);
		nTotalAmount += nAmount;
		xls.SetCellText(13, nRow, double2str(nAmount), FMT_NUMBER1);
		nRow++;
		rs.MoveNext();
	}
	if (nTotalAmount > 0)
	{
		xls.SetCellMergedColumns(0, nRow, 13);
		xls.SetCellText(0, nRow, _T("\x43\x1ED9ng"), 4098, true);
		xls.SetCellText(13, nRow, double2str(nTotalAmount), FMT_NUMBER1);
		nRow++;
		MoneyToString(double2str(nTotalAmount), szMoneyInWord);
		tmpStr.Format(_T("S\x1ED1 ti\x1EC1n \x62\x1EB1ng \x63h\x1EEF: %s"), szMoneyInWord);
		xls.SetCellMergedColumns(0, nRow, 13);
		xls.SetCellText(0, nRow, tmpStr, FMT_TEXT, true);
	}

	xls.Save(_T("Exports\\Danh sach de nghi boi duong PTTT.xls"));
	
} 
Esempio n. 11
0
/*
 * Used when converting result from a query
 */
int val2str(MYSQL* _c, db_val_t* _v, char* _s, int* _len)
{
	int l;
	char* old_s;

	if (!_c || !_v || !_s || !_len || !*_len) {
		LOG(L_ERR, "val2str: Invalid parameter value\n");
		return -1;
	}

	if (VAL_NULL(_v)) {
		if (*_len < sizeof("NULL")) {
			LOG(L_ERR, "val2str: Buffer too small\n");
			return -1;
		}
		*_len = snprintf(_s, *_len, "NULL");
		return 0;
	}
	
	switch(VAL_TYPE(_v)) {
	case DB_INT:
		if (int2str(VAL_INT(_v), _s, _len) < 0) {
			LOG(L_ERR, "val2str: Error while converting string to int\n");
			return -2;
		} else {
			return 0;
		}
		break;

	case DB_BITMAP:
		if (int2str(VAL_BITMAP(_v), _s, _len) < 0) {
			LOG(L_ERR, "val2str: Error while converting string to int\n");
			return -3;
		} else {
			return 0;
		}
		break;

	case DB_DOUBLE:
		if (double2str(VAL_DOUBLE(_v), _s, _len) < 0) {
			LOG(L_ERR, "val2str: Error while converting string to double\n");
			return -4;
		} else {
			return 0;
		}
		break;

	case DB_STRING:
		l = strlen(VAL_STRING(_v));
		if (*_len < (l * 2 + 3)) {
			LOG(L_ERR, "val2str: Destination buffer too short\n");
			return -5;
		} else {
			old_s = _s;
			*_s++ = '\'';
			_s += mysql_real_escape_string(_c, _s, VAL_STRING(_v), l);
			*_s++ = '\'';
			*_s = '\0'; /* FIXME */
			*_len = _s - old_s;
			return 0;
		}
		break;

	case DB_STR:
		l = VAL_STR(_v).len;
		if (*_len < (l * 2 + 3)) {
			LOG(L_ERR, "val2str: Destination buffer too short\n");
			return -6;
		} else {
			old_s = _s;
			*_s++ = '\'';
			_s += mysql_real_escape_string(_c, _s, VAL_STR(_v).s, l);
			*_s++ = '\'';
			*_s = '\0';
			*_len = _s - old_s;
			return 0;
		}
		break;

	case DB_DATETIME:
		if (time2str(VAL_TIME(_v), _s, _len) < 0) {
			LOG(L_ERR, "val2str: Error while converting string to time_t\n");
			return -7;
		} else {
			return 0;
		}
		break;

	case DB_BLOB:
		l = VAL_BLOB(_v).len;
		if (*_len < (l * 2 + 3)) {
			LOG(L_ERR, "val2str: Destination buffer too short\n");
			return -8;
		} else {
			old_s = _s;
			*_s++ = '\'';
			_s += mysql_escape_string(_s, VAL_STR(_v).s, l);
			*_s++ = '\'';
			*_s = '\0';
			*_len = _s - old_s;
			return 0;
		}			
		break;

	default:
		DBG("val2str: Unknown data type\n");
		return -9;
	}
	/*return -8; --not reached*/
}
void CFMPostedReceiptVoucherList::OnExportSelect(){
	CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd();
	UpdateData(true);
	CExcel xls;
	CRecord rs(&pMF->m_db);
	CString szSQL, tmpStr;
	int nCol = 0, nRow = 0;
	double nCost = 0;
	long double nTtlCost[6];
	int nIdx = 1;
	CStringArray arrField;
	szSQL = GetQueryString();
	rs.ExecSQL(szSQL);
	if (rs.IsEOF())
	{
		AfxMessageBox(_T("No Data"));
		return;
	}
	for (int i = 0; i < 6; i++)
		nTtlCost[i] = 0;
	arrField.Add(_T("staff"));
	arrField.Add(_T("invoiceno"));
	arrField.Add(_T("eamount"));
	arrField.Add(_T("deposit"));
	arrField.Add(_T("iamount"));
	arrField.Add(_T("inpatient_deposit_paid"));
	arrField.Add(_T("inpatient_payment"));
	arrField.Add(_T("totalamount"));
	xls.CreateSheet(1);
	xls.SetWorksheet(0);
	xls.SetColumnWidth(0, 5);
	xls.SetColumnWidth(1, 30);
	for (int i = 3; i < 9; i++)
		xls.SetColumnWidth(i, 15);
	//Header
	xls.SetCellMergedColumns(0, 0, 2);
	xls.SetCellMergedColumns(0, 1, 2);
	xls.SetCellMergedColumns(0, 2, 9);
	xls.SetCellMergedColumns(0, 3, 9);
	xls.SetCellText(0, 0, pMF->m_CompanyInfo.sc_name, 4098, true);
	xls.SetCellText(0, 1, _T("Ph\xF2ng t\xE0i \x63h\xEDnh"), 4098, true);
	xls.SetCellText(0, 2, _T("\x42\x1EA2NG K\xCA \x43H\x1EE8NG T\x1EEA GHI S\x1ED4 - THU"), 4098, true);
	tmpStr.Format(_T("T\x1EEB ng\xE0y %s \x111\x1EBFn ng\xE0y %s"), m_szFromDate, m_szToDate);
	xls.SetCellText(0, 3, tmpStr, 4098);
	for (int i = 0; i < 9; i++)
	{
		if (i < 5 || i > 7)
			xls.SetCellMergedRows(nCol + i, 4, 2);
		else if (i == 5)
			xls.SetCellMergedColumns(nCol + i, 4, 3);
	}
	xls.SetCellText(0, 4, _T("STT"), 528386, true);
	xls.SetCellText(1, 4, _T("H\x1ECD v\xE0 t\xEAn nh\xE2n vi\xEAn"), 528386, true);
	xls.SetCellText(2, 4, _T("S\x1ED1 phi\x1EBFu"), 528386, true);
	xls.SetCellText(3, 4, _T("\x43\xE1\x63 kho\x1EA3n ph\x1EA3i thu \x42N ngo\x1EA1i tr\xFA"), 528386, true);
	xls.SetCellText(4, 4, _T("\x42N t\x1EA1m g\x1EEDi"), 528386, true);
	xls.SetCellText(5, 4, _T("\x43\xE1\x63 kho\x1EA3n ph\x1EA3i thu \x42N n\x1ED9i tr\xFA"), 528386, true);
	xls.SetCellText(5, 5, _T("\x43\x1ED9ng"), 528386, true);
	xls.SetCellText(6, 5, _T("Tr\xED\x63h t\x1EA1m g\x1EEDi"), 528386, true);
	xls.SetCellText(7, 5, _T("Thu th\xEAm"), 528386, true);
	xls.SetCellText(8, 4, _T("T\x1ED5ng thu"), 528386, true);
	nRow = 6;
	while (!rs.IsEOF())
	{
		xls.SetCellText(nCol, nRow, int2str(nIdx++), FMT_TEXT | FMT_RIGHT);
		for (int i = 0; i < arrField.GetCount(); i++)
		{
			if (i < 2)
				xls.SetCellText(nCol + i + 1, nRow, rs.GetValue(arrField.GetAt(i)), FMT_TEXT);
			else
			{
				rs.GetValue(arrField.GetAt(i), nCost);
				nTtlCost[i-2] += nCost;
				xls.SetCellText(nCol + i + 1, nRow, double2str(nCost), FMT_NUMBER1);
			}
		}
		nRow++;
		rs.MoveNext();
	}
	xls.SetCellText(2, nRow, _T("T\x1ED5ng \x63\x1ED9ng"), FMT_TEXT | FMT_CENTER, true);
	for (int i = 0 ; i < 6;i++)	
	{
		tmpStr.Format(_T("%f"), nTtlCost[i]);
		xls.SetCellText(nCol+i+3, nRow, tmpStr, FMT_NUMBER1);
	}	
	xls.Save(_T("Exports\\Bang ke chung tu ghi so - thu.xls"));
} 
void ForexConnectWrapper::saveHistoricalDataToFile(const std::string filename, const std::string symbol, const std::string tf, int totalItemsToDownload) {
        IO2GTimeframeCollection *timeframeCollection = mRequestFactory->getTimeFrameCollection();
        IO2GTimeframe *timeframeObject = NULL;
        int timeframeCollectionSize = timeframeCollection->size();
        for (int i = 0; i < timeframeCollectionSize; i++) {
            IO2GTimeframe *searchTimeframeObject = timeframeCollection->get(i);
            if ( tf == searchTimeframeObject->getID() ) {
                timeframeObject = searchTimeframeObject;
                break;
            } else {
                searchTimeframeObject->release();
            }
        }
        timeframeCollection->release();

        if (!timeframeObject) {
            log("Could not find timeframe");
            throw "Could not find timeframe";
        }


        double timeFrom = 0, timeTo = 0;

        time_t rawtime = time(NULL);
        struct tm timeinfo = *localtime(&rawtime);
        timeinfo.tm_year = 50;
        timeinfo.tm_mon = 0;
        timeinfo.tm_mday = 1;
        timeinfo.tm_hour = 0;
        timeinfo.tm_min = 0;
        timeinfo.tm_sec = 0;

        CO2GDateUtils::CTimeToOleTime(&timeinfo, &timeFrom);
        std::string dd;
        formatDate(timeFrom, dd);

        std::ofstream outputFile;
        outputFile.open(filename.c_str());
        Listener *ll = new Listener(session);
        while (totalItemsToDownload > 0) {
            IO2GRequest *marketDataRequest = mRequestFactory->createMarketDataSnapshotRequestInstrument(symbol.c_str(), timeframeObject, totalItemsToDownload > 300 ? 300 : totalItemsToDownload);
            if (!marketDataRequest) {
                std::ostringstream errorMsg;
                errorMsg << "Failed to create MarketDataSnapshotRequestInstrument for " << symbol.c_str();
                throw  errorMsg.str();
            }
            mRequestFactory->fillMarketDataSnapshotRequestTime(marketDataRequest, timeFrom, timeTo, false);
            IO2GResponse *marketDataResponse = ll->sendRequest(marketDataRequest);
            if (!marketDataResponse) {
                throw "no response to marketDataRequest";
            }

            IO2GMarketDataSnapshotResponseReader *marketSnapshotReader = mResponseReaderFactory->createMarketDataSnapshotReader(marketDataResponse);
            if (!marketSnapshotReader) {
                throw "Failed to create marketSnapshotReader";
            }
            int snapshotSize = marketSnapshotReader->size();
            for (int i = snapshotSize - 1; i >= 0; i--) {
                double date = marketSnapshotReader->getDate(i);
                std::string dateTimeStr;
                formatDate(date, dateTimeStr);
                outputFile << dateTimeStr << "\t" << double2str(marketSnapshotReader->getAskOpen(i)) << "\t" << double2str(marketSnapshotReader->getAskHigh(i)) << "\t" << double2str(marketSnapshotReader->getAskLow(i)) << "\t" << double2str(marketSnapshotReader->getAskClose(i)) << "\t" << std::endl;

            }

            totalItemsToDownload -= snapshotSize;
            if (totalItemsToDownload > 0) {
                timeTo = marketSnapshotReader->getDate(0);
            }
            marketSnapshotReader->release();
        }
        timeframeObject->release();
        ll->release();
        outputFile.close();
}
Esempio n. 14
0
/**
 * Test of the library
 */
int 
main(int argc, char **argv)
{
	double in[32];
	double out[12];
	int i;

	mlp_neural_network_t *n;
	
	int ls[] = { 16, 512, 8 };
	n = mlp_new(ls, 3);
	n->transf_func = &sigmodial;
	n->transf_func_derivate = &sigmodial_derivate;
	mlp_set_learning_rate(n, 0.6);

	//char string[12];
	long long string = 0;
	//for(i = 0; i < 12; i++)
	//	string[i] = 0;
	//printf("%d\n", sizeof(string));
	
	for(i = 0; i < 10000; i++)
	{
		int j;
		char md5[16];
		
		string++;
		//MD5((char *) &string, 8, md5);
	
		char string2[32];
		strcpy(string2, "ciaooooo");
		MD5((char *) &string2, 8, md5);
	
		printf("%lld - \n", string);
		//for(j = 0; j < 16; j++)
		//	printf("%x", (unsigned char) md5[j]);
		//printf("\n");
		
		str2double((char *) &md5, 16, in);
		str2double((char *) &string, 8, out);

		mlp_back_propagate(n, in, out);
	}


	// Facciamo un test
	char test[] = "ciaooooo";
	char md5[16];
	
	MD5((char *) &test, 8, md5);
	str2double((char *) md5, 16, in);

	mlp_execute(n, in, out);

	char output_s[20];
	double2str(out, 8, output_s);

	printf("\n\t");
	//for(i = 0; i < 8; i++)
	//	printf("'%lf' ", out[i]);
	//printf("\n");
		
	printf("'%s' - ", output_s);
	for(i = 0; i < 8; i++)
		printf("'%c' ", output_s[i]);
	printf("\n");

	mlp_delete(n);
	return 0;
}
/*void CEMOperationFosteringListC12::OnObjectAddNew(){
	CMainFrame_E10 *pMF = (CMainFrame_E10 *) AfxGetMainWnd();
	
} */ 
void CEMOperationFosteringListC12::OnPrintPreviewSelect(){
	CMainFrame_E10 *pMF = (CMainFrame_E10*) AfxGetMainWnd();
	UpdateData(true);
	CReport rpt;
	CReportSection* rptDetail = NULL, *rptFooter = NULL;
	CString szSQL, tmpStr, tmpStr2, szDate, szObjects;
	double nTmp = 0, nAmt = 0, nType3 = 0, nOldDoc = 0, nNewDoc = 0;
	int nCount=0;
	CRecord rs(&pMF->m_db);
	int nIdx = 1;
	if (!rpt.Init(_T("Reports\\HMS\\BAO CAO BDPT C12.RPT")))
		return;
	szSQL = GetQueryString();
	rs.ExecSQL(szSQL);
	if (rs.IsEOF())
	{
		return;
	}
	rpt.GetReportHeader()->SetValue(_T("HEALTHSERVICE"), pMF->m_szHealthService);
	rpt.GetReportHeader()->SetValue(_T("HOSPITALNAME"), pMF->m_szHospitalName);
	for (int i = 0; i < m_wndObject.GetItemCount(); i++)
	{
		if (m_wndObject.GetCheck(i))
		{
			m_wndObject.SetCurSel(i);
			if (!szObjects.IsEmpty())
				szObjects += _T(", ");
			szObjects += m_wndObject.GetCurrent(1);
		}
	}
	if (!szObjects.IsEmpty())
		rpt.GetReportHeader()->SetValue(_T("Object"), szObjects);
	else
		rpt.GetReportHeader()->SetValue(_T("Object"), _T("To\xE0n \x62\x1ED9"));
	tmpStr.Format(rpt.GetReportHeader()->GetValue(_T("ReportDate")), CDate::Convert(m_szFromDate, yyyymmdd, ddmmyyyy), CDate::Convert(m_szToDate, yyyymmdd, ddmmyyyy));
	rpt.GetReportHeader()->SetValue(_T("ReportDate"), tmpStr);
	while (!rs.IsEOF())
	{
		rptDetail = rpt.AddDetail();
		rptDetail->SetValue(_T("1"), int2str(nIdx++));
		rptDetail->SetValue(_T("2"), rs.GetValue(_T("patname")));
		rs.GetValue(_T("doc_no"), nNewDoc);
		if (nNewDoc != nOldDoc)
		{
			nCount++;
			nOldDoc = nNewDoc;
		}
		rptDetail->SetValue(_T("3"), rs.GetValue(_T("doc_no")));
		if(rs.GetValue(_T("pobject")) == 'I')
		{
			rptDetail->SetValue(_T("11"), rs.GetValue(_T("cardno")));
		}
		else if(rs.GetValue(_T("pobject")) == 'D')
		{
			rptDetail->SetValue(_T("11"), rs.GetValue(_T("rank")));
		}
		rptDetail->SetValue(_T("4"), rs.GetValue(_T("ptname")));
		rptDetail->SetValue(_T("5"), rs.GetValue(_T("ptlevel")));
		nType3++;
		rptDetail->SetValue(_T("6"), rs.GetValue(_T("thefirst")));
		rptDetail->SetValue(_T("7"), rs.GetValue(_T("thesecond")));
		rptDetail->SetValue(_T("8"), rs.GetValue(_T("assist")));
		rs.GetValue(_T("ptcost"), nTmp);
		nAmt += nTmp;
		rptDetail->SetValue(_T("9"), double2str(nTmp));
		rs.MoveNext();
	}
	
	szDate = pMF->GetSysDate();
	rptFooter = rpt.GetReportFooter();
	tmpStr.Format(rptFooter->GetValue(_T("PrintDate")), szDate.Right(2), szDate.Mid(5, 2), szDate.Left(4));
	rptFooter->SetValue(_T("PrintDate"), tmpStr);
	rptFooter->SetValue(_T("10"), double2str(nAmt));
	rptFooter->SetValue(_T("14"), double2str(nType3));
	rptFooter->SetValue(_T("15"), _T("24000"));
	rptFooter->SetValue(_T("16"), double2str(nType3*24000));
	rptFooter->SetValue(_T("TotalPatient"), int2str(nCount));
	rptFooter->SetValue(_T("TotalItem"), double2str(nType3));
	rptFooter->SetValue(_T("TotalAmount"), double2str(nAmt));
	tmpStr2.Format(_T("%f"), nAmt);
	MoneyToString(tmpStr2, tmpStr);
	tmpStr += _T(" \x111\x1ED3ng.");
	rptFooter->SetValue(_T("SumInWord"), tmpStr);
	rpt.PrintPreview();
}
/*void CPMSProductSupplyPlan::OnStockAddNew(){
	CMainFrame_E10 *pMF = (CMainFrame_E10*) AfxGetMainWnd();
	
} */
void CPMSProductSupplyPlan::OnPrintPreviewSelect(){
	CMainFrame_E10 *pMF = (CMainFrame_E10*) AfxGetMainWnd();
	UpdateData(true);
	CRecord rs(&pMF->m_db);
	CReport rpt;
	CReportSection* rptDetail = NULL,* rptHeader = NULL, * rptGroup = NULL;
	double nTmp = 0;
	int nIdx = 1, j = 0;
	CString szSQL, tmpStr, szReportName, szDate, szPos, szStorages;
	long double nTotal[3];
	for (int i = 0; i < 3; i++)
	{
		nTotal[i] = 0;
	}
	szReportName = _T("Reports\\HMS\\PM_BAOCAODUTRU.RPT");
	if (!rpt.Init(szReportName))
		return;
	szSQL = GetQueryString();
	rs.ExecSQL(szSQL);
	if (rs.IsEOF()){
		AfxMessageBox(_T("No Data"));
		return;
	}
	rptHeader = rpt.GetReportHeader();
	if (rptHeader)
	{
		rptHeader->SetValue(_T("HealthService"), pMF->m_szHealthService);
		rptHeader->SetValue(_T("HospitalName"), pMF->m_szHospitalName);
		rptHeader->SetValue(_T("Department"), pMF->GetDepartmentName(pMF->GetDepartmentID()));
		tmpStr.Format(rptHeader->GetValue(_T("ReportDate")), CDate::Convert(m_szFromDate, yyyymmdd, ddmmyyyy), 
		CDate::Convert(m_szToDate), yyyymmdd, ddmmyyyy);
		rpt.GetReportHeader()->SetValue(_T("ReportDate"), tmpStr);
		for (int i = 0; i < m_wndStock.GetItemCount(); i++)
		{
			if (m_wndStock.GetCheck(i))
			{
				m_wndStock.SetCurSel(i);
				if (!szStorages.IsEmpty())
					szStorages += _T(", ");
				szStorages += m_wndStock.GetCurrent(1);
			}
		}
		if (!szStorages.IsEmpty())
			rptHeader->SetValue(_T("Storage"), szStorages);
		else
			rptHeader->SetValue(_T("Storage"), _T("To\xE0n \x62\x1ED9"));
	}
	while (!rs.IsEOF())
	{
		//Group Seperation
		rptDetail = rpt.AddDetail();
		if (rptDetail)
		{
			rptDetail->SetValue(_T("1"), int2str(nIdx++));
			rptDetail->SetValue(_T("2"), rs.GetValue(_T("name")));
			rptDetail->SetValue(_T("3"), rs.GetValue(_T("generic")));
			rptDetail->SetValue(_T("4"), rs.GetValue(_T("unit")));
			rs.GetValue(_T("expqty"), nTmp);
			nTotal[0]+= nTmp;
			rptDetail->SetValue(_T("6"), double2str(nTmp));
			rs.GetValue(_T("instockqty"), nTmp);
			nTotal[1]+= nTmp;
			rptDetail->SetValue(_T("7"), double2str(nTmp));
			rs.GetValue(_T("plan_qty"), nTmp);
			nTotal[2]+= nTmp;
			rptDetail->SetValue(_T("8"), double2str(nTmp));
		}
		rs.MoveNext();
	}
	tmpStr = pMF->GetSysDate();
	/*szDate.Format(rpt.GetReportFooter()->GetValue(_T("PrintDate")), tmpStr.Right(2), tmpStr.Mid(5,2), tmpStr.Left(4));
	rpt.GetReportFooter()->SetValue(_T("PrintDate"), szDate);*/
	rpt.PrintPreview();

} 
Esempio n. 17
0
int SRAssembler::init(int argc, char * argv[], int rank, int size) {
    //set the default values
	init_match_length = INIT_MATCH_LENGTH_PROTEIN;
	recur_match_length = RECUR_MATCH_LENGTH;
	mismatch_allowed = MISMATCH_ALLOWED_PROTEIN;
	num_rounds = NUM_ROUNDS;
	min_contig_size = MIN_CONTIG_SIZE;
	max_contig_size = MAX_CONTIG_SIZE;
	verbose = VERBOSE;
	assembly_round = ASSEMBLY_ROUND;
	reads_per_file = READS_PER_FILE;
	fastq_format = FASTQ_INTERLEAVED;
	out_dir = OUT_DIR;
	data_dir = "";
	type = QUERY_TYPE;
	assembler_program = ASSEMBLER_PROGRAM;
	gene_finding_program = GENE_FINDING_PROGRAM;
	spliced_alignment_program = SPLICED_ALIGNMENT_PROGRAM;
	start_k = START_K;
	end_k = END_K;
	step_k = STEP_K;
	clean_round = CLEAN_ROUND;
	over_write = OVER_WRITE;
	check_gene_assembled = CHECK_GENE_ASSEMBLED;
	preprocessing_only = PREPROCESSING_ONLY;
	min_score = MIN_SCORE;
	min_coverage = MIN_COVERAGE;
	bool k_format = true;
	this->rank = rank;
	this->size = size;
	unsigned int insert_size = INSERT_SIZE;
	string left_read = "";
	string right_read = "";
	//parse command line options
	bool default_e = true;
	bool default_i = true;
	usage = "usage:\n";
	usage.append("\n");
	usage.append("    SRAssembler [options] -q query_file -P parameter_file -s species\n");
	usage.append("                [-f library_file or -1 reads_file1 -2 reads_file2]\n");
	usage.append("\n");
	usage.append("-q: Required. The FASTA format query file.\n");
	usage.append("-s: Required. Species name. Options:'human', 'mouse', 'rat', 'chicken',\n");
	usage.append("    'drosophila', 'nematode', 'fission_yeast', 'aspergillus', 'arabidopsis',\n");
	usage.append("    'maize', 'rice', 'medicago'.\n");
	usage.append("-P: Required. Parameter configuration file\n");
	usage.append("-f: Required if you do not specify -1 option. Library file\n");
	usage.append("-1: Required if you do not specify library file. The option can be used to\n");
	usage.append("    specify the single-end file name or the left end file name for paired-end\n");
	usage.append("    reads.\n");
	usage.append("-2: Right end file name for paired-end reads\n");
	usage.append("-t: Query file type: Options: 'protein', 'cdna' [Default: " + QUERY_TYPE + "]\n");
	usage.append("-o: Output directory [Default: current directory]\n");
	usage.append("-R: Preprocessing directory [Default: output directory/" + READS_DATA + "]\n");
	usage.append("-m: Minimum contig length to be reported [Default: " + int2str(MIN_CONTIG_SIZE) + "]\n");
	usage.append("-M: Maximum contig length to be reported [Default: " + int2str(MAX_CONTIG_SIZE) + "]\n");
	usage.append("-e: Minimum score [Default: " + double2str(MIN_SCORE) + "]\n");
	usage.append("-c: Minimum coverage [Default: " + double2str(MIN_COVERAGE) + "]\n");
	usage.append("-k: The k-mer set for the internal assembler. The format is:\n");
	usage.append("    start_k:interval:end_k. The start_k and end_k must be odd value, and The\n");
	usage.append("    interval must be even value. For example, '15:10:45' means k-mer value\n");
	usage.append("    15, 25, 35, 45 will be tested.[Default: " + int2str(START_K) + ":" + int2str(STEP_K) + ":" + int2str(END_K) + "]\n");
	usage.append("-z: Insert size of the paired-end reads [Default: " + int2str(INSERT_SIZE) + "]\n");
	usage.append("-n: Number of rounds [Default: " + int2str(NUM_ROUNDS) + "]\n");
	usage.append("-x: Number of reads of split file [Default: " + int2str(READS_PER_FILE) + "]\n");
	usage.append("-A: The internal assembler. Options: 0=>SOAPdenovo 1=>ABySS [Default: " + int2str(ASSEMBLER_PROGRAM) + "]\n");
	usage.append("-S: Spliced alignment program. Options:0=>GenomeThreader, 1=>GeneSeqer,\n");
	usage.append("    2=>Exonerate [Default: " + int2str(SPLICED_ALIGNMENT_PROGRAM) + "]\n");
	usage.append("-G: Gene finding program. Options:0=>None, 1=>Snap [Default: " + int2str(GENE_FINDING_PROGRAM) + "]\n");
	usage.append("-p: Do preprocessing only\n");
	usage.append("-i: Do not start from the last checkpoint\n");
	usage.append("-l: Do not check if the genes are assembled in each round\n");
	usage.append("-a: The round number the assembling starts [Default: " + int2str(ASSEMBLY_ROUND) + "]\n");
	usage.append("-r: The round number to remove the unrelated contigs and reads. For example,\n");
	usage.append("    “3” means SRAssembler do the cleaning at round 3, 6, 9, 12... [Default: " + int2str(CLEAN_ROUND) + "]\n");
	usage.append("-v: Verbose output\n");
	usage.append("-h: Show the usage");


	char c;
	while((c = getopt(argc, argv, "q:s:t:1:2:o:z:n:m:x:r:e:c:a:k:c:f:M:S:P:A:G:R:vpilh")) != -1) {
		 switch (c){
			 case 'q':
				 query_file = optarg;
				 break;
			 case 's':
				 species = optarg;
				 break;
			 case 't':
				 type = optarg;
				 break;
			 case '1':
				 left_read = optarg;
				 break;
			 case '2':
				 right_read = optarg;
				 break;
			 case 'o':
				 out_dir = optarg;
				 break;
			 case 'R':
			 	 data_dir = optarg;
			 	 break;
			 case 'f':
				 library_file = optarg;
				 break;
			 case 'k': {
				 vector<string> tokens;
				 tokenize(optarg, tokens, ":");
			 	 if (tokens.size() != 3)
			 		k_format = false;
			 	 start_k = str2int(tokens[0]);
			 	 step_k = str2int(tokens[1]);
			 	 end_k = str2int(tokens[2]);
			 	 if (start_k <= 0 || start_k > 150 || start_k % 2 == 0) {
			 		k_format = false;
			 		break;
			 	 }
			 	 if (end_k <= 0 || end_k > 150 || end_k % 2 == 0 || end_k <= start_k) {
			 		k_format = false;
			 		break;
			 	 }
			 	 if (step_k <= 0 || step_k > 150 || step_k % 2 == 1) {
			 		k_format = false;
			 		break;
			 	 }
			 	 int k_value = start_k;
			 	 while (k_value < end_k)
			 		k_value += step_k;
			 	 if (k_value > step_k)
			 		 end_k = k_value;
			 	 break;
			 }
			 case 'z':
				 insert_size = str2int(optarg);
				 break;
			 case 'A':
			 	 assembler_program = str2int(optarg);
			 	 break;
			 case 'S':
				 spliced_alignment_program = str2int(optarg);
				 break;
			 case 'G':
			 	 gene_finding_program = str2int(optarg);
			 	 break;
			 case 'P':
			 	 param_file = optarg;
			 	 break;
			 case 'n':
				 num_rounds = str2int(optarg);
				 break;
			 case 'm':
				 min_contig_size = str2int(optarg);
				 break;
			 case 'e':
				 min_score = str2double(optarg);
				 break;
			 case 'c':
				 min_coverage = str2double(optarg);
				 break;
			 case 'M':
				 max_contig_size = str2int(optarg);
				 break;
			 case 'r':
				 clean_round = str2int(optarg);
				 break;
			 case 'x':
				 reads_per_file = str2int(optarg);
				 break;
			 case 'a':
				 assembly_round = str2int(optarg);
				 if (assembly_round == 0)
					 assembly_round = 9999;
				 break;
			 case 'v':
				 verbose = 1;
				 break;
			 case 'p':
			 	 preprocessing_only = 1;
			 	 break;
			 case 'i':
			 	 over_write = 1;
			 	 break;
			 case 'l':
				 check_gene_assembled = 0;
				 break;
			 case 'h':
				 show_usage();
				 return -1;
			 	 break;
			 case '?':
				 string msg = "input error! unknown option : -";
				 msg.append(1,optopt);
				 print_message(msg);         //unknown options
				 return -1;
		  }
	}
    if (argc == 1){
    	show_usage();
    	return -1;
    }
	tmp_dir = out_dir + "/tmp";
	if (data_dir == "")
	    data_dir = out_dir + "/" + READS_DATA;
	results_dir = out_dir + "/output";
	intermediate_dir = results_dir + "/intermediates";
	log_file = results_dir + "/msg.log";
	spliced_alignment_output_file = results_dir + "/output.aln";
	gene_finding_output_file = results_dir + "/output.ano";
	//spliced_alignment_gsq_file = results_dir + "/output.gsq";
	final_contig_file = results_dir + "/all_contigs.fasta";
	summary_file = results_dir + "/summary.html";
	aligned_contig_file = results_dir + "/hit_contigs.fasta";

	int level = Logger::LEVEL_INFO;
	if (verbose)
		level = Logger::LEVEL_DEBUG;
	logger = Logger::getInstance(level, log_file);


	if (param_file != ""){
		if (!file_exists(param_file)){
			print_message("Parameter file : " + param_file + " does not exist!");
			return -1;
		}
	}

	if (library_file != ""){
		if (!file_exists(library_file)){
			print_message("library file: " + library_file + " does not exist!");
			return -1;
		}
		if (!read_library_file())
			return -1;
	} else {
		if (left_read == ""){
			print_message("-1 or -r or library file is required");
			return -1;
		}
		Library lib(0, this->data_dir, this->tmp_dir,this->logger);
		lib.set_format(FORMAT_FASTQ);
		lib.set_left_read(left_read);
		if (right_read != ""){
			lib.set_paired_end(true);
			lib.set_right_read(right_read);
			lib.set_insert_size(insert_size);
			if (!file_exists(right_read)){
				print_message("file: " + right_read + " does not exist!");
				return -1;
			}
		}
		this->libraries.push_back(lib);
	}

	//check missing options
	if (num_rounds <= 0){
		print_message("-n must be larger than 0");
		return -1;
	}
	if (reads_per_file <= 1000){
		print_message("-x value is not valid or too small");
		return -1;
	}

	if (type != TYPE_PROTEIN && type != TYPE_CDNA){
		print_message("-t must be 'protein' or 'cdna'");
		return -1;
	} else {
		if (default_e && type == TYPE_CDNA)
			mismatch_allowed = MISMATCH_ALLOWED_CDNA;
		if (default_i && type == TYPE_CDNA)
			init_match_length = INIT_MATCH_LENGTH_CDNA;
	}
	if (species != "human" && species != "mouse" && species != "rat" && species != "chicken" && species != "drosophila" && species != "nematode" && species != "fission_yeast" && species != "aspergillus" && species != "arabidopsis" && species != "maize" && species != "rice" && species != "medicago"){
		print_message("-s is required");
		return -1;
	}
	if (!k_format){
		print_message("-k format error. The format is : start_k:interval:end_k. The start_k and end_k must be odd value, and The interval must be even value.");
		return -1;
	}
	//check the existence of read files
	if (!file_exists(query_file)){
		print_message("file: " + query_file + " does not exist!");
		return -1;
	}

	if (!file_exists(out_dir)){
		print_message("output directory: " + out_dir + " does not exist!");
		return -1;
	}

	return 0;
}
void CFMFoodSummaryByLevel::OnExportSelect(){
	CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd();
	UpdateData(true);
	CRecord rs(&pMF->m_db);
	CExcel xls;
	CStringArray arrCol;
	CString szSQL, tmpStr;
	double nTmp = 0;
	int nIdx = 1, nRow = 0, k = 0;
	double nTotal[17];
	for (int i = 0; i < 17; i++)
		nTotal[i] = 0;
	szSQL = GetQueryString();
	rs.ExecSQL(szSQL);
	if (rs.IsEOF())
	{
		AfxMessageBox(_T("No Data."));
		return;
	}
	xls.CreateSheet(1);
	xls.SetWorksheet(0);
	xls.SetColumnWidth(1, 30);
	xls.SetCellMergedColumns(0, 0, 2);
	xls.SetCellMergedColumns(0, 1, 2);
	xls.SetCellMergedColumns(0, 2, 10);
	xls.SetCellMergedColumns(0, 3, 10);
	xls.SetCellText(0, 0, pMF->m_szHealthService, 4098, true);
	xls.SetCellText(0, 1, pMF->m_szHospitalName, 4098, true);
	//TODO: Write Excel Name
	tmpStr = _T("\x42\x1EA2NG T\x1ED4NG H\x1EE2P \x43H\x1EA4M \x102N TH\x45O M\x1EE8\x43");
	xls.SetCellText(0, 2, tmpStr, 4098, true);
	tmpStr.Format(_T("T\x1EEB ng\xE0y %s \x111\x1EBFn ng\xE0y %s"), CDate::Convert(m_szFromDate, yyyymmdd, ddmmyyyy), CDate::Convert(m_szToDate, yyyymmdd, ddmmyyyy));
	xls.SetCellText(0, 3, tmpStr, 4098, true);
	//TODO: Write Column Header
	arrCol.Add(_T("S\x1EEF\x61"));
	arrCol.Add(_T("\x43\x1A1m"));
	arrCol.Add(_T("OT"));
	arrCol.Add(_T("Ti\x1EC3u \x111\x1B0\x1EDDng"));
	arrCol.Add(_T("\x43h\xE1o"));
	xls.SetCellText(0, 4, _T("STT"), 4098, true);
	xls.SetCellText(1, 4, _T("Kho\x61"), 4098, true);
	xls.SetCellMergedColumns(2, 4, 3);
	xls.SetCellText(2, 4, _T("S\x1EEF\x61"), 4098, true);
	xls.SetCellText(2, 5, _T("S\xE1ng"), 4098);
	xls.SetCellText(3, 5, _T("Tr\x1B0\x61"), 4098);
	xls.SetCellText(4, 5, _T("\x43hi\x1EC1u"), 4098);
	xls.SetCellMergedColumns(5, 4, 3);
	xls.SetCellText(5, 4, _T("\x43\x1A1m"), 4098, true);
	xls.SetCellText(5, 5, _T("S\xE1ng", 4098));
	xls.SetCellText(6, 5, _T("Tr\x1B0\x61"), 4098);
	xls.SetCellText(7, 5, _T("\x43hi\x1EC1u"), 4098);
	xls.SetCellMergedColumns(8, 4, 3);
	xls.SetCellText(8, 4, _T("OT"), 4098, true);
	xls.SetCellText(8, 5, _T("S\xE1ng"), 4098);
	xls.SetCellText(9, 5, _T("Tr\x1B0\x61"), 4098);
	xls.SetCellText(10, 5, _T("\x43hi\x1EC1u"), 4098);
	xls.SetCellMergedColumns(11, 4, 3);
	xls.SetCellText(11, 4, _T("Ti\x1EC3u \x111\x1B0\x1EDDng"), 4098, true);
	xls.SetCellText(11, 5, _T("S\xE1ng"), 4098);
	xls.SetCellText(12, 5, _T("Tr\x1B0\x61"), 4098);
	xls.SetCellText(13, 5, _T("\x43hi\x1EC1u"), 4098);
	xls.SetCellMergedColumns(14, 4, 3);
	xls.SetCellText(14, 4, _T("\x43h\xE1o"), 4098, true);
	xls.SetCellText(14, 5, _T("S\xE1ng"), 4098);
	xls.SetCellText(15, 5, _T("Tr\x1B0\x61"), 4098);
	xls.SetCellText(16, 5, _T("\x43hi\x1EC1u"), 4098);
	xls.SetCellText(17, 4, _T("Kh\xE1\x63"), 4098, true);
	xls.SetCellText(18, 4, _T("\x43\x1ED9ng"), 4098, true);
	nRow = 6;
	while (!rs.IsEOF())
	{
		xls.SetCellText(0, nRow, int2str(nIdx++), FMT_TEXT | FMT_RIGHT);
		xls.SetCellText(1, nRow, rs.GetValue(_T("dept")), FMT_TEXT);
		k = 0;
		for (int i = 0; i < 5; i++)
			for (int j = 0; j < 3; j++)
			{
				tmpStr.Format(_T("%d.%d"), i+3, j+1);
				rs.GetValue(tmpStr, nTmp);
				xls.SetCellText(k+2, nRow, double2str(nTmp), FMT_NUMBER1);
				nTotal[k++] += nTmp;
			}
		rs.GetValue(_T("8"), nTmp);
		nTotal[15] += nTmp;
		xls.SetCellText(17, nRow, double2str(nTmp), FMT_NUMBER1);
		rs.GetValue(_T("total"), nTmp);
		nTotal[16] += nTmp;
		xls.SetCellText(18, nRow, double2str(nTmp), FMT_NUMBER1);
		nRow++;
		rs.MoveNext();
	}
	xls.SetCellText(1, nRow, _T("\x43\x1ED9ng"), 4098, true);
	for (int i = 0; i < 17; i++)
		xls.SetCellText(i+2, nRow, double2str(nTotal[i]), FMT_NUMBER1);
	xls.Save(_T("Exports\\Bang thong ke cham an theo muc.xls"));
} 
void CFMFoodSummaryByLevel::OnPrintSelect(){
	CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd();
	UpdateData(true);
	CRecord rs(&pMF->m_db);
	CReport rpt;
	CReportSection* rptDetail = NULL,* rptHeader = NULL, * rptGroup = NULL;
	double nTmp = 0;
	int nIdx = 1, j = 0, k = 0;
	CString szSQL, tmpStr, szReportName, szDate, szPos;
	long double nTotal[17];
	for (int i = 0; i < 17; i++)
	{
		nTotal[i] = 0;
	}
	szReportName = _T("Reports\\HMS\\HF_BANGTONGHOPCHAMANTHEOMUC.RPT");
	if (!rpt.Init(szReportName))
		return;
	szSQL = GetQueryString();
	rs.ExecSQL(szSQL);
	if (rs.IsEOF()){
		AfxMessageBox(_T("No Data"));
		return;
	}
	rptHeader = rpt.GetReportHeader();
	if (rptHeader)
	{
		rptHeader->SetValue(_T("HealthService"), pMF->m_szHealthService);
		rptHeader->SetValue(_T("HospitalName"), pMF->m_szHospitalName);
		tmpStr.Format(rptHeader->GetValue(_T("ReportDate")), CDate::Convert(m_szFromDate, yyyymmdd, ddmmyyyy), 
		CDate::Convert(m_szToDate), yyyymmdd, ddmmyyyy);
		rpt.GetReportHeader()->SetValue(_T("ReportDate"), tmpStr);
	}
	while (!rs.IsEOF())
	{
		//Group Seperation
		rptDetail = rpt.AddDetail();
		if (rptDetail)
		{
			rptDetail->SetValue(_T("1"), int2str(nIdx++));
			rptDetail->SetValue(_T("2"), rs.GetValue(_T("dept")));
			k = 0;
			for (int i = 0; i < 5; i++)
				for (int j = 0; j < 3; j++)
				{
					tmpStr.Format(_T("%d.%d"), i+3, j+1);
					rs.GetValue(tmpStr, nTmp);
					rptDetail->SetValue(tmpStr, double2str(nTmp));
					nTotal[k++] += nTmp;
				}
			rs.GetValue(_T("8"), nTmp);
			nTotal[15]+= nTmp;
			rptDetail->SetValue(_T("8"), double2str(nTmp));
			rs.GetValue(_T("total"), nTmp);
			nTotal[16]+= nTmp;
			rptDetail->SetValue(_T("9"), double2str(nTmp));
		}
		rs.MoveNext();
	}
	tmpStr = pMF->GetSysDate();
	/*szDate.Format(rpt.GetReportFooter()->GetValue(_T("PrintDate")), tmpStr.Right(2), tmpStr.Mid(5,2), tmpStr.Left(4));
	rpt.GetReportFooter()->SetValue(_T("PrintDate"), szDate);*/
	rpt.PrintPreview();
} 
void CEMOperationFosteringListC12::OnExportSelect(){
	CMainFrame_E10 *pMF = (CMainFrame_E10*) AfxGetMainWnd();
	CRecord rs(&pMF->m_db);
	CString szSQL, tmpStr, szTemp, szWhere, szObjects;
	UpdateData(TRUE);
	BeginWaitCursor();
	szWhere.Empty();
	int nRow =0, nCol = 0, nCount = 0, nOldDoc = 0, nNewDoc = 0;
	int nIdx = 1;
	double nTmp = 0, nAmt = 0;
	szSQL = GetQueryString();
	rs.ExecSQL(szSQL);
	if (rs.IsEOF())
		return;
	CExcel xls;
	xls.CreateSheet(1);
	xls.SetWorksheet(0);

	xls.SetColumnWidth(0, 8);
	xls.SetColumnWidth(1, 16);
	xls.SetColumnWidth(2, 14);
	xls.SetColumnWidth(3, 14);
	xls.SetColumnWidth(4, 36);
	xls.SetColumnWidth(5, 8);
	xls.SetColumnWidth(6, 8);
	xls.SetColumnWidth(7, 8);
	xls.SetColumnWidth(8, 8);
	xls.SetColumnWidth(9, 22);
	xls.SetColumnWidth(10, 8);
	xls.SetColumnWidth(11, 8);
	xls.SetColumnWidth(12, 15);

	xls.SetCellText(nCol, nRow, pMF->m_szHealthService, FMT_TEXT | FMT_CENTER, true, 11);
	xls.SetCellText(nCol, nRow + 1, pMF->m_szHospitalName, FMT_TEXT | FMT_CENTER, true, 11);
	xls.SetCellText(nCol+1, nRow + 2, _T("C1.2"), FMT_TEXT | FMT_CENTER, true, 11);
	for (int i = 0; i < m_wndObject.GetItemCount(); i++)
	{
		if (m_wndObject.GetCheck(i))
		{
			m_wndObject.SetCurSel(i);
			if (!szObjects.IsEmpty())
				szObjects += _T(", ");
			szObjects += m_wndObject.GetCurrent(1);
		}
	}
	if (!szObjects.IsEmpty())
		tmpStr.Format(_T("\x42\x1EC7nh nh\xE2n %s"), szObjects);
	else
		tmpStr.Format(_T("\x42\x1EC7nh nh\xE2n"));
	xls.SetCellText(nCol, nRow + 4, tmpStr, FMT_TEXT | FMT_CENTER, true, 10);
	tmpStr.Format(_T("T\x1EEB ng\xE0y %s \x111\x1EBFn ng\xE0y %s"), CDate::Convert(m_szFromDate, yyyymmdd, ddmmyyyy), CDate::Convert(m_szToDate, yyyymmdd, ddmmyyyy));
	xls.SetCellText(nCol, nRow + 5, tmpStr, FMT_TEXT | FMT_CENTER, true, 10);

	xls.SetCellText(0, 2, _T("KHO\x41:"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 11);
	xls.SetCellText(0, 3, _T("\x44\x41NH S\xC1\x43H \x110\x1EC0 NGH\x1ECA \x42\x1ED2I \x44\x1AF\x1EE0NG PH\x1EAAU THU\x1EACT, TH\x1EE6 THU\x1EACT"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 12);
	xls.SetCellText(0, 6, _T("S\x1ED1 TT"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 10);
	xls.SetCellText(1, 6, _T("H\x1ECD v\xE0 t\xEAn \x62\x1EC7nh nh\xE2n"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 10);
	xls.SetCellText(2, 6, _T("S\x1ED1 h\x1ED3 s\x1A1"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 10);
	xls.SetCellText(3, 6, _T("SH, s\x1ED1 th\x1EBB, \x63\x1EA5p \x62\x1EAD\x63"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 10);
	xls.SetCellText(4, 6, _T("T\xEAn ph\x1EABu thu\x1EADt, th\x1EE7 thu\x1EADt"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 10);
	xls.SetCellText(5, 6, _T("Ph\xE2n lo\x1EA1i ph\x1EABu thu\x1EADt, th\x1EE7 thu\x1EADt"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 10);
	xls.SetCellText(5, 8, _T("\x110\x1EB7\x63 \x62i\x1EC7t"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 10);
	xls.SetCellText(6, 8, _T("Lo\x1EA1i \x31"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 10);
	xls.SetCellText(7, 8, _T("Lo\x1EA1i \x32"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 10);
	xls.SetCellText(8, 8, _T("Lo\x1EA1i \x33"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 10);
	xls.SetCellText(9, 0, _T("\x43\x1ED8NG H\xD2\x41 \x58\xC3 H\x1ED8I \x43H\x1EE6 NGH\x128\x41 VI\x1EC6T N\x41M"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 10);
	xls.SetCellText(9, 1, _T("\x110\x1ED9\x63 l\x1EADp - T\x1EF1 \x64o - H\x1EA1nh ph\xFA\x63"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 10);
	xls.SetCellText(9, 6, _T("K\xEDp th\x1EF1\x63 hi\x1EC7n"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 10);
	xls.SetCellText(9, 8, _T("\x43h\xEDnh"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 10);
	xls.SetCellText(10, 8, _T("Ph\x1EE5"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 10);
	xls.SetCellText(11, 8, _T("Gi\xFAp vi\x1EC7\x63"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 10);
	xls.SetCellText(12, 6, _T("S\x1ED1 ti\x1EC1n"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 10);

	xls.SetMerge(0, 0, 0, 2);
	xls.SetMerge(1, 1, 0, 2);
	xls.SetMerge(3, 3, 0, 12);
	xls.SetMerge(4, 4, 0, 12);
	xls.SetMerge(5, 5, 0, 12);
	xls.SetMerge(6, 9, 0, 0);
	xls.SetMerge(2, 2, 1, 2);
	xls.SetMerge(6, 9, 1, 1);
	xls.SetMerge(174, 174, 1, 11);
	xls.SetMerge(6, 9, 2, 2);
	xls.SetMerge(6, 9, 3, 3);
	xls.SetMerge(6, 9, 4, 4);
	xls.SetMerge(6, 7, 5, 8);
	xls.SetMerge(8, 9, 5, 5);
	xls.SetMerge(8, 9, 6, 6);
	xls.SetMerge(8, 9, 7, 7);
	xls.SetMerge(8, 9, 8, 8);
	xls.SetMerge(0, 0, 9, 12);
	xls.SetMerge(1, 1, 9, 12);
	xls.SetMerge(6, 7, 9, 11);
	xls.SetMerge(8, 9, 9, 9);
	xls.SetMerge(8, 9, 10, 10);
	xls.SetMerge(8, 9, 11, 11);
	xls.SetMerge(6, 9, 12, 12);

	nRow = 10;
	nCol = 0;
	while (!rs.IsEOF())
	{
void CEMMonthlyDrugIncome::OnExportSelect(){
	_debug(_T("%s"), CString(typeid(this).name()));
	CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd();
	UpdateData(true);
	CString szSQL, tmpStr;
	int nTmp = 0;
	double nAmt = 0;
	CRecord rs(&pMF->m_db);
	BeginWaitCursor();
	szSQL = GetQueryString();
	int nCount = rs.ExecSQL(szSQL);

	if (nCount <= 0)
	{
		ShowMessage(150, MB_ICONSTOP);
		return;
	}
	CExcel xls;	
	xls.CreateSheet(1);
	xls.SetWorksheet(0);

	xls.SetColumnWidth(0, 30);
	//xls.SetColumnWidth(1, 10);
	//xls.SetColumnWidth(2, 25);
	//xls.SetColumnWidth(3, 12);
	//xls.SetColumnWidth(4, 23);
	//xls.SetColumnWidth(5, 23);
	//xls.SetColumnWidth(6, 12);
	//xls.SetColumnWidth(7, 12);
	//xls.SetColumnWidth(8, 66);

	int nCol = 0;
	int nRow = 0;	
	xls.SetColumnWidth(3, 15);
	xls.SetCellMergedColumns(nCol, nRow + 1, 2);
	xls.SetCellMergedColumns(nCol, nRow + 2, 2);
	xls.SetCellText(nCol, nRow + 1, pMF->m_CompanyInfo.sc_pname, FMT_TEXT | FMT_CENTER, true, 10);
	xls.SetCellText(nCol, nRow + 2, pMF->m_CompanyInfo.sc_name, FMT_TEXT | FMT_CENTER, true, 10);

	xls.SetCellMergedColumns(nCol, nRow + 3, 6);
	xls.SetCellText(nCol, nRow + 3, _T("TH\x1ED0NG K\xCA TI\x1EC0N \x42\xC1N THU\x1ED0\x43 H\xC0NG TH\xC1NG"), FMT_TEXT | FMT_CENTER, true, 14);
	xls.SetCellMergedColumns(nCol, nRow + 4, 6);
	tmpStr.Format(_T("T\x1EEB ng\xE0y %s \x110\x1EBFn ng\xE0y %s"), CDateTime::Convert(m_szFromDate, yyyymmdd|hhmmss, ddmmyyyy|hhmmss), CDateTime::Convert(m_szToDate, yyyymmdd|hhmmss, ddmmyyyy|hhmmss));
	xls.SetCellText(nCol, nRow + 4, tmpStr, FMT_TEXT | FMT_CENTER, true, 11);

	xls.SetCellText(nCol, nRow + 5, _T("Ph\xF2ng kh\xE1m"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 11);
	xls.SetCellText(nCol + 1, nRow + 5, _T("T\x1ED5ng s\x1ED1 \x62\x1EC7nh nh\xE2n"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 11);

	xls.SetCellText(nCol + 2, nRow + 5, _T("S\x1ED1 k\xEA \x111\x1A1n"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 11);
	xls.SetCellText(nCol + 3, nRow + 5, _T("S\x1ED1 ti\x1EC1n mu\x61 thu\x1ED1\x63"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 11);
	xls.SetCellText(nCol + 4, nRow + 5, _T("S\x1ED1 ti\x1EC1n T\x42/\x111\x1A1n"), FMT_TEXT | FMT_CENTER | FMT_WRAPING, true, 11);

	nRow = 6;
	while(!rs.IsEOF())
	{
		rs.GetValue(_T("roomname"), tmpStr);
		xls.SetCellText(nCol, nRow, tmpStr);
		rs.GetValue(_T("examed"), nTmp);
		xls.SetCellText(nCol+1, nRow, int2str(nTmp), FMT_NUMBER1);
		rs.GetValue(_T("drugpurchase"), nTmp);
		xls.SetCellText(nCol+2, nRow, int2str(nTmp), FMT_NUMBER1);
		rs.GetValue(_T("amt"), nAmt);
		xls.SetCellText(nCol+3, nRow, double2str(nAmt), FMT_NUMBER1);
		rs.GetValue(_T("rate"), nAmt);
		tmpStr.Format(_T("%.2f"), nAmt);
		xls.SetCellText(nCol+4, nRow, tmpStr, FMT_NUMBER1);
		nRow++;
		rs.MoveNext();		
	}
	EndWaitCursor();
	xls.Save(_T("Exports\\THONG KE TIEN DON THUOC HANG THANG.xls"));
} 
void CPMSExportSheetList::OnExportSelect(){
	_debug(_T("%s"), CString(typeid(this).name()));
	CMainFrame_E10 *pMF = (CMainFrame_E10*) AfxGetMainWnd();
	UpdateData(true);
	CExcel xls;
	CRecord rs(&pMF->m_db);
	CString szSQL, tmpStr, szPrice;
	int nCol = 0, nRow = 0, nIdx = 0;
	double nAmount = 0, nTotal = 0;
	szSQL = GetQueryString();
	int nCount = rs.ExecSQL(szSQL);
	if (nCount <= 0)
	{
		ShowMessage(150, MB_ICONSTOP);
		return;
	}
	xls.CreateSheet(1);
	xls.SetWorksheet(0);
	xls.SetColumnWidth(0, 4);
	xls.SetColumnWidth(1, 10);
	xls.SetColumnWidth(2, 12);
	xls.SetColumnWidth(3, 36);
	xls.SetColumnWidth(5, 25);
	xls.SetColumnWidth(6, 10);
	//Header
	xls.SetCellMergedColumns(nCol, nRow, 3);
	xls.SetCellMergedColumns(nCol, nRow + 1, 3);
	xls.SetCellMergedColumns(nCol, nRow + 2, 7);
	xls.SetCellMergedColumns(nCol, nRow + 3, 7);
	xls.SetCellMergedColumns(nCol, nRow + 4, 4);
	xls.SetCellText(nCol, nRow, _T("HEALTHSERVICE"), FMT_TEXT | FMT_CENTER, true, 10);
	xls.SetCellText(nCol, nRow + 1, _T("HOSPITALNAME"), FMT_TEXT | FMT_CENTER, true, 10);
	xls.SetCellText(nCol, nRow + 2, _T("\x42\x1EA2NG K\xCA PHI\x1EBEU \x58U\x1EA4T"), FMT_TEXT | FMT_CENTER, true, 11);	
	tmpStr.Format(_T("T\x1EEB ng\xE0y %s \x111\x1EBFn ng\xE0y %s"), CDateTime::Convert(m_szFromDate, yyyymmdd|hhmmss, ddmmyyyy|hhmmss), CDateTime::Convert(m_szToDate, yyyymmdd|hhmmss, ddmmyyyy|hhmmss));
	xls.SetCellText(nCol, nRow + 3, tmpStr, FMT_TEXT | FMT_CENTER, false, 11);	
	tmpStr.Format(_T("Kho : %s"), m_wndStock.GetCurrent(1));
	xls.SetCellText(nCol, nRow + 4, tmpStr, FMT_TEXT, false, 11);

	//Column Heading
	CStringArray arrCol;
	arrCol.Add(_T("STT"));
	arrCol.Add(_T("S\x1ED1 phi\x1EBFu"));
	arrCol.Add(_T("Ng\xE0y \x78u\x1EA5t"));
	arrCol.Add(_T("\x110\x1A1n v\x1ECB nh\x1EADn h\xE0ng"));
	arrCol.Add(_T("M\xE3 s\x1ED1"));
	arrCol.Add(_T("H\x1ECD v\xE0 t\xEAn"));
	arrCol.Add(_T("S\x1ED1 ti\x1EC1n"));
	nRow = 5;
	for (int i = 0; i < arrCol.GetCount(); i++)
	{
		xls.SetCellText(nCol+i, nRow, arrCol.GetAt(i), FMT_TEXT | FMT_CENTER, true, 10); 
	}
	nRow = 6;
	szPrice = _T("vatamount");
	if (m_nByServPrice)
		szPrice = _T("servamount");
	while (!rs.IsEOF()){
		nIdx++;
		tmpStr.Format(_T("%d"), nIdx);
		xls.SetCellText(nCol, nRow, tmpStr, FMT_INTEGER);
		rs.GetValue(_T("orderid"), tmpStr);
		xls.SetCellText(nCol + 1, nRow, tmpStr, FMT_TEXT | FMT_CENTER);
		rs.GetValue(_T("expdate"), tmpStr);
		xls.SetCellText(nCol + 2, nRow, CDate::Convert(tmpStr, yyyymmdd , ddmmyyyy), FMT_TEXT);
		rs.GetValue(_T("patname"), tmpStr);
		xls.SetCellText(nCol + 3, nRow, tmpStr, FMT_TEXT);
		rs.GetValue(_T("id"), tmpStr);
		xls.SetCellText(nCol + 4, nRow, tmpStr, FMT_INTEGER | FMT_CENTER);
		rs.GetValue(_T("doctype"), tmpStr);
		xls.SetCellText(nCol + 5, nRow, tmpStr, FMT_TEXT);
		rs.GetValue(szPrice, nAmount);
		nTotal += nAmount;
		xls.SetCellText(nCol + 6, nRow, double2str(nAmount), FMT_NUMBER1);
		nRow++;
		rs.MoveNext();
	}
	xls.SetCellText(nCol + 5, nRow, _T("T\x1ED5ng \x63\x1ED9ng"), FMT_TEXT, true, 10);
	xls.SetCellText(nCol + 6, nRow, double2str(nTotal), FMT_NUMBER1, true, 10);
	xls.Save(_T("Exports\\Bang Ke Phieu Xuat.xls"));
	
} 
/*void CFMPostedReceiptVoucherList::OnClerkAddNew(){
	CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd();
	
} */
void CFMPostedReceiptVoucherList::OnPrintPreviewSelect(){
	CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd();
	UpdateData(true);
	CReport rpt;
	CRecord rs(&pMF->m_db);
	CString szSQL, tmpStr, szPos, szSysDate, szTemp;
	CStringArray arrCol;
	CReportSection *rptDetail = NULL, *rptFooter = NULL;
	long double nTtl[6];
	double nCost = 0, nHitechEAmount = 0, nHitechIAmount = 0;
	int nIdx = 1;
	if (!rpt.Init(_T("Reports\\HMS\\HF_BANGKECHUNGTUTHU.RPT")))
		return;
	szSQL = GetQueryString();
	rs.ExecSQL(szSQL);
	if (rs.IsEOF())
	{
		AfxMessageBox(_T("No Data"));
		return;
	}
	for (int i = 0 ; i < 6; i++){
		nTtl[i] = 0;
	}
	arrCol.Add(_T("eamount"));
	arrCol.Add(_T("deposit"));
	arrCol.Add(_T("iamount"));
	arrCol.Add(_T("inpatient_deposit_paid"));
	arrCol.Add(_T("inpatient_payment"));
	arrCol.Add(_T("totalamount"));
	rpt.GetReportHeader()->SetValue(_T("HOSPITALNAME"), pMF->m_CompanyInfo.sc_name);
	tmpStr.Format(rpt.GetReportHeader()->GetValue(_T("ReportDate")), CDateTime::Convert(m_szFromDate, yyyymmdd|hhmmss, ddmmyyyy|hhmmss), 
		CDateTime::Convert(m_szToDate, yyyymmdd|hhmmss, ddmmyyyy|hhmmss));
	rpt.GetReportHeader()->SetValue(_T("ReportDate"), tmpStr);
	if (m_bService)
		rpt.GetReportHeader()->SetValue(_T("Object"), _T("\x44\x1ECB\x63h v\x1EE5"));
	else
		rpt.GetReportHeader()->SetValue(_T("Object"), _T("\x42\x1EA3o hi\x1EC3m"));
	while (!rs.IsEOF())
	{
		rptDetail = rpt.AddDetail();
		rptDetail->SetValue(_T("1"), int2str(nIdx++));
		rptDetail->SetValue(_T("2"), rs.GetValue(_T("staff")));
		rptDetail->SetValue(_T("3"), rs.GetValue(_T("invoiceno")));
		for (int i = 0; i < arrCol.GetCount(); i++)
		{
			rs.GetValue(arrCol.GetAt(i), nCost);
			nTtl[i] += nCost;
			rptDetail->SetValue(int2str(i+4), double2str(nCost));
		}
		rs.MoveNext();
	}
	rptFooter = rpt.GetReportFooter();
	for (int i = 0; i < 6; i++)
	{
		szPos.Format(_T("s%d"), i+4);
		tmpStr.Format(_T("%f"), nTtl[i]);
		rptFooter->SetValue(szPos, tmpStr);
	}
	m_nEAmount = nTtl[0];
	m_nIAmount = nTtl[2];
	szSQL = GetQueryString1();
	rs.ExecSQL(szSQL);
	if (!rs.IsEOF())
	{
		rs.GetValue(_T("eamount"), nHitechEAmount);
		rs.GetValue(_T("iamount"), nHitechIAmount);
	}
	tmpStr.Empty();
	if (nHitechEAmount > 0)
	{
		FormatCurrency(nHitechEAmount, szTemp);
		tmpStr.AppendFormat(_T("Ngo\x1EA1i tr\xFA: %s"), szTemp);
	}
	if (nHitechIAmount > 0)
	{
		FormatCurrency(nHitechIAmount, szTemp);
		tmpStr.AppendFormat(_T(" N\x1ED9i tr\xFA: %s"), szTemp);
	}
	if (!tmpStr.IsEmpty())
		rptFooter->SetValue(_T("cnc"), tmpStr);
	tmpStr.Empty();
	if (m_nEAmount > 0)
	{
		FormatCurrency(m_nEAmount - nHitechEAmount, szTemp);
		tmpStr.AppendFormat(_T("Ngo\x1EA1i tr\xFA: %s"), szTemp);
	}
	if (m_nIAmount > 0)
	{
		FormatCurrency(m_nIAmount - nHitechIAmount, szTemp);
		tmpStr.AppendFormat(_T(" N\x1ED9i tr\xFA: %s"), szTemp);
	}
	if (!tmpStr.IsEmpty())
		rptFooter->SetValue(_T("conlai"), tmpStr);
	szSysDate = pMF->GetSysDate();
	tmpStr.Format(rptFooter->GetValue(_T("PrintDate")), szSysDate.Mid(8, 2), szSysDate.Mid(5, 2), szSysDate.Left(4));
	rptFooter->SetValue(_T("PrintDate"), tmpStr);
	rpt.PrintPreview();
}