// Добавление гостя в спискок private void button1_Click(object sender, EventArgs e) { try { Visitor visitor = new Visitor(); visitor.Surname = textBox2.Text; visitor.Name = textBox3.Text; visitor.Patronymic = textBox6.Text; visitor.Country = textBox4.Text; visitor.City = textBox5.Text; visitor.Num = num; visitor.Birthday = dateTimePicker2.Value; if (visitor.Surname == "" || visitor.Name == "" || visitor.Country == "" || visitor.City == "") { throw new ArgumentException("Все поля (кроме отчества) должны быть заполнены."); } visitors.Add(visitor); string s = visitor.Surname + " " + visitor.Name; textBox1.AppendText(s + "\n"); comboBox1.Items.Add(s); textBox2.Clear(); textBox3.Clear(); textBox6.Clear(); } catch (ArgumentException exc) { MessageBox.Show(exc.Message, "Регистрация гостя", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// This method provides List of Visitors available in Database. /// </summary> /// <param name="strWhere">Specifies condition for retrieving records.</param> /// <returns>Collection of Visitor Objects.</returns> public static VisitorList GetList(string strCompany, string strContactNo) { VisitorList objList = null; string strSql = "Select * from VISITORMASTER "; if (strCompany != string.Empty & strContactNo == string.Empty) { strSql += " WHERE COMPANY = '" + strCompany + "'"; } else if (strCompany == string.Empty & strContactNo != string.Empty) { strSql += " WHERE CONTACTNO = '" + strContactNo + "'"; } else if ((strCompany != string.Empty) & (strContactNo != string.Empty)) { strSql += " WHERE COMPANY = '" + strCompany + "' AND CONTACTNO = '" + strContactNo + "'"; } strSql += " ORDER BY VISITORREGNO"; using (SqlConnection Conn = new SqlConnection(General.GetSQLConnectionString())) { using (SqlCommand objCmd = new SqlCommand()) { objCmd.Connection = Conn; objCmd.CommandType = CommandType.Text; objCmd.CommandText = strSql; if (Conn.State != ConnectionState.Open) { Conn.Open(); } using (SqlDataReader oReader = objCmd.ExecuteReader()) { if (oReader.HasRows) { objList = new VisitorList(); while (oReader.Read()) { objList.Add(FillDataRecord(oReader)); } } oReader.Close(); oReader.Dispose(); } } } return(objList); }
public static void Visit(string visitorId) { var visitor = VisitorList.FirstOrDefault(x => x.Id == visitorId); if (visitor == null) { VisitorList.Add(new Visitor { Id = visitorId, FirstVisitAt = DateTime.Now, LatestVisitAt = DateTime.Now }); } else { visitor.LatestVisitAt = DateTime.Now; } }
/// <summary> /// This method called when the request arrives. /// </summary> /// <param name="visitorId">visitor identity</param> public static void Visit(string visitorId) { var visitor = VisitorList.FirstOrDefault(x => x.Id == visitorId); var d = DateTime.Now; if (visitor == null) { VisitorList.Add(new Visitor { Id = visitorId, FirstVisitAt = d, LatestVisitAt = d, ExpiredAt = d.AddSeconds(ViCounterSettings.ActivityDuration) }); } else { visitor.LatestVisitAt = d; visitor.ExpiredAt = d.AddSeconds(ViCounterSettings.ActivityDuration); } }