public bool SaveVesitorWithZone(Visitor aVisitor, List<Zone> zoneListforSave) { aConnection.Open(); string query = string.Format("INSERT INTO tbl_visitor VALUES('{0}','{1}','{2}')", aVisitor.VisitorName, aVisitor.VisitorEmail, aVisitor.VisitorPhone); SqlCommand aCommand = new SqlCommand(query, aConnection); int total = aCommand.ExecuteNonQuery(); aConnection.Close(); if (SaveVisitorandZoneinJointTable(aVisitor.VisitorEmail, zoneListforSave)&& total>0) { return true; } return false; }
public string SaveVesitorWithZone(Visitor aVisitor, List<Zone> zoneListforSave) { if (aVisitorGateway.IsThisEmailAlreadyinSystem(aVisitor.VisitorEmail)) { return "This Email's User Already Registerd"; } else { if (aVisitorGateway.SaveVesitorWithZone(aVisitor, zoneListforSave)) { return "Save Successfull"; } else { return "Faild"; } } }
private void saveButton_Click(object sender, EventArgs e) { Visitor aVisitor = new Visitor(); aVisitor.VisitorName=nameTextBox.Text; aVisitor.VisitorEmail = emailTextBox.Text; aVisitor.VisitorPhone = contactNumberTextBox.Text; if (nameTextBox.Text!="" && emailTextBox.Text!="" && contactNumberTextBox.Text!="") { List<Zone> zoneListforSave = new List<Zone>(); foreach (var zones in zoneList) { foreach (string itemChecked in zoneTypeCheckedListBox.CheckedItems) { string name = itemChecked; if (name == zones.Name) { zoneListforSave.Add(zones); } } } string message = visitorManager.SaveVesitorWithZone(aVisitor, zoneListforSave); MessageBox.Show(message, @"Information", MessageBoxButtons.OK, MessageBoxIcon.Information); nameTextBox.Clear(); emailTextBox.Clear(); contactNumberTextBox.Clear(); } else { MessageBox.Show("Please Fillup All TextBox!!!", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadCheckListBox(); }
private int GetVisitorId(string visitorEmail) { aConnection.Open(); string query = string.Format("SELECT * FROM tbl_visitor WHERE email='{0}'",visitorEmail); SqlCommand aCommand = new SqlCommand(query, aConnection); SqlDataReader aReader = aCommand.ExecuteReader(); Visitor aVisitor = new Visitor(); if (aReader.HasRows) { while (aReader.Read()) { aVisitor.VisitorId = (int)aReader[0]; } } aReader.Close(); aConnection.Close(); return aVisitor.VisitorId; }
private List<Visitor> GetVisitorList(List<int> visitorIdList) { List<Visitor> visitorsList = new List<Visitor>(); foreach (var visitorId in visitorIdList) { aConnection.Open(); string query = string.Format("SELECT * FROM tbl_visitor WHERE id={0}", visitorId); SqlCommand aCommand = new SqlCommand(query, aConnection); SqlDataReader aReader = aCommand.ExecuteReader(); if (aReader.HasRows) { while (aReader.Read()) { Visitor aVisitor = new Visitor(); aVisitor.VisitorId = (int)aReader[0]; aVisitor.VisitorName = aReader[1].ToString(); aVisitor.VisitorEmail = aReader[2].ToString(); aVisitor.VisitorPhone = aReader[3].ToString(); visitorsList.Add(aVisitor); } } aReader.Close(); aConnection.Close(); } return visitorsList; }