Exemplo n.º 1
0
        private static void Main(string[] args)
        {
            // MessageBox.Show(args[0]);
            if (args.Length == 0)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new FormReportExporter());
            }
            else if (args[0].ToLower().Equals("day"))
            {
                //MessageBox.Show("This was Day");
                //This takes the current day and send it as an argunment to the SQL stored procedure
                ExporterFactory exp_Factory = new ExporterFactory(false);
                exp_Factory.setDate(DateTime.Now.AddDays(-1).Date, DateTime.Now.AddDays(-1).Date);
                DataTable dt = exp_Factory.GetData();
                exp_Factory.periodeName = "Day";
                string fileName = exp_Factory.ExportToPDF(dt);
                exp_Factory.SendEmail(fileName);
            }
            else if (args[0].ToLower().Equals("week"))
            {
                //This takes the current day and send it as an argunment to the SQL stored procedure
                ExporterFactory exp_Factory = new ExporterFactory(false);
                exp_Factory.setDate(DateTime.Now.AddDays(-8).Date, DateTime.Now.AddDays(-1).Date);

                DataTable dt = exp_Factory.GetData();
                exp_Factory.periodeName = "Week";
                string fileName = exp_Factory.ExportToPDF(dt);
                exp_Factory.SendEmail(fileName);
            }
            else if ((args[0].ToLower().Equals("month")))
            {
                ExporterFactory exp_Factory = new ExporterFactory(false);
                exp_Factory.setDate(DateTime.Now.AddMonths(-1).Date, DateTime.Now.AddDays(-1).Date);

                DataTable dt = exp_Factory.GetData();
                exp_Factory.periodeName = "Month";
                string fileName = exp_Factory.ExportToPDF(dt);
                exp_Factory.SendEmail(fileName);
            }
        }
        private List <SqlParameter> GetParameters()
        {
            List <SqlParameter> paramList = new List <SqlParameter>();
            DateTime            startDate = new DateTime();
            DateTime            endDate   = new DateTime();

            foreach (object paramets in groupBoxParameters.Controls)
            {
                if (paramets is System.Windows.Forms.TextBox)
                {
                    System.Windows.Forms.TextBox tmpTextBox = paramets as System.Windows.Forms.TextBox;
                    if (tmpTextBox.Text.Equals(""))
                    {
                        //SqlParameter parameter = new SqlParameter(tmpTextBox.Name.ToString(), tmpTextBox.Text);
                        //parameter.IsNullable = true;
                        //parameter.Value = DBNull.Value;
                        //paramList.Add(parameter);
                    }
                    else
                    {
                        paramList.Add(new SqlParameter(tmpTextBox.Name.ToString(), tmpTextBox.Text));
                    }
                }
                else if (paramets is DateTimePicker)
                {
                    DateTimePicker tmpdatePicker = paramets as DateTimePicker;
                    string         _tmpDate;
                    _tmpDate = tmpdatePicker.Value.ToString("yyyyMMdd");
                    paramList.Add(new SqlParameter(tmpdatePicker.Name.ToString(), _tmpDate));

                    if (tmpdatePicker.Name.ToLower().Equals("@startdate"))
                    {
                        startDate = tmpdatePicker.Value;
                    }
                    else if (tmpdatePicker.Name.ToLower().Equals("@enddate"))
                    {
                        endDate = tmpdatePicker.Value;
                    }
                }
                else if (paramets is CheckedListBox)
                {
                    System.Windows.Forms.CheckedListBox tmpchecklistbox = paramets as System.Windows.Forms.CheckedListBox;

                    List <String[]> checkedlist = new List <string[]>();
                    foreach (object Item in tmpchecklistbox.CheckedItems)
                    {
                        if (Item.ToString().Equals("Velg alle"))
                        {
                            continue;
                        }
                        String[] chcSplit = Item.ToString().Split('_');
                        checkedlist.Add(chcSplit);
                    }

                    paramList.Add(new SqlParameter(tmpchecklistbox.Name, CreateSqlDataRecords(checkedlist)));
                }
                else if (paramets is CheckBox)
                {
                    CheckBox tmpcheckbox = paramets as CheckBox;

                    paramList.Add(new SqlParameter(tmpcheckbox.Name, tmpcheckbox.Checked));
                }
            }
            exp_Factory.setDate(startDate, endDate);
            return(paramList);
        }