/// <summary> /// This method provides List of Visitor-GatePass available in Database. /// </summary> /// <param name="strWhere">Specifies condition for retrieving records.</param> /// <returns>Collection of Visitor GatePass Objects.</returns> public static VisitorGatePassList GetList(string strWhere, DateTime vwDate, bool flgShowAll) { VisitorGatePassList objList = null; string strSql = "Select * from VISITORGATEPASS "; if (!flgShowAll) { strSql += " WHERE GATEDATE = @gateDate "; if (strWhere != string.Empty) { strSql = strSql + " AND " + strWhere; } } else { if (strWhere != string.Empty) { strSql = strSql + " WHERE " + strWhere; } } strSql += " ORDER BY GATEDATE DESC, GATEPASSNO DESC"; using (SqlConnection Conn = new SqlConnection(General.GetSQLConnectionString())) { using (SqlCommand objCmd = new SqlCommand()) { objCmd.Connection = Conn; objCmd.CommandType = CommandType.Text; objCmd.CommandText = strSql; if (!flgShowAll) { objCmd.Parameters.AddWithValue("@gateDate", vwDate.ToString("dd-MMM-yy")); } if (Conn.State != ConnectionState.Open) { Conn.Open(); } using (SqlDataReader oReader = objCmd.ExecuteReader()) { if (oReader.HasRows) { objList = new VisitorGatePassList(); while (oReader.Read()) { objList.Add(FillDataRecord(oReader)); } } oReader.Close(); oReader.Dispose(); } } } return(objList); }
private void FillList() { int totVisitors = 0, totInVisitors = 0, totOutVisitors = 0; VisitorGatePassList objList = new VisitorGatePassList(); objList = VisitorGatePassManager.GetList("", dtpDate.Value, flgShowAll); lvwGPs.Items.Clear(); if (objList != null) { foreach (VisitorGatePass objVisitorGP in objList) { ListViewItem objLvwItem = new ListViewItem(); objLvwItem.Name = Convert.ToString(objVisitorGP.DBID); objLvwItem.Text = objVisitorGP.GatePassNo; objLvwItem.SubItems.Add(objVisitorGP.VisitorName); objLvwItem.SubItems.Add(objVisitorGP.GateDate.ToShortDateString()); objLvwItem.SubItems.Add(objVisitorGP.TimeIn.ToShortTimeString()); objLvwItem.SubItems.Add(objVisitorGP.ToMeet); objLvwItem.SubItems.Add(objVisitorGP.Purpose); if (objVisitorGP.TimeOut != DateTime.MinValue) { objLvwItem.SubItems.Add(objVisitorGP.TimeOut.ToShortTimeString()); } else { objLvwItem.SubItems.Add(""); } totVisitors += 1; totInVisitors += 1; if (objVisitorGP.TimeOut != DateTime.MinValue) { totOutVisitors += 1; } lvwGPs.Items.Add(objLvwItem); if (objVisitorGP.TimeOut != DateTime.MinValue) { objLvwItem.ForeColor = Color.Red; } else { objLvwItem.ForeColor = Color.Blue; } } } lblTotal.Text = Convert.ToString(totVisitors); lblTotalIn.Text = Convert.ToString(totInVisitors); lblTotalOut.Text = Convert.ToString(totOutVisitors); }