Click here to Skip to main content
15,891,597 members
Home / Discussions / C#
   

C#

 
AnswerRe: Little conversion problem from visual basic to c# Pin
0x3c023-Jul-09 7:48
0x3c023-Jul-09 7:48 
GeneralRe: Little conversion problem from visual basic to c# Pin
PIEBALDconsult23-Jul-09 7:58
mvePIEBALDconsult23-Jul-09 7:58 
GeneralRe: Little conversion problem from visual basic to c# Pin
0x3c023-Jul-09 8:02
0x3c023-Jul-09 8:02 
GeneralRe: Little conversion problem from visual basic to c# Pin
Member 474292223-Jul-09 8:09
Member 474292223-Jul-09 8:09 
GeneralRe: Little conversion problem from visual basic to c# Pin
OriginalGriff23-Jul-09 8:17
mveOriginalGriff23-Jul-09 8:17 
GeneralRe: Little conversion problem from visual basic to c# Pin
Member 474292223-Jul-09 8:25
Member 474292223-Jul-09 8:25 
GeneralRe: Little conversion problem from visual basic to c# Pin
PIEBALDconsult23-Jul-09 8:37
mvePIEBALDconsult23-Jul-09 8:37 
Questionif someone could help me identify the problem please. [modified] Pin
DinoRondelly23-Jul-09 7:20
DinoRondelly23-Jul-09 7:20 
Here is my Code
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Data.Odbc;
using My;
using System.Data;

namespace FirstCitizensBank_DropOffReport
{
    class Program : MyGeneral
    {
        public static string dataBasePath;
        public static string dbname;
        public static string strconn;
        static void Main(string[] args)
        {
            StartUp("", "", true);
            dataBasePath = ConfigPath + "Empathic\\FirstCit\\";
            dbname = "Bank";
            strconn = "";


            try
            {
                string repname = dataBasePath + "Reports\\Dropoff" + myDate.ToString("yyyyMMdd") + ".xls";

                DateTime enddate = myDate.AddDays(-myDate.Day);
                DateTime startdate = enddate.AddDays(1).AddMonths(-1);
                MyWriteExcel exl = new MyWriteExcel(repname, dataBasePath + "Reports\\Templates\\DropoffTemp.xls");

                //dbname = dbname + myDate.ToString("yyMM");
                //WriteMonth(ref exl, startdate, enddate, "B");

                enddate = startdate.AddDays(-1);
                //startdate = startdate.AddMonths(-1);
                dbname = "Bank";
                dbname = dbname + myDate.AddMonths(-1).ToString("yyMM");
                WriteMonth(ref exl, startdate, enddate, "C");

                enddate = startdate.AddDays(-1);
                startdate = startdate.AddMonths(-2);
                dbname = "Bank";
                dbname = dbname + myDate.AddMonths(-2).ToString("yyMM");
                WriteMonth(ref exl, startdate, enddate, "D");

                exl.Save();
                exl.Close();

                MyEmail email = new MyEmail("", "First Citizens Bank Dropoff Report", "Please see attached report");
                email.AddAttachment(repname);
                email.AddBCC(CommonEmail);
                email.sendEmail();

                endProgram();
            }
            catch (Exception e)
            {
                WriteToLog("@Failed: " + e.ToString());

                HelpPage(e.ToString(), "Failed");
            }

        }

        public static void WriteMonth(ref MyWriteExcel exl, DateTime startdate, DateTime enddate, string column)
        {
            string sql = "select count(*) as total, sum(iif(mid(CALLSTATUS, 1, 2) >= '06', 1, 0)) as entered, sum(iif(DONE is not null, 1, 0)) as completed"
                    + " from " + dbname + " where startdate >= " + startdate.ToString("yyyyMMdd") + " and startdate <= " + enddate.AddMonths(+1).ToString("yyyyMMdd")
                    + " and stopdate is not null";
            OdbcConnection conn = new OdbcConnection(strconn);
            conn.Open();
            OdbcCommand cmd = new OdbcCommand(sql, conn);
            OdbcDataReader dr = cmd.ExecuteReader();

            dr.Read();

            int total;
            int entered;
            int completed;
            int abandoned;

            if (!(int.TryParse(dr["total"].ToString(), out total) && int.TryParse(dr["entered"].ToString(), out entered) && int.TryParse(dr["completed"].ToString(), out completed)))
            {
                Exception myex = new Exception("Failed to convert one of the counts to an integer");
                throw myex;
            }
            dr.Close();
            dr.Dispose();

            abandoned = entered - completed;


            sql = "select avg(duration) as avgdur from " + dbname + myDate.AddMonths(-1).ToString("yyMM") + " where startdate >= " + startdate.ToString("yyyyMMdd") + " and startdate <= " + enddate.AddMonths(+1).ToString("yyyyMMdd")
                + " and stopdate is not null and DONE is not null";
            cmd.CommandText = sql;
            dr = cmd.ExecuteReader();
            dr.Read();
            double avgcompleted;
            if (!double.TryParse(dr["avgdur"].ToString(), out avgcompleted))
            {
                Exception myex = new Exception("Failed to convert one of the average duration to a double");
                throw myex;
            }
            dr.Close();
            dr.Dispose();

            sql = "select avg(duration) as avgdur from " + dbname + " where startdate >= " + startdate.ToString("yyyyMMdd") + " and startdate <= " + enddate.AddMonths(+1).ToString("yyyyMMdd")
                + " and stopdate is not null and DONE is null";
            cmd.CommandText = sql;
            dr = cmd.ExecuteReader();
            dr.Read();
            double avgdrop;
            if (!double.TryParse(dr["avgdur"].ToString(), out avgdrop))
            {
                Exception myex = new Exception("Failed to convert one of the average duration to a double");
                throw myex;
            }
            dr.Close();
            dr.Dispose();

            sql = "select callstatus, count(*) as num from " + dbname + " where startdate >= " + startdate.ToString("yyyyMMdd") + " and startdate <= " + enddate.AddMonths(+1).ToString("yyyyMMdd")
                + " and stopdate is not null group by callstatus";
            cmd.CommandText = sql;
            dr = cmd.ExecuteReader();

            int linenum = 3;
            exl.WriteCell(column + linenum.ToString() + ":" + column + linenum.ToString(), total);

            linenum++;
            exl.WriteCell(column + linenum.ToString() + ":" + column + linenum.ToString(), entered);

            linenum++;
            exl.WriteCell(column + linenum.ToString() + ":" + column + linenum.ToString(), completed);

            linenum++;
            exl.WriteCell(column + linenum.ToString() + ":" + column + linenum.ToString(), abandoned);

            int minutes = ((int)Math.Round(avgcompleted, 0) / 60);
            int seconds = ((int)Math.Round(avgcompleted, 0) % 60);
            string line = minutes.ToString() + ":" + seconds.ToString();
            linenum++;
            exl.WriteCell(column + linenum.ToString() + ":" + column + linenum.ToString(), line);

            minutes = ((int)Math.Round(avgdrop, 0) / 60);
            seconds = ((int)Math.Round(avgdrop, 0) % 60);
            line = minutes.ToString() + ":" + seconds.ToString();
            linenum++;
            exl.WriteCell(column + linenum.ToString() + ":" + column + linenum.ToString(), line);

            object[] zerofill = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            exl.WriteRange(column + "11:" + column + "38", zerofill);
            while (dr.Read())
            {
                if (dr["callstatus"].ToString() == "00_SurveyInt")
                    linenum = 11;
                if (dr["callstatus"].ToString() == "01_SurveyCode")
                    linenum = 12;
                if (dr["callstatus"].ToString() == "02_Visit_Date")
                    linenum = 13;
                if (dr["callstatus"].ToString() == "03_Visit_Time")
                    linenum = 14;
                if (dr["callstatus"].ToString() == "04_Purpose_Visit")
                    linenum = 15;
                if (dr["callstatus"].ToString() == "06.1_First_Impres")
                    linenum = 16;
                if (dr["callstatus"].ToString() == "06.2_OV_SatB")
                    linenum = 17;
                if (dr["callstatus"].ToString() == "06.3_OV_RecB")
                    linenum = 18;
                if (dr["callstatus"].ToString() == "06.4_OV_Value")
                    linenum = 19;
                if (dr["callstatus"].ToString() == "06.5_Trans_Time")
                    linenum = 20;
                if (dr["callstatus"].ToString() == "06.5Service")
                    linenum = 21;
                if (dr["callstatus"].ToString() == "06.6_Employee_Pro")
                    linenum = 22;
                if (dr["callstatus"].ToString() == "06.7_Employee_Acc")
                    linenum = 23;
                if (dr["callstatus"].ToString() == "06.8_Employee_Thank")
                    linenum = 24;
                if (dr["callstatus"].ToString() == "06.9_Employee_Sat")
                    linenum = 25;
                if (dr["callstatus"].ToString() == "06.9.1_Employee_WOW")
                    linenum = 26;
                if (dr["callstatus"].ToString() == "06.9.2_Demographics")
                    linenum = 27;
                if (dr["callstatus"].ToString() == "06.9.3_Gender")
                    linenum = 28;
                if (dr["callstatus"].ToString() == "06.9.4_Age")
                    linenum = 29;
                if (dr["callstatus"].ToString() == "07_Draw")
                    linenum = 30;
                if (dr["callstatus"].ToString() == "13_Phone")
                    linenum = 31;
                if (dr["callstatus"].ToString() == "12_Rules")
                    linenum = 32;
                if (dr["callstatus"].ToString() == "11_ContestRules")
                    linenum = 33;
                if (dr["callstatus"].ToString() == "08_Exit_System")
                    linenum = 34;
                if (dr["callstatus"].ToString() == "10_Kicked")
                    linenum = 35;
                if (dr["callstatus"].ToString() == "Repeat")
                    linenum = 36;
                if (dr["callstatus"].ToString() == "Start")
                    linenum = 37;
                if (dr["callstatus"].ToString() == "06_Instruc_1")
                    linenum = 38;

                    exl.WriteCell(column + linenum.ToString() + ":" + column + linenum.ToString(), dr["num"]);
                }
            }
        }
    }



Here are my expected results
From the first DB
00_SurveyInt 172
01_SurveyCode 641
02_Visit_Date 146
03_Visit_Time 18
04_Purpose_Visit 7
06.1_First_Impres 6
06.2_OV_SatB 64
06.3_OV_RecB 10
06.4_OV_Value 5
06.5Service 2
06.5_Trans_Time 5
06.6_Employee_Pro 14
06.7_Employee_Acc 10
06.8_Employee_Thank 2
06.9.1_Employee_WOW 5
06.9.3_Gender 4
06.9.4_Age 4
06.9_Employee_Sat 3
06_Instruc_1 4
07_Draw 4
08_Exit_System 1360
10_Kick 9
11_ContestRules 3
12_Rules 14
13_Phone 31
Repeat 1
Start 21

and these are the results the process is returning
Survey Intro 172
Survey Entry Code 641
Visit_Date 146
Visit_Time 18
Purpose_Visit 7
First_Impres 6
OV_SatBranch 64
OV_RecBranch 10
OV_Value 5
Trans_Time 5
Service 2
Employee_Pro 14
Employee_Acc 10
Employee_Thank 2
Employee_Sat 3
Employee_WOW 5
Demographics 0
Gender 4
Age 4
Draw 4
Phone 31
Rules 14
Contest Rules 3
Exit System 9
Kicked Out 0
Repeat 1
Start 21
Instructions 4


I cant figure out why these arent matching up if someone could help me identify the problem please.

modified on Thursday, July 23, 2009 1:43 PM

AnswerRe: if someone could help me identify the problem please. Pin
Nagy Vilmos23-Jul-09 7:27
professionalNagy Vilmos23-Jul-09 7:27 
GeneralRe: if someone could help me identify the problem please. Pin
PIEBALDconsult23-Jul-09 7:30
mvePIEBALDconsult23-Jul-09 7:30 
GeneralRe: if someone could help me identify the problem please. Pin
Nagy Vilmos23-Jul-09 7:46
professionalNagy Vilmos23-Jul-09 7:46 
GeneralRe: if someone could help me identify the problem please. Pin
PIEBALDconsult23-Jul-09 7:48
mvePIEBALDconsult23-Jul-09 7:48 
GeneralRe: if someone could help me identify the problem please. Pin
LetMeFinclOut23-Jul-09 12:15
LetMeFinclOut23-Jul-09 12:15 
GeneralRe: if someone could help me identify the problem please. [modified] Pin
Luc Pattyn23-Jul-09 7:33
sitebuilderLuc Pattyn23-Jul-09 7:33 
GeneralRe: if someone could help me identify the problem please. Pin
Nagy Vilmos23-Jul-09 7:46
professionalNagy Vilmos23-Jul-09 7:46 
GeneralRe: if someone could help me identify the problem please. Pin
Curtis Schlak.23-Jul-09 18:02
Curtis Schlak.23-Jul-09 18:02 
GeneralRe: if someone could help me identify the problem please. Pin
Adam R Harris23-Jul-09 7:50
Adam R Harris23-Jul-09 7:50 
GeneralRe: if someone could help me identify the problem please. Pin
Luc Pattyn3-Sep-09 5:17
sitebuilderLuc Pattyn3-Sep-09 5:17 
AnswerRe: if someone could help me identify the problem please. Pin
PIEBALDconsult23-Jul-09 7:49
mvePIEBALDconsult23-Jul-09 7:49 
AnswerRe: if someone could help me identify the problem please. Pin
DinoRondelly23-Jul-09 8:32
DinoRondelly23-Jul-09 8:32 
GeneralRe: if someone could help me identify the problem please. Pin
PIEBALDconsult23-Jul-09 12:45
mvePIEBALDconsult23-Jul-09 12:45 
QuestionHow to inject code to assembly (inject new class)? Pin
hdv21223-Jul-09 7:14
hdv21223-Jul-09 7:14 
QuestionPass data between two child forms Pin
Saamir23-Jul-09 6:56
Saamir23-Jul-09 6:56 
AnswerRe: Pass data between two child forms Pin
musefan23-Jul-09 7:00
musefan23-Jul-09 7:00 
GeneralRe: Pass data between two child forms Pin
Saamir23-Jul-09 7:14
Saamir23-Jul-09 7:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.