private void frmSopirUpdate_FormClosed(object sender, FormClosedEventArgs e) { if (this.DialogResult == DialogResult.OK) { if (this.Caller is frmSopirBrowse) { frmSopirBrowse frmCaller = (frmSopirBrowse)this.Caller; frmCaller.RefreshData(); frmCaller.FindRow("Nama", txtNama.Text); } } }
private void cmdSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtNama.Text)) { MessageBox.Show("Nama sopir belum diisi"); txtNama.Focus(); return; } if (string.IsNullOrEmpty(cboSp.Text)) { MessageBox.Show("Sopir/Kernet belum diisi"); cboSp.Focus(); return; } try { switch (formMode) { case enumFormMode.NEW: using (Database db = new Database()) { db.Open(); DataTable dt = new DataTable(); db.Commands.Add(db.CreateCommand("usp_Sopir_INSERT")); db.Commands[0].Parameters.Add(new Parameter("@nama", SqlDbType.VarChar, txtNama.Text)); db.Commands[0].Parameters.Add(new Parameter("@sk", SqlDbType.VarChar, cboSp.SelectedItem)); db.Commands[0].Parameters.Add(new Parameter("@lastUpdatedBy", SqlDbType.VarChar, SecurityManager.UserID)); dt = db.Commands[0].ExecuteDataTable(); db.Close(); db.Dispose(); if (dt.Rows.Count > 0) { MessageBox.Show("Sopir: " + txtNama.Text + " sudah terdaftar"); txtNama.Text = string.Empty; txtNama.Focus(); return; } } break; case enumFormMode.UPDATE: using (Database db = new Database()) { db.Open(); DataTable dt = new DataTable(); db.Commands.Add(db.CreateCommand("usp_Sopir_UPDATE")); db.Commands[0].Parameters.Add(new Parameter("@tampNama", SqlDbType.VarChar, tampNama)); db.Commands[0].Parameters.Add(new Parameter("@nama", SqlDbType.VarChar, txtNama.Text)); db.Commands[0].Parameters.Add(new Parameter("@sk", SqlDbType.VarChar, cboSp.SelectedItem)); db.Commands[0].Parameters.Add(new Parameter("@lastUpdatedBy", SqlDbType.VarChar, SecurityManager.UserID)); db.Commands[0].ExecuteNonQuery(); db.Close(); db.Dispose(); } break; } this.DialogResult = DialogResult.OK; frmSopirBrowse frmcaller = (frmSopirBrowse)this.Caller; frmcaller.RefreshData(); this.Close(); frmcaller.Show(); } catch (Exception ex) { Error.LogError(ex); } }