private void saveAll(object sender, EventArgs e) { try { Member member = new Member(); User u = new User(); String unionid = "D" + district_no.Text + "T" + thana_no.Text + "U" + union_no.Text +""; String cncid = "D" + district_no.Text + "T" + thana_no.Text + "U" + union_no.Text + "C" + cncbox.Text + ""; String khanaid = "D" + district_no.Text + "T" + thana_no.Text + "U" + union_no.Text + "C" + cncbox.Text + "K" + khanabox.Text + ""; //MessageBox.Show(khanaid); Khana k = new Khana(); Cnc c = new Cnc (); bool cncexists = c.exist(cncid); if (cncexists == false) { cncexists = c.insert(Convert.ToInt32(cncbox.Text),cncid,unionid); } if (cncexists) { bool inserted = k.Insert( Convert.ToInt32(khanabox.Text), cncid, userid, Convert.ToInt32(chalabox.Text), Convert.ToInt32(wallbox.Text), Convert.ToInt32(floorbox.Text), Convert.ToInt32(watersourcebox.Text), Convert.ToInt32(evaluationbox.Text), Convert.ToInt32(housevaluebox.Text), Convert.ToInt32(totallandbox.Text), Convert.ToInt32(landvaluebox.Text), Convert.ToInt32(cowbox.Text), Convert.ToInt32(goatbox.Text), Convert.ToInt32(henbox.Text), Convert.ToInt32(treebox.Text), Convert.ToInt32(vegitablebox.Text), Convert.ToInt32(monthscoveredbox.Text), Convert.ToInt32(bedbox.Text), Convert.ToInt32(chairbox.Text), Convert.ToInt32(radiobox.Text), Convert.ToInt32(tvbox.Text), Convert.ToInt32(tubewellbox.Text), Convert.ToInt32(gavibox.Text), Convert.ToInt32(sagolbox.Text), Convert.ToInt32(daylabourerbox.Text), Convert.ToInt32(dayslabourbox.Text), Convert.ToInt32(latrinebox.Text), Convert.ToString(datacollectorbox.Text), Convert.ToString(cnocnpbox.Text), Convert.ToString(datebox.Text), khanaid); if (inserted) { //u.increaseKhanaCount(userid); //khanacountbox.Text = u.getKhanaCount(userid).ToString(); int i = dataGridView1.RowCount - 1; // MessageBox.Show(i.ToString()); for (int j = 0; j < i; j++) { int mother = 0; float age = 0; int day = 0, month = 0, year = 0; float weights = 0; int heights = 0; int paritys = 0; int maritalyear=88; String memberid = "D" + district_no.Text + "T" + thana_no.Text + "U" + union_no.Text + "C" + cncbox.Text + "K" + khanabox.Text + "M" + Convert.ToInt32(dataGridView1[0, j].Value) + ""; if (dataGridView1[4, j].Value.ToString().Length > 0) { age = float.Parse(dataGridView1[4, j].Value.ToString()); } String dob = Convert.ToString(dataGridView1[5, j].Value); String[] dobs = dob.Split('/'); if (dobs[0].Length > 0) { day = Convert.ToInt32(dobs[0]); } if (dobs[1].Length > 0) { month = Convert.ToInt32(dobs[1]); } if (dobs[2].Length > 0) { year = Convert.ToInt32(dobs[2]); } if (dataGridView1[8, j].Value.ToString().Length > 0) { maritalyear= Convert.ToInt32(dataGridView1[8, j].Value); } if (dataGridView1[11, j].Value.ToString().Length > 0) { weights = float.Parse(dataGridView1[11, j].Value.ToString()); } if (dataGridView1[12, j].Value.ToString().Length > 0) { heights = Convert.ToInt32(dataGridView1[12, j].Value); } if (dataGridView1[13, j].Value.ToString().Length > 0) { paritys = int.Parse( (dataGridView1[13, j].Value.ToString())); } if (dataGridView1[1, j].Value.ToString().Length > 0) { mother=Convert.ToInt32(dataGridView1[1, j].Value); } if (dobs[2].Length == 4) { if (Math.Abs(24121 - (year * 12 + month)) <= 24) age = age / 12; } if (dobs[2].Length == 2) { if (Math.Abs(121 - (year * 12 + month)) <= 24) age = age / 12; } if (dobs[2].Length == 1) { if (Math.Abs(121 - (year * 12 + month)) <= 24) age = age / 12; } bool Memberinserted = member.Insert( memberid, Convert.ToInt32(dataGridView1[0, j].Value), mother, Convert.ToString(dataGridView1[2, j].Value), Convert.ToInt32(dataGridView1[3, j].Value), age, Convert.ToString(dataGridView1[5, j].Value), Convert.ToInt32(dataGridView1[6, j].Value), Convert.ToInt32(dataGridView1[7, j].Value), maritalyear, Convert.ToInt32(dataGridView1[9, j].Value), weights/10, heights, paritys, Convert.ToInt32(dataGridView1[10, j].Value), khanaid); if (!Memberinserted) { //u.increaseMemberCount(userid); } } khanabox.Clear(); chalabox.Clear(); wallbox.Clear(); floorbox.Clear(); watersourcebox.Clear(); evaluationbox.Clear(); housevaluebox.Clear(); totallandbox.Clear(); landvaluebox.Clear(); cowbox.Clear(); goatbox.Clear(); henbox.Clear(); treebox.Clear(); vegitablebox.Clear(); monthscoveredbox.Clear(); bedbox.Clear(); chairbox.Clear(); radiobox.Clear(); tvbox.Clear(); tubewellbox.Clear(); gavibox.Clear(); sagolbox.Clear(); daylabourerbox.Clear(); dayslabourbox.Clear(); latrinebox.Clear(); datacollectorbox.Clear(); cnocnpbox.Clear(); datebox.Clear(); //membercountbox.Text = u.getMemberCount(userid).ToString(); dataGridView1.Rows.Clear(); khanabox.Select(); i = 0; } } else { k.delete(khanaid); member.delete(khanaid); MessageBox.Show("Please check your inputs again"); } } catch (Exception ex) { editbutton_Click(sender, e); MessageBox.Show("Sorry all data you enter is not saved. \nThe data may not contain all required field . \nPlease re entry not saved information again and click DONE button."); } }
private void save_Click(object sender, EventArgs e) { try { Member member = new Member(); User u = new User(); String cncid = "D" + district_no.Text + "T" + thana_no.Text + "U" + union_no.Text + "C" + cncbox.Text + ""; String khanaid = "D" + district_no.Text + "T" + thana_no.Text + "U" + union_no.Text + "C" + cncbox.Text + "K" + khanabox.Text + ""; //MessageBox.Show(khanaid); Khana k = new Khana(); k.Insert( Convert.ToInt32(khanabox.Text), cncid, userid, Convert.ToInt32(chalabox.Text), Convert.ToInt32(wallbox.Text), Convert.ToInt32(floorbox.Text), Convert.ToInt32(watersourcebox.Text), Convert.ToInt32(evaluationbox.Text), Convert.ToInt32(housevaluebox.Text), Convert.ToInt32(totallandbox.Text), Convert.ToInt32(landvaluebox.Text), Convert.ToInt32(cowbox.Text), Convert.ToInt32(goatbox.Text), Convert.ToInt32(henbox.Text), Convert.ToInt32(treebox.Text), Convert.ToInt32(vegitablebox.Text), Convert.ToInt32(monthscoveredbox.Text), Convert.ToInt32(bedbox.Text), Convert.ToInt32(chairbox.Text), Convert.ToInt32(radiobox.Text), Convert.ToInt32(tvbox.Text), Convert.ToInt32(tubewellbox.Text), Convert.ToInt32(gavibox.Text), Convert.ToInt32(sagolbox.Text), Convert.ToInt32(daylabourerbox.Text), Convert.ToInt32(dayslabourbox.Text), Convert.ToInt32(latrinebox.Text), Convert.ToString(datacollectorbox.Text), Convert.ToString(cnocnpbox.Text), Convert.ToString(datebox.Text), khanaid); u.increaseKhanaCount(userid); khanacountbox.Text = u.getKhanaCount(userid).ToString(); for (int j = 0; j < i; j++) { String memberid = "D" + district_no.Text + "T" + thana_no.Text + "U" + union_no.Text + "C" + cncbox.Text + "K" + khanabox.Text + "M" + Convert.ToInt32(dataGridView1[0, j].Value) + ""; member.Insert( memberid, Convert.ToInt32(dataGridView1[0, j].Value), Convert.ToInt32(dataGridView1[1, j].Value), Convert.ToString(dataGridView1[2, j].Value), Convert.ToInt32(dataGridView1[3, j].Value), Convert.ToInt32(dataGridView1[4, j].Value), Convert.ToString(dataGridView1[5, j].Value), Convert.ToInt32(dataGridView1[6, j].Value), Convert.ToInt32(dataGridView1[7, j].Value), Convert.ToInt32(dataGridView1[8, j].Value), Convert.ToInt32(dataGridView1[9, j].Value), float.Parse(dataGridView1[11, j].Value.ToString()), Convert.ToInt32(dataGridView1[12, j].Value), Convert.ToInt32(dataGridView1[13, j].Value), Convert.ToInt32(dataGridView1[10, j].Value), khanaid); u.increaseMemberCount(userid); membercountbox.Text = u.getMemberCount(userid).ToString(); } khanabox.Clear(); chalabox.Clear(); wallbox.Clear(); floorbox.Clear(); watersourcebox.Clear(); evaluationbox.Clear(); housevaluebox.Clear(); totallandbox.Clear(); landvaluebox.Clear(); cowbox.Clear(); goatbox.Clear(); henbox.Clear(); treebox.Clear(); vegitablebox.Clear(); monthscoveredbox.Clear(); bedbox.Clear(); chairbox.Clear(); radiobox.Clear(); tvbox.Clear(); tubewellbox.Clear(); gavibox.Clear(); sagolbox.Clear(); daylabourerbox.Clear(); dayslabourbox.Clear(); latrinebox.Clear(); datacollectorbox.Clear(); cnocnpbox.Clear(); datebox.Clear(); dataGridView1.Rows.Clear(); i = 0; } catch (Exception ex) { } }