using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Collections;
using PDFGenerator.BusinessLayer.DataSection;
using PDFGenerator.BusinessLayer;
using System.Collections.Generic;

namespace PDFGenerator.BusinessLayer.DataSection
{
    class DSS138Proventi : IDataSection
    {
        public DSS138Proventi()  {
        }

        #region IDataSection Members
        public DataSectionResult getDataSection(List<SessionStruct> tabelleSessione, string querySql, DataThread dataThread)
        {

            try
            {
                FormatNum num = new FormatNum();
                DataSectionResult dsr = new DataSectionResult();
                if (dataThread.NoMonitoraggio)
                                    return dsr;

                DataTable dt = SectionManager.GetDataSection(tabelleSessione, querySql, dataThread);
              
                DataSetS138 ds138 = new DataSetS138();

                decimal tot = 0;
                for (int r = 0; r < dt.Rows.Count; r++)
                {
                    if (dt.Rows[r]["DESPROD"] == null || dt.Rows[r]["DESPROD"].ToString().Equals(""))
                        throw new Exception("DescrizioneProdotto is Null");
                     
                        DataRow dr = ds138.Proventi.NewRow();
                        dr["DTRIFE"] = dt.Rows[r]["DTRIFE"].ToString().Substring(0,10);
                        dr["DESPROD"] = dt.Rows[r]["DESPROD"].ToString();
                        dr["TIPMOV"] = dt.Rows[r]["TIPMOV"].ToString();
                        dr["IMPORTO"] = num.ConvertNum(dt.Rows[r]["IMPORTO"].ToString());
                        tot += decimal.Parse(dt.Rows[r]["IMPORTO"].ToString());
                        ds138.Proventi.Rows.Add(dr);
                     
                }

                DataRow drTotal = ds138.Totale.NewRow();
                drTotal["Descrizione"] = "Totale";
                drTotal["Totale"] = tot;
                ds138.Totale.Rows.Add(drTotal);

                
                dsr.DatiSezione = ds138;
                dsr.Esito = ds138.Proventi.Rows.Count;
                return dsr;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
    }
}