Exemple #1
0
 private void frmPemasokUpdate_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (this.DialogResult == DialogResult.OK)
     {
         if (this.Caller is frmPemasokBrowse)
         {
             frmPemasokBrowse frmCaller = (frmPemasokBrowse)this.Caller;
             frmCaller.RefreshData();
             frmCaller.FindRow("PemasokID", txtPemasokID.Text);
         }
     }
 }
Exemple #2
0
        private void cmdSave_Click(object sender, EventArgs e)
        {
            //if (string.IsNullOrEmpty(txtPemasokID.Text))
            //{
            //    MessageBox.Show("Kode belum diisi");
            //    txtPemasokID.Focus();
            //    return;
            //}

            if (string.IsNullOrEmpty(txtNama.Text))
            {
                MessageBox.Show("Nama belum diisi");
                txtNama.Focus();
                return;
            }

            try
            {
                switch (formMode)
                {
                case enumFormMode.New:
                    try
                    {
                        using (Database db = new Database())
                        {
                            db.Open();

                            DataTable dtMessage = new DataTable();
                            db.Commands.Add(db.CreateCommand("usp_Pemasok_INSERT"));

                            db.Commands[0].Parameters.Add(new Parameter("@Nama", SqlDbType.VarChar, txtNama.Text));
                            db.Commands[0].Parameters.Add(new Parameter("@Lengkap", SqlDbType.VarChar, txtLengkap.Text));
                            db.Commands[0].Parameters.Add(new Parameter("@Alamat", SqlDbType.VarChar, txtAlamat.Text));
                            db.Commands[0].Parameters.Add(new Parameter("@Kota", SqlDbType.VarChar, txtKota.Text));
                            db.Commands[0].Parameters.Add(new Parameter("@Telp", SqlDbType.VarChar, txtTelp.Text));
                            db.Commands[0].Parameters.Add(new Parameter("@Fax", SqlDbType.VarChar, txtFax.Text));
                            db.Commands[0].Parameters.Add(new Parameter("@Kontak", SqlDbType.VarChar, txtKontrak.Text));
                            db.Commands[0].Parameters.Add(new Parameter("@Keterangan", SqlDbType.VarChar, txtKeterangan.Text));
                            db.Commands[0].Parameters.Add(new Parameter("@Salesman", SqlDbType.VarChar, txtSalesman.Text));
                            db.Commands[0].Parameters.Add(new Parameter("@HPSalesman", SqlDbType.VarChar, txtHPSelesman.Text));
                            db.Commands[0].Parameters.Add(new Parameter("@EmailOrder", SqlDbType.Char, txtEmailOrder.Text));
                            db.Commands[0].Parameters.Add(new Parameter("@StatusAktif", SqlDbType.Bit, rbAktif.Checked == true ? 1:0));
                            db.Commands[0].Parameters.Add(new Parameter("@SyncFlag", SqlDbType.Bit, 0));
                            db.Commands[0].Parameters.Add(new Parameter("@LastUpdatedBy", SqlDbType.VarChar, SecurityManager.UserID));
                            dtMessage = db.Commands[0].ExecuteDataTable();

                            db.Close();
                            db.Dispose();

                            if (dtMessage.Rows.Count > 0)
                            {
                                if (dtMessage.Rows[0]["pesan"].ToString() == "Insert Berhasil")
                                {
                                    this.DialogResult = DialogResult.OK;
                                    this.Close();
                                }
                                else
                                {
                                    MessageBox.Show(dtMessage.Rows[0]["pesan"].ToString()); return;
                                }
                                //if (dt.Rows[0]["pesan"].ToString() == "Data Sudah Ada")
                                //{
                                //    txtKode.Text = string.Empty;
                                //    txtKode.Focus();
                                //    return;
                                //}
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Error.LogError(ex);
                    }

                    break;

                case enumFormMode.Update:
                    try
                    {
                        using (Database db = new Database())
                        {
                            if (Tools.cekDuplikasiDataOnDatabase("Pemasok", "Nama", txtNama.Text, "PemasokID", txtPemasokID.Text))
                            {
                                MessageBox.Show("Pemasok Dengan Nama " + txtNama.Text + " Sudah Ada !!");
                                txtNama.Focus();
                                return;
                            }
                            db.Open();

                            DataTable dt = new DataTable();
                            db.Commands.Add(db.CreateCommand("usp_Pemasok_UPDATE"));
                            db.Commands[0].Parameters.Add(new Parameter("@RowID", SqlDbType.UniqueIdentifier, RowID));
                            db.Commands[0].Parameters.Add(new Parameter("@PemasokID", SqlDbType.VarChar, _rowID));
                            db.Commands[0].Parameters.Add(new Parameter("@Nama", SqlDbType.VarChar, txtNama.Text));
                            db.Commands[0].Parameters.Add(new Parameter("@Lengkap", SqlDbType.VarChar, txtLengkap.Text));
                            db.Commands[0].Parameters.Add(new Parameter("@Alamat", SqlDbType.VarChar, txtAlamat.Text));
                            db.Commands[0].Parameters.Add(new Parameter("@Kota", SqlDbType.VarChar, txtKota.Text));
                            db.Commands[0].Parameters.Add(new Parameter("@Telp", SqlDbType.VarChar, txtTelp.Text));
                            db.Commands[0].Parameters.Add(new Parameter("@Fax", SqlDbType.VarChar, txtFax.Text));
                            db.Commands[0].Parameters.Add(new Parameter("@Kontak", SqlDbType.VarChar, txtKontrak.Text));
                            db.Commands[0].Parameters.Add(new Parameter("@Keterangan", SqlDbType.VarChar, txtKeterangan.Text));
                            db.Commands[0].Parameters.Add(new Parameter("@Salesman", SqlDbType.VarChar, txtSalesman.Text));
                            db.Commands[0].Parameters.Add(new Parameter("@HPSalesman", SqlDbType.VarChar, txtHPSelesman.Text));
                            db.Commands[0].Parameters.Add(new Parameter("@EmailOrder", SqlDbType.Char, txtEmailOrder.Text));
                            db.Commands[0].Parameters.Add(new Parameter("@StatusAktif", SqlDbType.Bit, rbAktif.Checked == true ? 1 : 0));
                            db.Commands[0].Parameters.Add(new Parameter("@SyncFlag", SqlDbType.Bit, 0));
                            db.Commands[0].Parameters.Add(new Parameter("@LastUpdatedBy", SqlDbType.VarChar, SecurityManager.UserID));
                            db.Commands[0].ExecuteNonQuery();

                            db.Close();
                            db.Dispose();
                            this.DialogResult = DialogResult.OK;
                            frmPemasokBrowse frmCaller = (frmPemasokBrowse)this.Caller;
                            frmCaller.RefreshData();
                            this.Close();
                            frmCaller.Show();
                        }
                    }

                    catch (Exception ex)
                    {
                        Error.LogError(ex);
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                Error.LogError(ex);
            }
        }