Example #1
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("DATA AKAN DIHAPUS PERMANEN!\nYakin Akan Menghapus Data Ini?", "Hapus Data", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK)
     {
         deleteData();
         Menu      menu = new Menu();
         equipment eq   = new equipment();
         menu.menuClick(eq);
     }
 }
Example #2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Setiap Melakukan Update Data Akan Tercatat di History\nPeriksa Kembali Data yang Anda Masukkan\nApakah Data yang dimasukkan sudah benar?", "Konfirmasi Update", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
            {
                My_Db db = new My_Db();
                db.openConnection();

                //Posisi Alat
                string posisiAlat = "";
                string ket        = "";
                if (comboBoxStatus.SelectedItem.Equals("Cadangan"))
                {
                    posisiAlat = "Office WWT";
                }
                else if (comboBoxStatus.SelectedItem.Equals("Terpasang"))
                {
                    posisiAlat = txtKet.Text;
                }
                else if (comboBoxStatus.SelectedItem.Equals("Rusak"))
                {
                    posisiAlat = "Maintenance"; ket = txtKet.Text;
                }
                else if (comboBoxStatus.SelectedItem.Equals("Dibuang"))
                {
                    posisiAlat = "Dibuang";
                }

                //kondisi alat
                string kondisiAlat;
                if (comboBoxStatus.SelectedItem.Equals("Cadangan") || comboBoxStatus.SelectedItem.Equals("Terpasang"))
                {
                    kondisiAlat = "OK";
                }
                else if (comboBoxStatus.SelectedItem.Equals("Rusak"))
                {
                    kondisiAlat = "Rusak";
                }
                else
                {
                    kondisiAlat = "Dibuang";
                }

                //image
                //byte[] pict;
                //try
                //{
                //    MemoryStream img = new MemoryStream();
                //    boxGambarAlat.Image.Save(img, boxGambarAlat.Image.RawFormat);
                //    pict = img.GetBuffer();
                //}
                //catch
                //{
                //    pict = new byte[0];
                //}

                //history
                SqlCommand getHistory = new SqlCommand("SELECT *FROM [Equipment] WHERE [Kode Alat]=@ko", db.GetConnection);
                getHistory.Parameters.Add("@ko", SqlDbType.VarChar).Value = itemEdit;
                DataTable      history = new DataTable();
                SqlDataAdapter adap    = new SqlDataAdapter(getHistory);
                adap.Fill(history);
                string hstory = history.Rows[0]["History"].ToString() + "\n" + tglPemakaian.Value.ToString("dd-MMM-yyyy");

                if (posisiAlat == "Office WWT")
                {
                    hstory += "  :  Disimpan Sebagai Stok";
                }
                else if (posisiAlat == txtKet.Text)
                {
                    hstory += "  :  Terpasang di" + txtKet.Text;
                }
                else if (posisiAlat == "Maintenance")
                {
                    hstory += "  :  Terjadi Kerusakan ( " + txtKet.Text + " )";
                }
                else
                {
                    hstory += "  :  Alat Dibuang";
                }

                try
                {
                    SqlCommand command = new SqlCommand("UPDATE [Equipment] SET [Kode Alat]=@ko,[Nama Alat]=@na,[Posisi Alat]=@po,[Kondisi Alat]=@ka,[Keterangan]=@ket,[No. NCR]=@ncr,[No. Buang Aktiva Tetap]=@at,[History]=@hi WHERE [Kode Alat]=@kode", db.GetConnection);
                    command.Parameters.AddWithValue("@kode", itemEdit);
                    command.Parameters.AddWithValue("@ko", txtKode.Text);
                    command.Parameters.AddWithValue("@na", txtNama.Text);
                    if (posisiAlat == "")
                    {
                        command.Parameters.AddWithValue("@po", "Terpasang");
                    }
                    else
                    {
                        command.Parameters.AddWithValue("@po", posisiAlat);
                    }
                    command.Parameters.AddWithValue("@ka", kondisiAlat);
                    command.Parameters.AddWithValue("@ket", ket);
                    command.Parameters.AddWithValue("@ncr", txtNCR.Text);
                    command.Parameters.AddWithValue("@at", txtNoBuang.Text);
                    //command.Parameters.AddWithValue("@im", pict);
                    command.Parameters.AddWithValue("@hi", hstory);
                    command.ExecuteScalar();

                    db.closeConnection();
                    if (MessageBox.Show("Data Berhasil diupdate.", "Update Data Berhasil", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
                    {
                        equipment eq   = new equipment();
                        Menu      menu = new Menu();
                        menu.menuClick(eq);
                    }
                }
                catch
                {
                    db.closeConnection();
                    MessageBox.Show("Gagal Update Data!\nMohon periksa kembali data yang anda masukkan", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }