Beispiel #1
0
        private void cmdDELETE_Click(object sender, EventArgs e)
        {
            DateTimeFormatInfo dfi  = DateTimeFormatInfo.CurrentInfo;
            DateTime           date = GlobalVar.GetServerDate;
            Calendar           cal  = dfi.Calendar;
            int mingguKe            = cal.GetWeekOfYear(date, dfi.CalendarWeekRule, dfi.FirstDayOfWeek);

            if (dataGridView1.SelectedCells.Count > 0)
            {
                string namacustomer = dataGridView1.SelectedCells[0].OwningRow.Cells["Nama"].Value.ToString();
                Guid   rowID        = (Guid)dataGridView1.SelectedCells[0].OwningRow.Cells["RowID"].Value;
                if (MessageBox.Show(Messages.Question.AskDelete, "Anda yakin akan menghapus data ini ?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    try
                    {
                        DataTable dtSales = FillComboBox.DBGetTargetSales(Guid.Empty, rowID);
                        if (dtSales.Rows.Count > 0)
                        {
                            MessageBox.Show("Terdapat keterkaitan data !");
                            return;
                        }
                        else
                        {                                                                 // pake cekDelete punya Pak Novi
                            if (Class.PenerimaanUang.checkDelete(rowID, "Sales") == true) // this.ceckDelete(rowID) == true -> ke Sales
                            {
                                Tools.pin(PinId.Periode.Hari, mingguKe, date, PinId.Bagian.Piutang, Convert.ToInt32(PinId.ModulId.HapusMaster), "Hapus Master.\nSudah lewat tanggal, tidak diperkenankan menghapus data ini !");
                                if (GlobalVar.pinResult == false)
                                {
                                    return;
                                }
                            }

                            using (Database db = new Database())
                            {
                                DataTable dt = new DataTable();
                                db.Commands.Add(db.CreateCommand("usp_Sales_DELETE"));
                                db.Commands[0].Parameters.Add(new Parameter("@RowID", SqlDbType.UniqueIdentifier, rowID));
                                dt = db.Commands[0].ExecuteDataTable();
                            }

                            dataGridView1.Rows.Remove(dataGridView1.SelectedCells[0].OwningRow);
                            MessageBox.Show("Data berhasil dihapus");
                        }
                    }
                    catch (Exception ex)
                    {
                        Error.LogError(ex);
                    }
                }
            }
            else
            {
                MessageBox.Show(Messages.Error.RowNotSelected);
            }
        }