/// ----------------------- /// --- No Prediction ---- ------------------------------ /// ---------------------- /// --- Birth --- public ArrayList noPredictBirth(PopulationPredict myNoPredictBirth) { SqlConnection sqlConn = new SqlConnection(DL.SQL.conn); SqlDataReader sqlRdr = null; try { sqlConn.Open(); //------------------- SqlCommand sqlCom = new SqlCommand("BirthPredictor", sqlConn); sqlCom.CommandType = CommandType.StoredProcedure; sqlCom.Parameters.Add("@SelectedRegion", myNoPredictBirth.strPredictDistrict); sqlRdr = sqlCom.ExecuteReader(); //------------------- while (sqlRdr.Read()) { ArrayBirth objBirth = new ArrayBirth(); objBirth.intBirthYear = Convert.ToInt32(sqlRdr["tempYear"]); objBirth.doubleBirthCount = Convert.ToInt32(sqlRdr["tempCount"]); myBirthArray.Insert(b, objBirth); b = b + 1; } } catch (Exception ex) { } return(myBirthArray); }
protected void Page_Load(object sender, EventArgs e) { // --- xml Graph--- StringBuilder xmlDataBirth = new StringBuilder(); xmlDataBirth.Append("<chart caption='Year-Birth Report' subCaption='For Colombo' Column3DSliceDepth='10' showBorder='1' formatNumberScale='0' numberSuffix=' '>"); StringBuilder xmlDataDeath = new StringBuilder(); xmlDataDeath.Append("<chart caption='Year-Death Report' subCaption='For Colombo' Column3DSliceDepth='10' showBorder='1' formatNumberScale='0' numberSuffix=' '>"); StringBuilder xmlDataPopulation = new StringBuilder(); xmlDataPopulation.Append("<chart caption='Year-Population Report' subCaption='For Colombo' Column3DSliceDepth='10' showBorder='1' formatNumberScale='0' numberSuffix=' '>"); // ---------- if (!IsPostBack) { objPopulation.strPredictDistrict = "Colombo"; ArrayList DisBirth = objPopulation.noPredictBirth(objPopulation); ArrayList DisDeath = objPopulation.noPredictDeath(objPopulation); ArrayList DisPopulation = objPopulation.noPredictPopulation(objPopulation); // Loop only By Birth int Get = DisBirth.Count; for (int i = 0; i < Get; i++) { // --- Birth Data To xml --- BL.ArrayBirth objBirth = (BL.ArrayBirth)(DisBirth[i]); int yrBirth = objBirth.intBirthYear; double valBirth = objBirth.doubleBirthCount; xmlDataBirth.AppendFormat("<set label='{0}' value='{1}' />", yrBirth.ToString(), valBirth.ToString()); // --- Death Data To xml --- BL.ArrayDeath objDeath = (BL.ArrayDeath)(DisDeath[i]); int yrDeath = objDeath.intDeathYear; double valDeath = objDeath.doubleDeathCount; xmlDataDeath.AppendFormat("<set label='{0}' value='{1}' />", yrDeath.ToString(), valDeath.ToString()); // --- Population Data To xml --- BL.ArrayPopulation objPop = (BL.ArrayPopulation)(DisPopulation[i]); int yrPopulation = objPop.intPopulationYear; double valPopulation = objPop.doublePopulationCount; xmlDataPopulation.AppendFormat("<set label='{0}' value='{1}' />", yrPopulation.ToString(), valPopulation.ToString()); } /// Create The Birth Chart - Column3D Chart With Data From xmlDataBirth xmlDataBirth.Append("</chart>"); LiteralBirth.Text = FusionCharts.RenderChart("FusionCharts/Column3D.swf", "", xmlDataBirth.ToString(), "Column3DBirth", "430", "200", false, true); /// Create The Death Chart - Column3D Chart With Data From xmlDataDeath xmlDataDeath.Append("</chart>"); LiteralDeath.Text = FusionCharts.RenderChart("FusionCharts/Column3D.swf", "", xmlDataDeath.ToString(), "Column3DDeath", "430", "200", false, true); /// Create The Population Chart - Column3D Chart With Data From xmlDataPopulation xmlDataPopulation.Append("</chart>"); LiteralPop.Text = FusionCharts.RenderChart("FusionCharts/Line.swf", "", xmlDataPopulation.ToString(), "Column3DPopulation", "430", "200", false, true); } }
protected void btnEnter_Click(object sender, EventArgs e) { ClearListBx(); if (txtYear.Text != "") { DateTime dt = DateTime.Now; int CurrentYear = dt.Year; string Reg = ddlRegion.SelectedValue.ToString(); int t = int.Parse(txtYear.Text) - CurrentYear; //if (Reg != "--Select--" && 0 <= t && t < 5) { /// Clear The Error Message. lblMsg.Text = ""; /// Make Visible the Content Items lblBirth.Visible = true; LstBirth.Visible = true; /// <summary> /// Pass The Value From "PopulationPredict.cs" /// </summary> objPopulationPredict.strPredictDistrict = Reg; objPopulationPredict.intPredictYear = int.Parse(txtYear.Text); ArrayList CalcBirthArray = objPopulationPredict.FindBirth(objPopulationPredict); /// <summary> /// Inialize The Graph Elements. /// And Get The Value From "PopulationPredict.cs" /// </summary> // ---Graph Column3D--- StringBuilder xmlData = new StringBuilder(); xmlData.Append("<chart caption='Year-Birth Report' subCaption='' Column3DSliceDepth='10' showBorder='1' formatNumberScale='0' numberSuffix=' '>"); // ----------Pie------ // ------------------- int Get = CalcBirthArray.Count; for (int i = 0; i < Get; i++) { // --- Display Birth --- BL.ArrayBirth objBirth = (BL.ArrayBirth)(CalcBirthArray[i]); int BirthYr = objBirth.intBirthYear; double BirthVal = objBirth.doubleBirthCount; LstBirth.Items.Add("Year : " + BirthYr + " -->> " + BirthVal); xmlData.AppendFormat("<set label='{0}' value='{1}' />", BirthYr.ToString(), BirthVal.ToString()); // --------------------- } /// Close chart Element------ /// xmlData.Append("</chart>"); /// Create The Chart - Column3D Chart With Data From xmlData BirthGraph.Text = FusionCharts.RenderChart("FusionCharts/Column3D.swf", "", xmlData.ToString(), "Column3DDeath", "900", "400", false, true); /// BirthPieGraph.Text = FusionCharts.RenderChart("FusionCharts/Pie3D.swf", "", xmlData.ToString(), "Pie3DDeath", "622", "200", false, true); /// /// ------------------------- } //else //lblMsg.Text = "Error Inserted Value... :-("; } //else //lblMsg.Text = "Please Enter Value... :-("; }
/// --- Birth --- /// <summary> /// ------------- /// </summary> public ArrayList FindBirth(PopulationPredict myFindBirth) { SqlConnection sqlConn = new SqlConnection(DL.SQL.conn); SqlDataReader sqlRdr = null; try { sqlConn.Open(); //------------- SqlCommand sqlCom = new SqlCommand("BirthPredictor", sqlConn); sqlCom.CommandType = CommandType.StoredProcedure; sqlCom.Parameters.Add("@SelectedRegion", myFindBirth.strPredictDistrict); sqlRdr = sqlCom.ExecuteReader(); //------------ while (sqlRdr.Read()) { ArrayBirth objArrBirth = new ArrayBirth(); objArrBirth.intBirthYear = Convert.ToInt32(sqlRdr["tempYear"]); objArrBirth.doubleBirthCount = Convert.ToInt32(sqlRdr["tempCount"]); myBirthArray.Insert(b, objArrBirth); b = b + 1; } /// Close The Connections sqlRdr.Close(); sqlConn.Close(); /// --- Find Oldest Year & Value --- ArrayBirth objOldBirthFind = (ArrayBirth)(myBirthArray[0]); int DB_Old_BirthYear = objOldBirthFind.intBirthYear; double DB_Old_BirthCount = objOldBirthFind.doubleBirthCount; /// --- Find Newest year & Value --- int NoOf_tblBirth_DB_Row = myBirthArray.Count; int NoOf_Rows = NoOf_tblBirth_DB_Row - 1; ArrayBirth objNewBirthFind = (ArrayBirth)(myBirthArray[NoOf_Rows]); int DB_New_BirthYear = objNewBirthFind.intBirthYear; double DB_New_BirthCount = objNewBirthFind.doubleBirthCount; /// --- Predict Future --- int FindYear = myFindBirth.intPredictYear; int t = FindYear - DB_New_BirthYear; int CalcYear = CurrentYear; for (int i = 0; i < t; i++) { if (CalcYear <= 2022) { /// Algo For Birth double NFuture = DB_New_BirthCount * Math.Exp((Math.Log((DB_New_BirthCount / DB_Old_BirthCount), Math.Exp(1)) / 4) * 1); /// Algo For Birth ArrayBirth objPredictArrBirth = new ArrayBirth(); objPredictArrBirth.intBirthYear = CalcYear; objPredictArrBirth.doubleBirthCount = Math.Ceiling(NFuture); myBirthArray.Insert(b, objPredictArrBirth); b = b + 1; // Copy Predicted value to calc next year value DB_New_BirthCount = NFuture; // Increment The Year CalcYear++; } else { //DB_New_BirthCount = DB_New_BirthCount - 302; ArrayBirth objPredictArrBirth = new ArrayBirth(); objPredictArrBirth.intBirthYear = CalcYear; objPredictArrBirth.doubleBirthCount = Math.Ceiling(DB_New_BirthCount); myBirthArray.Insert(b, objPredictArrBirth); b = b + 1; CalcYear++; } } } catch (Exception ex) { } return(myBirthArray); }
/// --- Population --- /// <summary> /// ------------ /// </summary> public ArrayList FindPopulation(PopulationPredict myFindPopulation) { /// --- Get the Newest Value from DB -->> tblPopulation SqlConnection sqlConn = new SqlConnection(DL.SQL.conn); SqlDataReader sqlRdr = null; try { sqlConn.Open(); //------------- SqlCommand sqlCom = new SqlCommand("PopulationPredictor", sqlConn); sqlCom.CommandType = CommandType.StoredProcedure; sqlCom.Parameters.Add("@SelectedRegion", myFindPopulation.strPredictDistrict); sqlRdr = sqlCom.ExecuteReader(); //------------ while (sqlRdr.Read()) { ArrayPopulation objArrPopulation = new ArrayPopulation(); objArrPopulation.intPopulationYear = Convert.ToInt32(sqlRdr["tempYear"]); objArrPopulation.doublePopulationCount = Convert.ToInt32(sqlRdr["tempCount"]); myPopulationArray.Insert(p, objArrPopulation); p = p + 1; } /// Close The Connections sqlRdr.Close(); sqlConn.Close(); /// --- Find Newest year & Value --- int NoOf_tblPopulation_DB_Row = myPopulationArray.Count; int NoOf_Rows = NoOf_tblPopulation_DB_Row - 1; ArrayPopulation objNewPopulationFind = (ArrayPopulation)(myPopulationArray[NoOf_Rows]); int DB_New_PopulationYear = objNewPopulationFind.intPopulationYear; double DB_New_PopulationCount = objNewPopulationFind.doublePopulationCount; /// --- Predict Future --- int FindYear = myFindPopulation.intPredictYear; int t = FindYear - DB_New_PopulationYear; int CalcYear = CurrentYear; for (int i = 0; i < t; i++) { /// --- Birth Of The Year --- ArrayBirth objGetBirth = (ArrayBirth)(myBirthArray[NoOf_Rows]); double GetBirth = objGetBirth.doubleBirthCount; /// --- Death Of The Year --- ArrayDeath objGetdeath = (ArrayDeath)(myDeathArray[NoOf_Rows]); double GetDeath = objGetdeath.doubleDeathCount; /// Population Predict Algo double FuturePopulation = DB_New_PopulationCount + GetBirth - GetDeath; /// Population Predict Algo ArrayPopulation objPredictArrPopulation = new ArrayPopulation(); objPredictArrPopulation.intPopulationYear = CalcYear; objPredictArrPopulation.doublePopulationCount = Math.Ceiling(FuturePopulation); myPopulationArray.Insert(p, objPredictArrPopulation); p = p + 1; // Copy Predicted value to calc next year value DB_New_PopulationCount = FuturePopulation; // Increment The Year CalcYear++; // Increment The Birth & Death Year Value NoOf_Rows++; } } catch (Exception ex) { } return(myPopulationArray); }