public void Post(DataModelStatsBib dd1)
 {
     StatsBibFunctions fn1 = new StatsBibFunctions();
     DataModelStatsBibRecord tempData = fn1.setTempData();
     tempData = fn1.getSQLData(tempData, dd1);
     if (tempData.statPTotal == 0) { tempData.statPTotal = fn1.getPTotal(tempData, dd1); }
     if (dd1.statType == "Adds") { tempData.statAdds = dd1.stat; }
     if (dd1.statType == "Total") { tempData.statTotal = dd1.stat; }
     tempData.iType = dd1.iType;
     tempData.iAudiance = dd1.iAudiance;
     tempData.dateReport = dd1.dateReport;
     tempData.dateCreated = DateTime.Now;
     tempData.statNet = tempData.statTotal - tempData.statPTotal;
     tempData.statDeletes = tempData.statPTotal + tempData.statAdds - tempData.statTotal;
     if (tempData.statDeletes < 0) { tempData.statDeletes = tempData.statDeletes * -1; }
     fn1.proccessData(tempData);
 }
        public DataModelStatsBibRecord getSQLData(DataModelStatsBibRecord tempData, DataModelStatsBib dd1)
        {
            Models.StatsBib.DataSetStatsBibTableAdapters.OLPL_Apps_Stats_BibTableAdapter tbConnection = new Models.StatsBib.DataSetStatsBibTableAdapters.OLPL_Apps_Stats_BibTableAdapter();
            DataSetStatsBib.OLPL_Apps_Stats_BibDataTable tbResults = new DataSetStatsBib.OLPL_Apps_Stats_BibDataTable();
            tbConnection.FillByFilter(tbResults, dd1.dateReport, dd1.iType, dd1.iAudiance);
            if (tbResults.Count > 0)
            {
                DataSetStatsBib.OLPL_Apps_Stats_BibRow row1 = (DataSetStatsBib.OLPL_Apps_Stats_BibRow)tbResults.Rows[0];
                tempData.iType = row1.iType;
                tempData.id = row1.id;
                tempData.iAudiance = row1.iAudiance;
                tempData.statNet = row1.statNet;
                tempData.statAdds = row1.statAdds;
                tempData.statPTotal = row1.statPTotal;
                tempData.dateCreated = row1.dateCreated;
                tempData.dateReport = row1.dateReport;
                tempData.statDeletes = row1.statDeletes;
                tempData.statTotal = row1.statTotal;

            }
            else { tempData.id = 0; }
            return tempData;
        }
        public int getPTotal(DataModelStatsBibRecord tempData, DataModelStatsBib dd1)
        {
            Models.StatsBib.DataSetStatsBibTableAdapters.OLPL_Apps_Stats_BibTableAdapter tbConnection = new Models.StatsBib.DataSetStatsBibTableAdapters.OLPL_Apps_Stats_BibTableAdapter();
            DataSetStatsBib.OLPL_Apps_Stats_BibDataTable tbResults = new DataSetStatsBib.OLPL_Apps_Stats_BibDataTable();
            DateTime datePTotal;
            if (dd1.dateReport.Month == 1)
            {
                int year = dd1.dateReport.Year-1;
                datePTotal = DateTime.Parse("12/1/" + year.ToString());

            }
            else
            {
                datePTotal = dd1.dateReport.AddMonths(-1);
            }
            tbConnection.FillByFilter(tbResults, datePTotal, dd1.iType, dd1.iAudiance);
            if (tbResults.Count > 0)
            {
                DataSetStatsBib.OLPL_Apps_Stats_BibRow row1 = (DataSetStatsBib.OLPL_Apps_Stats_BibRow)tbResults.Rows[0];
                return row1.statTotal;
            }
            else { return 0; }
        }