Guest User

Untitled

a guest
Aug 14th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. protected void Page_Load(Object sender, EventArgs e)
  2. {
  3. if (!IsPostBack)
  4. {
  5. cal2.VisibleDate = DateTime.Today;
  6. FillLeaveplannerDataset();
  7. }
  8. }
  9. protected void FillLeaveplannerDataset()
  10. {
  11. cal2.VisibleDate = cal2.TodaysDate;
  12. DateTime firstDate = new DateTime(cal2.VisibleDate.Year, cal2.VisibleDate.Month, 1).AddDays(-6);
  13. DateTime lastDate = new DateTime(cal2.VisibleDate.Date.AddMonths(1).Year, cal2.VisibleDate.Date.AddMonths(1).Month, 1).AddDays(7);
  14. dsleaveplanner = GetCurrentMonthData(firstDate, lastDate);
  15. }
  16. protected DateTime GetFirstDayOfNextMonth()
  17. {
  18. int monthNumber, yearNumber;
  19. if (cal2.VisibleDate.Month == 12)
  20. {
  21. monthNumber = 1;
  22. yearNumber = cal2.VisibleDate.Year + 1;
  23. }
  24. else
  25. {
  26. monthNumber = cal2.VisibleDate.Month + 1;
  27. yearNumber = cal2.VisibleDate.Year;
  28. }
  29. DateTime lastDate = new DateTime(yearNumber, monthNumber, 1);
  30. return lastDate;
  31. }
  32. protected DataSet GetCurrentMonthData(DateTime firstDate, DateTime lastDate)
  33. {
  34. DataSet dsMonth = new DataSet();
  35. MySqlConnection con = new MySqlConnection("Server=localhost;Database=mydb;Uid=myid;Pwd=abc123;");
  36. string caldate = "Select date From approved Where date >= @firstDate And date <= @lastDate Group By date";
  37. MySqlCommand cmd = new MySqlCommand(caldate, con);
  38. cmd.Parameters.AddWithValue("@firstDate", firstDate);
  39. cmd.Parameters.AddWithValue("@lastDate", lastDate);
  40. MySqlDataAdapter mysqlDataAdapter = new MySqlDataAdapter(cmd);
  41. try
  42. {
  43. mysqlDataAdapter.Fill(dsMonth);
  44. }
  45. catch { }
  46. return dsMonth;
  47. }
  48.  
  49. protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
  50. {
  51. DateTime nextDate;
  52. if (dsleaveplanner != null)
  53. {
  54. foreach (DataRow dr in dsleaveplanner.Tables[0].Rows)
  55. {
  56. nextDate = (DateTime)dr["date"];
  57. MySqlConnection conn = new MySqlConnection("Server=localhost;Database=mydb;Uid=myid;Pwd=abc123;");
  58. string cntdate = "SELECT COUNT(date) FROM approved WHERE date = @date";
  59. string cntdate2 = "SELECT COUNT(date) FROM pending WHERE date = @date";
  60. MySqlCommand cmd2 = new MySqlCommand(cntdate, conn);
  61. MySqlCommand cmd3 = new MySqlCommand(cntdate2, conn);
  62. cmd2.Parameters.AddWithValue("@date", nextDate);
  63. cmd3.Parameters.AddWithValue("@date", nextDate);
  64. conn.Open();
  65. string count = cmd2.ExecuteScalar().ToString();
  66. string count2 = cmd3.ExecuteScalar().ToString();
  67. var slot2 = Convert.ToInt32(count);
  68. Int32 slot3 = 10 - slot2;
  69. string slot4 = slot3.ToString();
  70. conn.Close();
  71. if (nextDate == e.Day.Date)
  72. {
  73. e.Cell.BackColor = System.Drawing.Color.Orange;
  74. Environment.NewLine.ToString();
  75. e.Cell.ForeColor = System.Drawing.Color.Red;
  76. e.Cell.Font.Size = 9;
  77. e.Cell.Controls.Add(new LiteralControl("<p></p>Slot available:"));
  78. e.Cell.Controls.Add(new LiteralControl(slot4));
  79. e.Cell.Controls.Add(new LiteralControl("<p></p>Pending:"));
  80. e.Cell.Controls.Add(new LiteralControl(count2));
  81. }
  82. else
  83. {
  84. e.Cell.Font.Size = 9;
  85. e.Cell.Controls.Add(new LiteralControl("<p>Slot available: 10</p>"));
  86. e.Cell.Controls.Add(new LiteralControl("<p></p>Pending: 0"));
  87. }
  88. }
  89. }
  90.  
  91. }
  92. protected void Calendar1_VisibleMonthChanged(object sender,
  93. MonthChangedEventArgs e)
  94. {
  95. DateTime firstDate = e.NewDate.AddDays(-7);
  96. DateTime lastDate = e.NewDate.AddMonths(1).AddDays(7);
  97. dsleaveplanner = GetCurrentMonthData(firstDate, lastDate);
  98.  
  99. }
Add Comment
Please, Sign In to add comment