private void SaveLeave_Click(object sender, EventArgs e) { string query = ""; int TypeKey = ((KeyValuePair <int, string>)LeaveaTypeCombo.SelectedItem).Key; String TypeValue = ((KeyValuePair <int, string>)LeaveaTypeCombo.SelectedItem).Value; if (StaffID.Text.Trim() == "") { MessageBox.Show("Please Enter Staff ID"); StaffID.Focus(); return; } if (TypeKey < 1) { MessageBox.Show("Please Enter Leave Type"); LeaveaTypeCombo.Focus(); return; } if (DateFrom.Text == "") { MessageBox.Show("Please Enter Date From"); DateFrom.Focus(); return; } if (DateTo.Text.Trim() == "") { MessageBox.Show("Please Enter Date To"); DateTo.Focus(); return; } if (TotalLeave.Text.Trim() == "") { TotalLeave.Focus(); return; } else { if (!IsValid(TypeKey, TypeValue, Convert.ToInt32(TotalLeave.Text))) { MessageBox.Show("You can not apply for more than ur assigned leave!!!"); return; } } try { if (hiddenText.Text == "") { query = "INSERT INTO LeaveApply_Info(StaffID,Type,Datefrom,DateTo,Total) VALUES(" + Convert.ToInt32(StaffID.Text) + ", '" + TypeValue + "', '" + DateFrom.Value.ToString("yyyy/MM/dd") + "', '" + DateTo.Value.ToString("yyyy/MM/dd") + "', '" + TotalLeave.Text + "' )"; } else { query = "UPDATE LeaveApply_Info SET Type = '" + TypeValue + "', Datefrom= '" + DateFrom.Value.ToString("yyyy/MM/dd") + "',DateTo = '" + DateTo.Value.ToString("yyyy/MM/dd") + "', Total = '" + TotalLeave.Text + "' WHERE Id = " + Convert.ToInt32(hiddenText.Text); } if (DbAccess.ExecuteToDB(query)) { if (hiddenText.Text == "") { MessageBox.Show("Saved Successfully!!!"); } else { MessageBox.Show("Updated Successfully!!!"); } } else { MessageBox.Show("Failed To Save!!!"); } } catch (Exception ex) { MessageBox.Show("Connection Error!!!"); } finally { Reset(); } }