private void bunifuFlatButton1_Click_1(object sender, EventArgs e) { if (check()) { MessageBox.Show("Please complete the fields(if not applicable please indicate n/a)", "System Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { int prov = DBAccess.get_cmb_data(cmbProvince.Text, "sp_get_cmb_province", "prov_id"); int reg = DBAccess.get_cmb_data(cmbRegion.Text, "sp_get_cmb_region", "region_id"); hostProj = new hostProjects( id.ToString(), txtTitle.Text.Trim(), txtMgr.Text.Trim(), txtDuration.Text.Trim(), txtAddressNo.Text.Trim(), txtAddressStreet.Text.Trim(), txtAddressCity.Text.Trim(), prov.ToString(), reg.ToString(), txtBudget.Text.Trim(), txtSourceFund.Text.Trim(), rtbObjective.Text.Trim(), txtStart.Text.Trim(), txtTargetBeneficiaries.Text.Trim(), txtPosition.Text, txtContactNo.Text ); DBAccess.insert_host_proj(hostProj); dgv_proj.DataSource = DBAccess.dtProject("sp_load_project", id); logs = new auditTrail(frm_login.UserName, "Added a Project for LPI ID " + id); DBAccess.insert_logs(logs); MessageBox.Show("Successfully Added!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); clear(); dgv_proj.Enabled = true; btnDel.Enabled = true; btnUpdate.Enabled = true; txtID.Text = "(Auto generated)"; enabled(false); btnAdd.Visible = true; btnCancel.Visible = false; btnSave.Enabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.StackTrace); } }//if }
private void btnUpdate_Click(object sender, EventArgs e) { if (txtID.Text == string.Empty || txtID.Text == "(Auto generated)") { MessageBox.Show("Please Select Project ID !", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (check()) { MessageBox.Show("Please complete the fields(if not applicable please indicate n/a)", "System Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { int prov = DBAccess.get_cmb_data(txtprv.Text, "sp_get_cmb_province", "prov_id"); int reg = DBAccess.get_cmb_data(txtReg.Text, "sp_get_cmb_region", "region_id"); hostProj = new hostProjects( int.Parse(txtID.Text), txtTitle.Text.Trim(), txtMgr.Text.Trim(), txtDuration.Text.Trim(), txtAddressNo.Text.Trim(), txtAddressStreet.Text.Trim(), txtAddressCity.Text.Trim(), prov.ToString(), reg.ToString(), txtBudget.Text.Trim(), txtSourceFund.Text.Trim(), rtbObjective.Text.Trim(), txtStart.Text.Trim(), txtTargetBeneficiaries.Text.Trim(), txtPosition.Text, txtContactNo.Text ); DBAccess.update_host_proj(hostProj); logs = new auditTrail(frm_login.UserName, "Updated Project id " + txtID.Text); DBAccess.insert_logs(logs); MessageBox.Show("Successfully updated!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); clear(); txtID.Text = "(Auto generated)"; dgv_proj.DataSource = DBAccess.dtProject("sp_load_project", id); enabled(false); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.StackTrace); } } }
private void dgv_proj_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { clear(); enabled(true); int i = dgv_proj.CurrentRow.Index; string id = dgv_proj.Rows[i].Cells["Project ID"].Value.ToString(); hostProj = DBAccess.get_host_project(int.Parse(id)); if (hostProj != null) { try { txtID.Text = hostProj.Project_id.ToString(); txtTitle.Text = hostProj.Proj_title; txtMgr.Text = hostProj.Proj_mgr; txtDuration.Text = hostProj.Proj_duration; txtAddressNo.Text = hostProj.Proj_address_no; txtAddressStreet.Text = hostProj.Proj_address_street; txtAddressCity.Text = hostProj.Mun_city; txtBudget.Text = hostProj.Bugdet; txtSourceFund.Text = hostProj.Source_fund; txtTargetBeneficiaries.Text = hostProj.Target_benificiaries; txtStart.Text = hostProj.Date_start; cmbProvince.Text = hostProj.Prov_id; cmbRegion.Text = hostProj.Region_id; txtprv.Text = hostProj.Prov_id; txtReg.Text = hostProj.Region_id; rtbObjective.Text = hostProj.Objective; txtPosition.Text = hostProj.Coordinator_position; txtContactNo.Text = hostProj.ContactNo; } catch (IndexOutOfRangeException ex) { MessageBox.Show(ex.Message, "Incomplete Data!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Null"); } }