Пример #1
0
    public static List <SampleAnalizeControl> getSampleAnalizeControl(List <SampleAnalize> samples, int year)
    {
        List <SampleAnalizeControl> samplescontrol = new List <SampleAnalizeControl>();
        int maxcount = 20;
        SampleAnalizeControl samplecontrol = new SampleAnalizeControl();

        if (samples.Count < 20)
        {
            maxcount = samples.Count;
        }
        samplecontrol.Nrc = maxcount;


        for (int i = 0; i < maxcount; i++)
        {
            SampleAnalize sample = samples[i];
            //      sample.Val = Math.Round(sample.Val, 2);
            string nrcontrol = sample.Nrcontrol;
            int    nrc       = 1;
            if (year == 2012)
            {
                nrc = 3;
            }
            if (nrcontrol.StartsWith("C"))
            {
                nrc = Convert.ToInt32(nrcontrol.Substring(1));
            }


            //   if (i <= maxcount - 1)
            switch (nrc)
            {
            case 1: samplecontrol.C1 = sample.Val; break;

            case 2: samplecontrol.C2 = sample.Val; break;

            case 3: samplecontrol.C3 = sample.Val; break;

            case 4: samplecontrol.C4 = sample.Val; break;

            case 5: samplecontrol.C5 = sample.Val; break;

            case 6: samplecontrol.C6 = sample.Val; break;

            case 7: samplecontrol.C7 = sample.Val; break;

            case 8: samplecontrol.C8 = sample.Val; break;

            case 9: samplecontrol.C9 = sample.Val; break;

            case 10: samplecontrol.C10 = sample.Val; break;

            case 11: samplecontrol.C11 = sample.Val; break;

            case 12: samplecontrol.C12 = sample.Val; break;

            case 13: samplecontrol.C13 = sample.Val; break;

            case 14: samplecontrol.C14 = sample.Val; break;

            case 15: samplecontrol.C15 = sample.Val; break;

            case 16: samplecontrol.C16 = sample.Val; break;

            case 17: samplecontrol.C17 = sample.Val; break;

            case 18: samplecontrol.C18 = sample.Val; break;

            case 19: samplecontrol.C19 = sample.Val; break;

            case 20: samplecontrol.C20 = sample.Val; break;

            case 21: samplecontrol.C21 = sample.Val; break;

            case 22: samplecontrol.C22 = sample.Val; break;


            default: break;
            }
        }
        samplescontrol.Add(samplecontrol);
        return(samplescontrol);
    }
Пример #2
0
    public static List<SampleAnalize> GetSampleAnalize(int fermaid, string crot)
    {
        int curryear = DateTime.Now.Year;

        List<SampleAnalize> samples = new List<SampleAnalize>();
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["AdditionalInformation"].ConnectionString);
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = conn;
        string querycrot = "";
        if (crot.Length > 0)
        {
            querycrot = " and CodFerma='" + crot + "' ";
        }
        cmd.CommandText =
            "SELECT NrComanda, DataTestare,CantitateLaPrelevare,Grasime,ProcentProteine,Caseina,ProcentLactoza,SubstantaUscata,PH,Urea,NumarCeluleSomatice from MostreTancuri Where FermaId =" +
            fermaid + querycrot
            + " and Year(DataTestare) =" + curryear
            + " Order By DataTestare";
        conn.Open();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        DataTable table = ds.Tables[0];
        if (table.Rows != null && table.Rows.Count > 0)
        {
            DataRow row = table.Rows[0];

            string refcontrol = row["NrComanda"].ToString();
            string nrcontrol = row["NrComanda"].ToString();
            DateTime datatestare = DateTime.Parse(row["DataTestare"].ToString());


            int nrrows = table.Rows.Count;
            int count = 0;
            double cant = 0;
            double[] summ = new double[9];
            for (int i = 0; i < 9; i++)
                summ[i] = 0.00;
            string nrc = "C1";
            while (count < nrrows)
            {
                SampleAnalize sample = new SampleAnalize();

                if (refcontrol.StartsWith("C"))
                {
                    int cratima = -1;
                    if (refcontrol.IndexOf("-") > 0)
                        cratima = refcontrol.IndexOf("-");
                    if (cratima > 2)
                        nrc = refcontrol.Substring(0, cratima);
                    else
                        nrc = refcontrol.Substring(0, 2);
                }
                sample.Datatestare = datatestare;
                sample.Nrcontrol = nrc;
                sample.INrcontrol = Convert.ToInt32(nrc.Substring(1));
                row = table.Rows[count];
                datatestare = DateTime.Parse(row["DataTestare"].ToString());
                nrcontrol = row["NrComanda"].ToString();

                while (count < nrrows && nrcontrol.Equals(refcontrol))
                {
                    // create avg parameter 
                    double litri = 0.00;
                    try
                    {
                        litri = Convert.ToDouble(row["CantitateLaPrelevare"], CultureInfo.InvariantCulture);
                    }
                    catch
                    {
                        litri = 0.00;
                    }
                    cant += litri;
                    for (int i = 0; i < 9; i++)
                    {
                        double sum = 0;
                        try
                        {
                            if (i < 8)
                                sum = Convert.ToDouble(row[3 + i], CultureInfo.InvariantCulture);
                            else
                            {
                                double gras = Convert.ToDouble(row["Grasime"], CultureInfo.InvariantCulture);
                                double prot = Convert.ToDouble(row["ProcentProteine"], CultureInfo.InvariantCulture);
                                if (prot > 0)
                                    sum = gras / prot;
                            }
                        }
                        catch
                        {
                            sum = 0.00;
                        }
                        summ[i] += sum * litri;
                    }

                    count++;
                    if (count < nrrows)
                    {
                        row = table.Rows[count];
                        datatestare = DateTime.Parse(row["DataTestare"].ToString());
                        nrcontrol = row["NrComanda"].ToString();
                    }
                }

                sample.Cantitate = cant;
                if (cant > 0)
                {
                    sample.Grasime = summ[0] / cant;
                    sample.Proteine = summ[1] / cant;
                    sample.Caseina = summ[2] / cant;
                    sample.Lactoza = summ[3] / cant;
                    sample.Solide = summ[4] / cant;
                    sample.Ph = summ[5] / cant;
                    sample.Urea = summ[6] / cant;
                    sample.Ncs = summ[7] / cant;
                    sample.GrasProt = summ[8] / cant;
                }
                samples.Add(sample);
                // add to list
                refcontrol = nrcontrol;
                cant = 0;
                for (int i = 0; i < 9; i++)
                    summ[i] = 0.00;
            } // while rows
        } //if data exists
        return samples;
    }
Пример #3
0
    public static List <SampleAnalize> GetSampleAnalize(int fermaid, string crot, int curryear)
    {
//            int curryear = DateTime.Now.Year;

        List <SampleAnalize> samples = new List <SampleAnalize>();
        SqlConnection        conn    = new SqlConnection(ConfigurationManager.ConnectionStrings["AdditionalInformation"].ConnectionString);
        SqlCommand           cmd     = new SqlCommand();

        cmd.Connection = conn;
        string querycrot = "";

        if (crot.Length > 0)
        {
            querycrot = " and CodFerma='" + crot + "' ";
        }
        cmd.CommandText = "SELECT NrComanda, DataTestare,CantitateLaPrelevare,Grasime,ProcentProteine,Caseina,ProcentLactoza,SubstantaUscata,PH,Urea,NumarCeluleSomatice from MostreTancuri Where FermaId =" + fermaid + querycrot
                          + " and Year(DataTestare) =" + curryear
                          + " Order By DataTestare";
        conn.Open();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet        ds = new DataSet();

        da.Fill(ds);
        DataTable table = ds.Tables[0];

        if (table.Rows != null && table.Rows.Count > 0)
        {
            DataRow row = table.Rows[0];

            string refcontrol  = row["NrComanda"].ToString();
            string nrcontrol   = row["NrComanda"].ToString();
            string datatestare = row["DataTestare"].ToString();


            int      nrrows = table.Rows.Count;
            int      count  = 0;
            double   cant   = 0;
            double[] summ   = new double[9];
            for (int i = 0; i < 9; i++)
            {
                summ[i] = 0.00;
            }
            string nrc = "C1";
            if (curryear == 2012)
            {
                nrc = "C3";
            }
            while (count < nrrows)
            {
                SampleAnalize sample = new SampleAnalize();

                if (refcontrol.StartsWith("C"))
                {
                    int cratima = -1;
                    if (refcontrol.IndexOf("-") > 0)
                    {
                        cratima = refcontrol.IndexOf("-");
                    }
                    if (cratima > 2)
                    {
                        nrc = refcontrol.Substring(0, cratima);
                    }
                    else
                    {
                        nrc = refcontrol.Substring(0, 2);
                    }
                }

                sample.Datatestare = datatestare; sample.Nrcontrol = nrc; sample.INrcontrol = Convert.ToInt32(nrc.Substring(1));
                row         = table.Rows[count];
                datatestare = row["DataTestare"].ToString();
                nrcontrol   = row["NrComanda"].ToString();

                while (count < nrrows && nrcontrol.Equals(refcontrol))
                {     // create avg parameter
                    double litri = 0.00;
                    try
                    {
                        litri = Convert.ToDouble(row["CantitateLaPrelevare"]);
                    }
                    catch
                    {
                        litri = 0.00;
                    }
                    cant += litri;
                    for (int i = 0; i < 9; i++)
                    {
                        double sum = 0;
                        try
                        {
                            if (i < 8)
                            {
                                sum = Convert.ToDouble(row[3 + i]);
                            }
                            else
                            {
                                double gras = Convert.ToDouble(row["Grasime"]);
                                double prot = Convert.ToDouble(row["ProcentProteine"]);
                                if (prot > 0)
                                {
                                    sum = gras / prot;
                                }
                            }
                        }
                        catch
                        {
                            sum = 0.00;
                        }
                        summ[i] += sum * litri;
                    }

                    count++;
                    if (count < nrrows)
                    {
                        row         = table.Rows[count];
                        datatestare = row["DataTestare"].ToString();
                        nrcontrol   = row["NrComanda"].ToString();
                    }
                }

                sample.Cantitate = cant;
                if (cant > 0)
                {
                    sample.Grasime  = summ[0] / cant; sample.Proteine = summ[1] / cant; sample.Caseina = summ[2] / cant; sample.Lactoza = summ[3] / cant;
                    sample.Solide   = summ[4] / cant; sample.Ph = summ[5] / cant; sample.Urea = summ[6] / cant; sample.Ncs = summ[7] / cant;
                    sample.GrasProt = summ[8] / cant;
                }
                samples.Add(sample);
                // add to list
                refcontrol = nrcontrol;
                cant       = 0;
                for (int i = 0; i < 9; i++)
                {
                    summ[i] = 0.00;
                }
            } // while rows
        }     //if data exists
        return(samples);
    }
Пример #4
0
    protected void ItemsSubreportProcessingEventHandler(object sender, SubreportProcessingEventArgs e)
    {
        int fermaid = 0;

        try { fermaid = Convert.ToInt32(FermaId.Text); }
        catch { fermaid = 0; }
        string username = Username.Text;

        UserInfos userinfos  = UserInfos.getUserInfos(username);
        string    reportpath = e.ReportPath;
        string    nrpar      = e.Parameters["NrPar"].Values[0];
        int       year       = Int32.Parse(Session["year"].ToString());
        int       i          = 0;

        try { i = Convert.ToInt32(nrpar); }
        catch { i = 0; }
        if (fermaid != 0)
        {
            e.DataSources.Clear();

            ReportDataSource rds = new ReportDataSource();
            rds.Name = "SampleAnalize";
            List <SampleAnalize> samples = SampleAnalize.GetSampleAnalize(fermaid, "", year);
            foreach (SampleAnalize sample in samples)
            {
                switch (i)
                {
                case 0:
                    sample.Val = sample.Grasime; break;

                case 1:
                    sample.Val = sample.Proteine; break;

                case 2:
                    sample.Val = sample.Caseina; break;

                case 3:
                    sample.Val = sample.Lactoza; break;

                case 4:
                    sample.Val = sample.Solide; break;

                case 5:
                    sample.Val = sample.Ph; break;

                case 6:
                    sample.Val = sample.Urea; break;

                case 7:
                    sample.Val = sample.Ncs; break;

                case 8:
                    sample.Val = sample.Cantitate; break;

                default: break;
                }
                sample.Val = Math.Round(sample.Val, 2);
            }
            rds.Value = samples;
            e.DataSources.Add(rds);

            //
            ReportDataSource rdsc = new ReportDataSource();
            rdsc.Name = "SampleAnalizeControl";
            List <SampleAnalizeControl> samplescontrol = SampleAnalize.getSampleAnalizeControl(samples, year);
            rdsc.Value = samplescontrol;
            e.DataSources.Add(rdsc);
            // detaliu
            ReportDataSource rdscrot = new ReportDataSource();
            rdscrot.Name = "SampleAnalizeCrotalia";
            List <SampleAnalizeCrotalia> samplescrot = SampleAnalize.getSampleAnalizeCrotalia(fermaid, i, year);
            rdscrot.Value = samplescrot;
            e.DataSources.Add(rdscrot);
        }
    }
Пример #5
0
    public void CreateReportExt(int year)
    {
        LocalReport report = new LocalReport();
        string      mimeType, encoding, fileExtension;

        string[]  streams;
        Warning[] warnings;
        Session["year"]             = year;
        report.SubreportProcessing += new SubreportProcessingEventHandler(ItemsSubreportProcessingEventHandler);

        int fermaid = 0;

        try { fermaid = Convert.ToInt32(FermaId.Text); }
        catch { fermaid = 0; }
        string    username  = Username.Text;
        UserInfos userinfos = UserInfos.getUserInfos(username);

        if (fermaid != 0)
        {
            string[] parIds          = { "g", "p", "c", "l", "s", "h", "u", "n", "z" };
            string[] chartLabelsName = { "Grasime (g/100g)", "Proteine (g/100g)", "Cazeina (g/100g)", "Lactoza (g/100g)", "SUN (g/100g)", "pH", "Uree (mg/dl)", "NCSx1000", "Cantitate lapte (l)" };
            string[] chartTitles     = { "Grasime", "Proteine", "Cazeina",
                                         "Lactoza",     "SUN",      "Ph",
                                         "Uree",        "NCS",      "Cantitate lapte" };
            string[] um = { "g/100g", "g/100g", "g/100g", "g/100g", "g/100g", "pH", "mg/dl", "NCSx1000", "l" };


            //controale
            ReportDataSource rdsm = new ReportDataSource();
            rdsm.Name = "SampleAnalizeExt";
            logger.Info(string.Format("CreateReportExt|getting samples"));
            List <SampleAnalizeExt> samplesext = SampleAnalize.GetSampleAnalizeExt(fermaid, year);
            logger.Info(string.Format("CreateReportExt|got {0} samples", samplesext.Count));
            rdsm.Value = samplesext;
            report.DataSources.Clear();
            report.DataSources.Add(rdsm);

            report.ReportPath = "ControlsSummaryExt.rdlc";
            string datatestare = "Data: " + DateTime.Now.ToString("dd/MM/yyyy");
            // set reports parameters
            string title = FermaName.Text + " - " + "Cod exploatatie " + FermaCod.Text;

            ReportParameter pCod  = new ReportParameter("CodExpl", FermaCod.Text);
            ReportParameter pData = new ReportParameter("DataExec", datatestare);
            //    ReportParameter pChartTitle = new ReportParameter("ChartTitle", chartTitles[i]);
            //   ReportParameter pChartLabelsName = new ReportParameter("ChartLabelsName", chartLabelsName[i]);
            // ReportParameter pUm = new ReportParameter("Um", um[i]);
            ReportParameter   pTitle    = new ReportParameter("Title", title);
            ReportParameter   pUsername = new ReportParameter("UserName", username);
            string            baseurl   = "http://" + Request.ServerVariables.Get("HTTP_HOST") + "/" + ConfigurationManager.AppSettings["baseurl"];
            ReportParameter   pBaseurl  = new ReportParameter("BaseUrl", baseurl);
            ReportParameter[] p         = { pCod, pData, pTitle, pBaseurl, pUsername };
            report.SetParameters(p);
            report.Refresh();
            // write xls
            string httppath = ConfigurationManager.AppSettings["httppath"] + userinfos.AsocId + "/" + year + "/";
            //"/Downloads/";
            string filepath = ConfigurationManager.AppSettings["filepath"] + userinfos.AsocId + "\\" + year + "\\";
            if (!Directory.Exists(filepath))
            {
                Directory.CreateDirectory(filepath);
            }

            //"D:\\portal\\Downloads\\";
            string path_raport_http = "http://" + Request.ServerVariables.Get("HTTP_HOST") + "/" + httppath;
            string fermaname        = replace_special_car_null(FermaName.Text);
            string raport_excel     = FermaCod.Text + "_" + fermaname + ".xls";
            string excel_file       = filepath + raport_excel;
            string excel_link       = path_raport_http + raport_excel;
            //      infomess.Text = infomess.Text + ";" + excel_file;
            byte[] xls_content = report.Render("EXCEL", StaticData.DEVICE_INFO_XLS, out mimeType, out encoding, out fileExtension, out streams, out warnings);
            File.WriteAllBytes(excel_file, xls_content);
            logger.Info(string.Format("CreateReportExt|wrote excel file {0}", excel_file));
            //rename sheets
            List <SampleAnalize> samples = SampleAnalize.GetSampleAnalize(fermaid, "", year);
            using (StreamReader input = new StreamReader(excel_file))
            {
                HSSFWorkbook workbook = new HSSFWorkbook(new POIFSFileSystem(input.BaseStream));
                if (workbook != null && samples.Count > 0)
                {
                    for (int count = 0; count < samples.Count; count++)
                    {
                        workbook.SetSheetName(count, samples[count].Nrcontrol);
                    }

                    for (int count = 0; count < chartTitles.Length; count++)
                    {
                        string sheetname = chartTitles[count].Replace(" ", "");
                        workbook.SetSheetName(count + samples.Count, "Grafic" + sheetname);
                    }
                    //  workbook.SetSheetName(1, "Detaliu date");
                    WriteExcel(excel_file, workbook);
                }
            }
        }
    }
Пример #6
0
    public void CreateReportExt()
    {
        LocalReport report = new LocalReport();
        string      mimeType, encoding, fileExtension;

        string[]  streams;
        Warning[] warnings;
        int       year = Int32.Parse(Session["year"].ToString());

        report.SubreportProcessing += new SubreportProcessingEventHandler(ItemsSubreportProcessingEventHandler);


        string    username  = User.Identity.Name;
        UserInfos userinfos = UserInfos.getUserInfos(username);
        int       fermaid   = GetFermaId(userinfos.UserCod);

        if (fermaid != 0)
        {
            string[] parIds          = { "g", "p", "c", "l", "s", "h", "u", "n", "z" };
            string[] chartLabelsName = { "Grasime (g/100g)", "Proteine (g/100g)", "Cazeina (g/100g)", "Lactoza (g/100g)", "SUN (g/100g)", "pH", "Uree (mg/dl)", "NCSx1000", "Cantitate lapte (l)" };
            string[] chartTitles     = { "Grasime", "Proteine", "Cazeina",
                                         "Lactoza",     "SUN",      "Ph",
                                         "Uree",        "NCS",      "Cantitate lapte" };
            string[] um = { "g/100g", "g/100g", "g/100g", "g/100g", "g/100g", "pH", "mg/dl", "NCSx1000", "l" };


            //controale
            ReportDataSource rdsm = new ReportDataSource();
            rdsm.Name = "SampleAnalizeExt";
            List <SampleAnalizeExt> samplesext = SampleAnalize.GetSampleAnalizeExt(fermaid, year);
            rdsm.Value = samplesext;
            report.DataSources.Clear();
            report.DataSources.Add(rdsm);

            report.ReportPath = "ControlsSummaryExt.rdlc";
            string datatestare = "Data: " + DateTime.Now.ToString("dd/MM/yyyy");
            // set reports parameters
            string title = userinfos.NumeFerma + " - " + "Cod exploatatie " + userinfos.UserCod;

            ReportParameter pCod  = new ReportParameter("CodExpl", userinfos.UserCod);
            ReportParameter pData = new ReportParameter("DataExec", datatestare);
            //    ReportParameter pChartTitle = new ReportParameter("ChartTitle", chartTitles[i]);
            //   ReportParameter pChartLabelsName = new ReportParameter("ChartLabelsName", chartLabelsName[i]);
            // ReportParameter pUm = new ReportParameter("Um", um[i]);
            ReportParameter   pTitle    = new ReportParameter("Title", title);
            ReportParameter   pUsername = new ReportParameter("UserName", username);
            string            baseurl   = "http://" + Request.ServerVariables.Get("HTTP_HOST") + "/" + ConfigurationManager.AppSettings["baseurl"];
            ReportParameter   pBaseurl  = new ReportParameter("BaseUrl", baseurl);
            ReportParameter[] p         = { pCod, pData, pTitle, pBaseurl, pUsername };
            report.SetParameters(p);
            report.Refresh();
            // write xls
            string httppath = ConfigurationManager.AppSettings["httppath"] + userinfos.AsocId + "/" + year + "/";
            //"/Downloads/";
            string filepath = ConfigurationManager.AppSettings["filepath"] + userinfos.AsocId + "\\" + year + "\\";
            if (!Directory.Exists(filepath))
            {
                Directory.CreateDirectory(filepath);
            }

            //"D:\\portal\\Downloads\\";
            string path_raport_http = "http://" + Request.ServerVariables.Get("HTTP_HOST") + "/" + httppath;
            string fileid           = chartTitles[0];
            string fermaname        = replace_special_car_null(userinfos.NumeFerma);
            string raport_excel     = userinfos.UserCod + "_" + fermaname + ".xls";
            string excel_file       = filepath + raport_excel;
            string excel_link       = path_raport_http + raport_excel;
            byte[] xls_content      = report.Render("EXCEL", deviceInfoXls, out mimeType, out encoding, out fileExtension, out streams, out warnings);
            File.WriteAllBytes(excel_file, xls_content);
            //rename sheets
            List <SampleAnalize> samples = SampleAnalize.GetSampleAnalize(fermaid, "", year);
            using (StreamReader input = new StreamReader(excel_file))
            {
                HSSFWorkbook workbook = new HSSFWorkbook(new POIFSFileSystem(input.BaseStream));
                if (workbook != null && samples.Count > 0)
                {
                    for (int count = 0; count < samples.Count; count++)
                    {
                        workbook.SetSheetName(count, samples[count].Nrcontrol);
                    }

                    for (int count = 0; count < chartTitles.Length; count++)
                    {
                        string sheetname = chartTitles[count].Replace(" ", "");
                        workbook.SetSheetName(count + samples.Count, "Grafic" + sheetname);
                    }
                    //  workbook.SetSheetName(1, "Detaliu date");
                    WriteExcel(excel_file, workbook);
                }
            }

            //
            ContentPlaceHolder holder = (ContentPlaceHolder)Master.FindControl("MainContent");
            HyperLink          hyper  = (HyperLink)holder.FindControl("xlslink" + parIds[0]);
            hyper.Visible     = true;
            hyper.NavigateUrl = excel_link;
            hyper.Text        = raport_excel;
            ErrorMessage.Text = "";
        }//fermaid >0
        else
        {
            // ErrorMessage.Text = "Nu exista date pentru codul "+ userinfos.UserCod;
        }
    }
Пример #7
0
    public void CreateReportAll()
    {
        LocalReport report = new LocalReport();
        string      mimeType, encoding, fileExtension;

        string[]  streams;
        Warning[] warnings;

        int year             = Int32.Parse(Session["year"].ToString());
        ReportDataSource rds = new ReportDataSource();

        rds.Name = "SampleAnalize";
        string    username  = User.Identity.Name;
        UserInfos userinfos = UserInfos.getUserInfos(username);
        int       fermaid   = GetFermaId(userinfos.UserCod);

        if (fermaid != 0)
        {
            List <SampleAnalize> samples = SampleAnalize.GetSampleAnalize(fermaid, "", year);
            if (samples.Count > 0)
            {
                string[] parIds          = { "g", "p", "c", "l", "s", "h", "u", "n", "z" };
                string[] chartLabelsName = { "Grasime (g/100g)", "Proteine (g/100g)", "Cazeina (g/100g)", "Lactoza (g/100g)", "SUN (g/100g)", "pH", "Uree (mg/dl)", "NCSx1000", "Cantitate lapte (l)" };
                string[] chartTitles     = { "Grasime", "Proteine", "Cazeina",
                                             "Lactoza",     "SUN",      "Ph",
                                             "Uree",        "NCS",      "Cantitate lapte" };
                string[] um = { "g/100g", "g/100g", "g/100g", "g/100g", "g/100g", "pH", "mg/dl", "NCSx1000", "l" };

                ContentPlaceHolder holder = (ContentPlaceHolder)Master.FindControl("MainContent");
                for (int i = 0; i < 1; i++)
                {//parIds.Length
                    string   endChar = parIds[i].ToUpper();
                    CheckBox chk     = (CheckBox)holder.FindControl("chk" + endChar);
                    if (chk.Checked)
                    {
                        //set current param
                        foreach (SampleAnalize sample in samples)
                        {
                            switch (i)
                            {
                            case 0:
                                sample.Val = sample.Grasime; break;

                            case 1:
                                sample.Val = sample.Proteine; break;

                            case 2:
                                sample.Val = sample.Caseina; break;

                            case 3:
                                sample.Val = sample.Lactoza; break;

                            case 4:
                                sample.Val = sample.Solide; break;

                            case 5:
                                sample.Val = sample.Ph; break;

                            case 6:
                                sample.Val = sample.Urea; break;

                            case 7:
                                sample.Val = sample.Ncs; break;

                            case 8:
                                sample.Val = sample.Cantitate; break;

                            default: break;
                            }
                            sample.Val = Math.Round(sample.Val, 2);
                        }
                        // create samplescontrol from samples

                        // set reports datasource
                        rds.Value = samples;
                        report.DataSources.Clear();
                        report.DataSources.Add(rds);

                        //
                        ReportDataSource rdsc = new ReportDataSource();
                        rdsc.Name = "SampleAnalizeControl";
                        List <SampleAnalizeControl> samplescontrol = SampleAnalize.getSampleAnalizeControl(samples, year);
                        rdsc.Value = samplescontrol;
                        report.DataSources.Add(rdsc);
                        // detaliu
                        ReportDataSource rdscrot = new ReportDataSource();
                        rdscrot.Name = "SampleAnalizeCrotalia";
                        List <SampleAnalizeCrotalia> samplescrot = SampleAnalize.getSampleAnalizeCrotalia(fermaid, i, year);
                        rdscrot.Value = samplescrot;
                        report.DataSources.Add(rdscrot);
                        //controale
                        ReportDataSource rdsm = new ReportDataSource();
                        rdsm.Name = "SampleAnalizeExt";
                        List <SampleAnalizeExt> samplesext = SampleAnalize.GetSampleAnalizeExt(fermaid, year);
                        rdsm.Value = samplesext;
                        report.DataSources.Add(rdsm);

                        report.ReportPath = "ControlsSummaryAll.rdlc";
                        string datatestare = "Data: " + DateTime.Now.ToString("dd/MM/yyyy");
                        // set reports parameters
                        string title = userinfos.NumeFerma + " - " + "Cod exploatatie " + userinfos.UserCod;

                        ReportParameter   pCod             = new ReportParameter("CodExpl", userinfos.UserCod);
                        ReportParameter   pData            = new ReportParameter("DataExec", datatestare);
                        ReportParameter   pChartTitle      = new ReportParameter("ChartTitle", chartTitles[i]);
                        ReportParameter   pChartLabelsName = new ReportParameter("ChartLabelsName", chartLabelsName[i]);
                        ReportParameter   pUm       = new ReportParameter("Um", um[i]);
                        ReportParameter   pTitle    = new ReportParameter("Title", title);
                        ReportParameter   pUsername = new ReportParameter("UserName", username);
                        string            baseurl   = "http://" + Request.ServerVariables.Get("HTTP_HOST") + "/" + ConfigurationManager.AppSettings["baseurl"];
                        ReportParameter   pBaseurl  = new ReportParameter("BaseUrl", baseurl);
                        ReportParameter[] p         = { pCod, pData, pChartTitle, pChartLabelsName, pUm, pTitle, pUsername, pBaseurl };
                        report.SetParameters(p);
                        report.Refresh();
                        // write xls
                        string httppath = ConfigurationManager.AppSettings["httppath"];
                        //"/Downloads/";
                        string filepath = ConfigurationManager.AppSettings["filepath"];
                        //"D:\\portal\\Downloads\\";
                        string path_raport_http = "http://" + Request.ServerVariables.Get("HTTP_HOST") + "/" + httppath;
                        string fileid           = chartTitles[i];
                        if (i == 8)
                        {
                            fileid = fileid.Substring(0, 4);
                        }
                        string raport_excel = "Grafic" + fileid + "_" + userinfos.UserCod + "_" + (DateTime.Now).ToString("ddMMyyyy") + ".xls";
                        string excel_file   = filepath + raport_excel;
                        string excel_link   = path_raport_http + raport_excel;
                        byte[] xls_content  = report.Render("EXCEL", deviceInfoXls, out mimeType, out encoding, out fileExtension, out streams, out warnings);
                        File.WriteAllBytes(excel_file, xls_content);
                        //rename sheets
                        using (StreamReader input = new StreamReader(excel_file))
                        {
                            HSSFWorkbook workbook = new HSSFWorkbook(new POIFSFileSystem(input.BaseStream));
                            if (workbook != null)
                            {
                                workbook.SetSheetName(0, chartTitles[i]);
                                //  workbook.SetSheetName(1, "Detaliu date");
                                WriteExcel(excel_file, workbook);
                            }
                        }

                        //

                        HyperLink hyper = (HyperLink)holder.FindControl("xlslink" + parIds[i]);
                        hyper.Visible     = true;
                        hyper.NavigateUrl = excel_link;
                        hyper.Text        = raport_excel;
                        ErrorMessage.Text = "";
                    } //checked
                }     //for
            }         //samplecount >0
        }             //fermaid >0
        else
        {
            // ErrorMessage.Text = "Nu exista date pentru codul "+ userinfos.UserCod;
        }
    }
Пример #8
0
    public string CreateReport(string username, string crot, string nrpar)
    {
        string url = "";

        try
        {
            int      i               = Convert.ToInt32(nrpar);
            string[] parIds          = { "g", "p", "c", "l", "s", "h", "u", "n", "z", "gp" };
            string[] chartLabelsName =
            {
                "Grasime (g/100g)", "Proteine (g/100g)", "Cazeina (g/100g)", "Lactoza (g/100g)",
                "SUN (g/100g)",     "pH",                "Uree (mg/dl)",     "NCSx1000",        "Cantitate lapte (l)", "Grasime/Proteine (%)"
            };
            string[] chartTitles =
            {
                "Grasime", "Proteine", "Cazeina",
                "Lactoza", "SUN",      "Ph",
                "Uree",    "NCS",      "Cantitate lapte", "Raport Grasime/Proteine"
            };
            string[] um = { "g/100g", "g/100g", "g/100g", "g/100g", "g/100g", "pH", "mg/dl", "NCSx1000", "l", "%" };

            //  string username = Page.User.Identity.Name;
            UserInfos userinfos = UserInfos.getUserInfos(username);
            int       fermaid   = GetFermaId(userinfos.UserCod);
            int       year      = Int32.Parse(Session["year"].ToString());
            string    baseurl   = "http://" + Request.ServerVariables.Get("HTTP_HOST") + "/" +
                                  ConfigurationManager.AppSettings["httppath"];
            string filepath = ConfigurationManager.AppSettings["filepath"];
            string fileid   = chartTitles[i];
            fileid = fileid.Replace("/", "");
            fileid = fileid.Replace("/", "");
            if (i == 8)
            {
                fileid = fileid.Substring(0, 4);
            }
            string raport_excel = "Grafic" + fileid + "_" + userinfos.UserCod + "_" + crot + "_" + year + ".xls";

            LocalReport report = new LocalReport();
            report.EnableHyperlinks = true;
            string    mimeType, encoding, fileExtension;
            string[]  streams;
            Warning[] warnings;

            if (fermaid != 0)
            {
                List <SampleAnalize> samples = SampleAnalize.GetSampleAnalize(fermaid, crot, year);
                if (samples.Count > 0)
                {
                    //set current param
                    foreach (SampleAnalize sample in samples)
                    {
                        switch (i)
                        {
                        case 0:
                            sample.Val = sample.Grasime;
                            break;

                        case 1:
                            sample.Val = sample.Proteine;
                            break;

                        case 2:
                            sample.Val = sample.Caseina;
                            break;

                        case 3:
                            sample.Val = sample.Lactoza;
                            break;

                        case 4:
                            sample.Val = sample.Solide;
                            break;

                        case 5:
                            sample.Val = sample.Ph;
                            break;

                        case 6:
                            sample.Val = sample.Urea;
                            break;

                        case 7:
                            sample.Val = sample.Ncs;
                            break;

                        case 8:
                            sample.Val = sample.Cantitate;
                            break;

                        case 9:
                            sample.Val = 0;
                            if (sample.Proteine > 0)
                            {
                                sample.Val = sample.Grasime / sample.Proteine;
                            }
                            break;

                        default:
                            break;
                        }
                        sample.Val = Math.Round(sample.Val, 2);
                    }
                    //datasources
                    ReportDataSource rds = new ReportDataSource();
                    rds.Name  = "SampleAnalize";
                    rds.Value = samples;
                    report.DataSources.Clear();
                    report.DataSources.Add(rds);

                    //
                    ReportDataSource rdsc = new ReportDataSource();
                    rdsc.Name = "SampleAnalizeControl";
                    List <SampleAnalizeControl> samplescontrol = SampleAnalize.getSampleAnalizeControl(samples, year);
                    rdsc.Value = samplescontrol;
                    report.DataSources.Add(rdsc);
                    //parameters
                    report.ReportPath = "GraficCrotalie.rdlc";
                    string datatestare = "Data: " + DateTime.Now.ToString("dd/MM/yyyy");
                    // set reports parameters
                    string          title       = userinfos.NumeFerma + " - " + "Cod exploatatie " + userinfos.UserCod;
                    ReportParameter pCod        = new ReportParameter("CodExpl", title);
                    ReportParameter pData       = new ReportParameter("DataExec", datatestare);
                    ReportParameter pChartTitle = new ReportParameter("ChartTitle",
                                                                      chartTitles[i] + " - Nr. matricol: " + crot);
                    ReportParameter pChartLabelsName = new ReportParameter("ChartLabelsName", chartLabelsName[i]);
                    ReportParameter pUm = new ReportParameter("Um", um[i]);

                    ReportParameter[] p = { pCod, pData, pChartTitle, pChartLabelsName, pUm };
                    report.SetParameters(p);
                    report.Refresh();

                    string excel_file  = filepath + raport_excel;
                    byte[] xls_content = report.Render("EXCEL", deviceInfoXls, out mimeType, out encoding,
                                                       out fileExtension, out streams, out warnings);
                    File.WriteAllBytes(excel_file, xls_content);
                    url = baseurl + raport_excel;
                }
            }
            else
            {
                FailureText.Text = "Nu exista date pentru codul " + userinfos.UserCod + " si numarul matricol " + crot;
            }
        }

        catch (Exception ex)
        {
            string err   = ex.Message;
            string trace = ex.StackTrace;
            Logger.Error(trace + "|" + err);
        }
        return(url);
    }