public int SaveVisitor(Visitor aVisitor) { int visitorId=0; SqlConnection connection = new SqlConnection(connectionString); string query = "INSERT INTO VisitorTBL VALUES('" + aVisitor.Name + "','"+aVisitor.Email+"','"+aVisitor.ContactNumber+"')"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); command.ExecuteNonQuery(); query = "SELECT * FROM VisitorTBL"; command = new SqlCommand(query, connection); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { visitorId =int.Parse( reader["Id"].ToString()); } reader.Close(); connection.Close(); return visitorId; }
//public int GetVisitorId() public List<Visitor> GetSelectedZoneVisitors(int id) { List<Visitor> visitorList = new List<Visitor>(); SqlConnection connection = new SqlConnection(connectionString); string query = "SELECT * FROM VisitorTBL WHERE Id='"+id+"'"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); while(reader.Read()){ Visitor aVisitor = new Visitor(); aVisitor.Name = reader["Name"].ToString(); aVisitor.Email = reader["Email"].ToString(); aVisitor.ContactNumber = reader["ContactNumber"].ToString(); visitorList.Add(aVisitor); } reader.Close(); connection.Close(); return visitorList; }
public int CheckedZone(int visitorId) { int check = 0; foreach (Control box in visitorGroupBox.Controls) { if (box is CheckBox) { CheckBox temp = (CheckBox)box; if (temp.Checked) { check = 1; Visitor aVisitor = new Visitor(); Zone selectedZone = (Zone)temp.Tag; Zone aZone = new Zone(); aZone.Id = selectedZone.Id; aVisitor.AZon = aZone; visitorManager.SaveInRelation(visitorId,aVisitor.AZon.Id); zoneManager.UpdateTotalVisitors(aZone.Id); } } } return check; }
private void visitorEntrySaveButton_Click(object sender, EventArgs e) { Visitor aVisitor = new Visitor(); aVisitor.Name = nameTextBox.Text; aVisitor.Email = emailTextBox.Text; aVisitor.ContactNumber = contactNumberTextBox.Text; int visitorId = visitorManager.SaveVisitor(aVisitor); if (nameTextBox.Text == "" || emailTextBox.Text == "" || contactNumberTextBox.Text == "") { MessageBox.Show(@"Please Fillup all Information!",@"Warning!",MessageBoxButtons.OK,MessageBoxIcon.Information); return; } int value= CheckedZone(visitorId); if (value == 0) { MessageBox.Show("Select ZoneType!",@"Warning!",MessageBoxButtons.OK,MessageBoxIcon.Information); return; } MessageBox.Show("Visitor Saved Successfully!"); nameTextBox.Clear(); emailTextBox.Clear(); contactNumberTextBox.Clear(); this.Close(); }
public int SaveVisitor(Visitor aVisitor) { return visitorGateway.SaveVisitor(aVisitor) ; }