// Edit New Item private void editMenu_Click(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(CS)) { con.Open(); try { Reset(); EditPanel.Visible = true; viewPanel.Visible = false; saveInfo.Text = "UPDATE"; //COUNTRYID = Convert.ToInt32(dgvCountry.SelectedRows[0].Cells[0].Value); textName.Text = dgvCountry.SelectedRows[0].Cells[1].Value.ToString(); textDes.Text = dgvCountry.SelectedRows[0].Cells[2].Value.ToString(); } catch (SqlException ex) { Console.WriteLine(ex.Message); } } DataTable dt = CountryDA.GetCountryById(COUNTRYID); if (dt != null && dt.Rows.Count > 0) { textName.Text = dt.Rows[0]["CountryName"].ToString(); textDes.Text = dt.Rows[0]["Description"].ToString(); } }
// Reset Section private void Reset() { dgvCountry.DataSource = CountryDA.GetCountries(); textName.Clear(); textDes.Clear(); textName.Focus(); }
public static DataTable GetCountryByCampYearID(int CampYearID) { DataTable dt = CountryDA.GetCountryByCampYearID(CampYearID); return(dt); //DataTable dtOut = new DataTable(); //dtOut.Columns.Add(new DataColumn("CountryID", typeof(int))); //dtOut.Columns.Add(new DataColumn("CountryName", typeof(string))); //DataRow newrow; //int temp; //foreach(DataRow dr in dt.Rows) //{ // string name = dr["CountryName"].ToString(); // if (!int.TryParse(name, out temp)) // { // if (name.Length <= 20) // { // newrow = dtOut.NewRow(); // if (dtOut.Rows.Count > 0) // newrow[0] = dtOut.Rows[dtOut.Rows.Count - 1]["CountryID"]; // else // newrow[0] = 1; // newrow[1] = name; // dtOut.Rows.Add(newrow); // } // } //} //return dtOut; }
// Delete Item private void deleteMenu_Click(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(CS)) { con.Open(); try { if (COUNTRYID > 0) { EditPanel.Visible = false; CountryDA.Delete(this.COUNTRYID); MessageBox.Show("Row Deleted successfully", "Deletd", MessageBoxButtons.OK, MessageBoxIcon.Information); viewPanel.Visible = false; Reset(); } else { MessageBox.Show("Please Select a Row to Delete the info", "Select?", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (SqlException ex) { Console.WriteLine(ex.Message); } } }
protected void btnDelete_Click(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(CS)) { con.Open(); try { int COUNTRYID; COUNTRYID = Convert.ToInt32(gdvCountry.SelectedRow.Cells[0].Text); if (COUNTRYID > 0) { editPanel.Visible = false; CountryDA.Delete(COUNTRYID); lblMessage.Text = "Row Deleted successfully"; viewPanel.Visible = false; Reset(); } else { lblMessage.Text = "Please Select a Row to Delete the info"; } } catch (SqlException ex) { if (ex.Number == 547) { lblMessage.Text = $"{ex.Number} occured.Sorry, You can't delete this row because it has associated row that you need to delete first."; } } } }
public ResultEntity <IEnumerable <CountryEntity> > GetAll(DBParamEntity dbParamEntity) { var validationResult = new ResultEntity <IEnumerable <CountryEntity> >(); using (var countryDA = new CountryDA()) { validationResult.Value = countryDA.GetAll(dbParamEntity); } return(validationResult); }
public ResultEntity <CountryEntity> GetById(int id) { var validationResult = new ResultEntity <CountryEntity>(); using (var countryDA = new CountryDA()) { validationResult.Value = countryDA.GetById(id); } return(validationResult); }
public ResultEntity <CountryEntity> Create(CountryEntity countryEntity) { var validationResult = new ResultEntity <CountryEntity>(); using (var countryDA = new CountryDA()) { validationResult.Value = countryDA.Create(countryEntity); } return(validationResult); }
public ResultEntity <int> GetTotalRows(DBParamEntity dbParamEntity) { var validationResult = new ResultEntity <int>(); using (var countryDA = new CountryDA()) { validationResult.Value = countryDA.GetTotalRows(dbParamEntity); } return(validationResult); }
private void saveInfo_Click_1(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(CS)) { con.Open(); try { if (saveInfo.Text == "INSERT") { if (!CountryDA.CountryNameCheck(textName.Text)) { CountryDA.Insert(textName.Text, textDes.Text, dateTimePicker.Value); MessageBox.Show("Data inserted Successfully", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information); Reset(); EditPanel.Visible = false; viewPanel.Visible = false; } else { MessageBox.Show($"Country Name {textName.Text} Already Exsist"); } } else if (saveInfo.Text == "UPDATE") { if (COUNTRYID > 0) { if (!CountryDA.DuplicateCheck(textName.Text, COUNTRYID)) { CountryDA.Update(textName.Text, textDes.Text, dateTimePicker.Value, this.COUNTRYID); MessageBox.Show("Data Updated successfully", "Updated", MessageBoxButtons.OK, MessageBoxIcon.Information); Reset(); EditPanel.Visible = false; } else { MessageBox.Show($"Country Name {textName.Text} Already Exsist"); } } else { MessageBox.Show("Please Select a Country to update the info", "Select?", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (SqlException ex) { Console.WriteLine(ex.Message); } } }
public IActionResult GetCountriesById(int countryId) { List <CountryModel> countriesById = new List <CountryModel>(); var dt = CountryDA.GetCountryById(countryId); foreach (DataRow dataRow in dt.Rows) { CountryModel countryModel = new CountryModel(); countryModel.CountryId = Convert.ToInt32(dataRow["CountryId"]); countryModel.CountryName = dataRow["CountryName"].ToString(); countryModel.Description = dataRow.IsNull("Description") ? null : dataRow["Description"].ToString(); countriesById.Add(countryModel); } return(Ok(countriesById)); }
[HttpPost] //Insert to Database public IHttpActionResult Post([FromBody] Contact postContact) { ContactDA.read(); if (postContact != null) { Country country = null; bool storeData = true; foreach (var item in CountryDA.CtryList) { if (Convert.ToString(item.CountryName).ToLower() == postContact.Address.Country.CountryName.ToLower()) { country = item; storeData = false; } } if (storeData) { country = new Country(); country.CountryName = postContact.Address.Country.CountryName; country.CountryCode = postContact.Address.Country.CountryCode; //=============================================== //DATA ACCESS METHOD CountryDA.insert(country); //=============================================== } Address a = new Address(postContact.Address.AddressST, postContact.Address.City, postContact.Address.State, postContact.Address.ZipCode, country.CountryID, country); AddressDA.insert(a); Contact con = new Contact( postContact.FName, postContact.LName, postContact.Age, postContact.Gender, postContact.Email, a.AddressID, postContact.PhoneNumber, a); ContactDA.insert(con); return(Ok("Contact Added.")); } else { return(BadRequest()); } }
public ResultEntity <int> DeleteById(int id) { var validationResult = new ResultEntity <int>(); using (var countryDA = new CountryDA()) { var ids = new int[] { id }; validationResult.Value = countryDA.Delete(ids); if (validationResult.Value != 1) { validationResult.Warning.Add("Failed delete record Country with ID: " + id); return(validationResult); } } return(validationResult); }
public ResultEntity <CountryEntity> Update(CountryEntity countryEntity) { var validationResult = new ResultEntity <CountryEntity>(); using (var countryDA = new CountryDA()) { var resultUpdate = countryDA.Update(countryEntity); if (resultUpdate <= 0) { validationResult.Warning.Add("Failed Updating Country!"); return(validationResult); } validationResult.Value = countryEntity; } return(validationResult); }
public void Reset() { gdvCountry.DataSource = CountryDA.GetCountries(); gdvCountry.DataBind(); }
//protected void btnImg_Click(object sender, ImageClickEventArgs e) //{ // editPanel.Visible = true; // if (Calendar1.Visible) // { // Calendar1.Visible = false; // } // else // { // Calendar1.Visible = true; // } //} //protected void Calendar1_SelectionChanged(object sender, EventArgs e) //{ // editPanel.Visible = true; // //Calendar1.Visible = false; // txtCreateDate.Text = Calendar1.SelectedDate.ToShortDateString(); //} protected void btnSave_Click(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(CS)) { con.Open(); try { if (btnSave.Text == "INSERT") { DateTime dateTime = DateTime.Parse(datepicker.Value); if (Page.IsValid) { if (!CountryDA.CountryNameCheck(txtCountryName.Text)) { CountryDA.Insert(txtCountryName.Text, txtDescription.Text, dateTime); lblMessage.Text = "Data Inserted successfully"; ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Insert is successfull')", true); Reset(); editPanel.Visible = false; viewPanel.Visible = false; } else { lblMessage.Text = $"Country Name {txtCountryName.Text} Already Exists. Data Can not be inserted!"; ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Country name already exists.Data Can not be inserted!')", true); } } } else if (btnSave.Text == "UPDATE") { DateTime dateTime = DateTime.Parse(datepicker.Value); int COUNTRYID; COUNTRYID = Convert.ToInt32(gdvCountry.SelectedRow.Cells[0].Text); if (COUNTRYID > 0) { if (!CountryDA.DuplicateCheck(txtCountryName.Text, COUNTRYID)) { if (Page.IsValid) { CountryDA.Update(txtCountryName.Text, txtDescription.Text, dateTime, COUNTRYID); ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Data updated successfully')", true); lblMessage.Text = "Data Updated successfully"; editPanel.Visible = false; Reset(); } } else { lblMessage.Text = $"Country Name {txtCountryName.Text} Already Exists. Data Can not be updated!"; ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Country name already exists.Data Can not be inserted!')", true); } } else { lblMessage.Text = "Please Select a Country to update the info "; } } } catch (SqlException ex) { Console.WriteLine(ex.Message); } } }
public List <CountryModel> Get(CountryModel filter) { CountryDA da = new CountryDA(); return(da.Get(filter)); }
public CountryModel GetById(int id) { CountryDA da = new CountryDA(); return(da.GetById(id)); }
public CountryService() { countryDA = new CountryDA(); }
public void Delete(int countryId) { CountryDA.Delete(countryId); }
public void Put(string countryName, string description, DateTime createDate, int countryId) { CountryDA.Update(countryName, description, createDate, countryId); }
public IActionResult Post(string countryName, string description, DateTime createDate) { CountryDA.Insert(countryName, description, createDate); return(Ok()); }