Exemple #1
0
        private void cmdDelete_Click(object sender, EventArgs e)
        {
            try
            {
                DateTime tgl       = ((DateTime)gridBBM.SelectedCells[0].OwningRow.Cells["TglBBM"].Value).Date;
                DateTime tglServer = GlobalVar.DateOfServer.Date;

                if (tgl != tglServer)
                {
                    MessageBox.Show("Tanggal server tidak sama dengan tanggal transaksi. Tidak bisa hapus transaksi");
                    return;
                }

                switch (selectedGrid)
                {
                case enumSelectedGrid.DetailSelected:

                    if (gridGiro.SelectedCells.Count > 0)
                    {
                        DateTime _Tanggal = (DateTime)gridBBM.SelectedCells[0].OwningRow.Cells["TglBBM"].Value;
                        if (PeriodeClosing.IsKasirClosed(_Tanggal))
                        {
                            MessageBox.Show("Sudah Closing!");
                            return;
                        }
                        if (!SecurityManager.IsManager())
                        {
                            MessageBox.Show("Hapus hanya boleh dilakukan oleh Manager");
                            return;
                        }
                        Guid rowIDBBM = (Guid)gridBBM.SelectedCells[0].OwningRow.Cells["RowID"].Value;
                        Guid giroID   = (Guid)gridGiro.SelectedCells[0].OwningRow.Cells["RowIDGiro"].Value;

                        if (MessageBox.Show("Data Ini Akan Dihapus?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            DeleteGiroCairTolakBatal(rowIDBBM, giroID);

                            RefreshBBM(rowIDBBM);

                            #region "Tambahan"
                            int i = 0;
                            int n = 0;
                            i = gridGiro.SelectedCells[0].RowIndex;
                            n = gridGiro.SelectedCells[0].ColumnIndex;
                            DataRowView dv = (DataRowView)gridGiro.SelectedCells[0].OwningRow.DataBoundItem;

                            DataRow dr = dv.Row;

                            dr.Delete();
                            _dtDetail.AcceptChanges();
                            gridGiro.Focus();
                            gridGiro.RefreshEdit();
                            if (gridGiro.RowCount > 0)
                            {
                                if (i == 0)
                                {
                                    gridGiro.CurrentCell = gridGiro.Rows[0].Cells[n];
                                    gridGiro.RefreshEdit();
                                }
                                else
                                {
                                    gridGiro.CurrentCell = gridGiro.Rows[i - 1].Cells[n];
                                    gridGiro.RefreshEdit();
                                }
                            }
                            #endregion
                        }
                    }

                    break;

                case enumSelectedGrid.HeaderSelected:
                    if (gridBBM.SelectedCells.Count > 0)
                    {
                        DateTime _Tanggal = (DateTime)gridBBM.SelectedCells[0].OwningRow.Cells["TglBBM"].Value;
                        if (PeriodeClosing.IsKasirClosed(_Tanggal))
                        {
                            MessageBox.Show("Sudah Closing!");
                            return;
                        }
                        Guid rowIDBBM = (Guid)gridBBM.SelectedCells[0].OwningRow.Cells["RowID"].Value;
                        //if ((int)_dtDetail.Compute("count(Nomor)", "") > 0)
                        //{
                        //    MessageBox.Show("Masih ada detail");
                        //    return;
                        //}

                        if (gridGiro.SelectedCells.Count > 0)
                        {
                            MessageBox.Show("Sudah ada record di detail, tidak bisa hapus record. Silahkan hapus record detail terlebih dahulu");
                            return;
                        }

                        if (!SecurityManager.IsManager())
                        {
                            MessageBox.Show("Hapus hanya boleh dilakukan oleh Manager");
                            return;
                        }

                        if (MessageBox.Show("Data Ini Akan Dihapus?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            try
                            {
                                using (Database db = new Database(GlobalVar.DBFinance))
                                {
                                    BBM.DeleteBBM(db, rowIDBBM);
                                }



                                #region "Tambahan"
                                int i = 0;
                                int n = 0;
                                i = gridBBM.SelectedCells[0].RowIndex;
                                n = gridBBM.SelectedCells[0].ColumnIndex;
                                DataRowView dv = (DataRowView)gridBBM.SelectedCells[0].OwningRow.DataBoundItem;

                                DataRow dr = dv.Row;

                                dr.Delete();
                                _dtHeader.AcceptChanges();
                                gridBBM.Focus();
                                gridBBM.RefreshEdit();
                                if (gridBBM.RowCount > 0)
                                {
                                    if (i == 0)
                                    {
                                        gridBBM.CurrentCell = gridBBM.Rows[0].Cells[n];
                                        gridBBM.RefreshEdit();
                                    }
                                    else
                                    {
                                        gridBBM.CurrentCell = gridBBM.Rows[i - 1].Cells[n];
                                        gridBBM.RefreshEdit();
                                    }
                                }
                                #endregion
                            }
                            catch (Exception ex)
                            {
                                Error.LogError(ex);
                            }
                        }
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #2
0
        private void cmdDelete_Click(object sender, EventArgs e)
        {
            switch (selectedGrid)
            {
            case enumSelectedGrid.DetailSelected:

                if (gridGiro.SelectedCells.Count > 0)
                {
                    DateTime _Tanggal = (DateTime)gridBBM.SelectedCells[0].OwningRow.Cells["TglBBM"].Value;
                    if (GlobalVar.Gudang != "2808")
                    {
                        if (PeriodeClosing.IsKasirClosed(_Tanggal))
                        {
                            MessageBox.Show("Sudah Closing!");
                            return;
                        }
                    }

                    Guid rowIDBBM = (Guid)gridBBM.SelectedCells[0].OwningRow.Cells["RowID"].Value;
                    Guid giroID   = (Guid)gridGiro.SelectedCells[0].OwningRow.Cells["RowIDGiro"].Value;

                    if (MessageBox.Show("Data Ini Akan Dihapus?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        DeleteGiroCairTolakBatal(rowIDBBM, giroID);

                        RefreshBBM(rowIDBBM);

                        #region "Tambahan"
                        int i = 0;
                        int n = 0;
                        i = gridGiro.SelectedCells[0].RowIndex;
                        n = gridGiro.SelectedCells[0].ColumnIndex;
                        DataRowView dv = (DataRowView)gridGiro.SelectedCells[0].OwningRow.DataBoundItem;

                        DataRow dr = dv.Row;

                        dr.Delete();
                        _dtDetail.AcceptChanges();
                        gridGiro.Focus();
                        gridGiro.RefreshEdit();
                        if (gridGiro.RowCount > 0)
                        {
                            if (i == 0)
                            {
                                gridGiro.CurrentCell = gridGiro.Rows[0].Cells[n];
                                gridGiro.RefreshEdit();
                            }
                            else
                            {
                                gridGiro.CurrentCell = gridGiro.Rows[i - 1].Cells[n];
                                gridGiro.RefreshEdit();
                            }
                        }
                        #endregion
                    }
                }

                break;

            case enumSelectedGrid.HeaderSelected:
                if (gridBBM.SelectedCells.Count > 0)
                {
                    DateTime _Tanggal = (DateTime)gridBBM.SelectedCells[0].OwningRow.Cells["TglBBM"].Value;
                    if (GlobalVar.Gudang != "2808")
                    {
                        if (PeriodeClosing.IsKasirClosed(_Tanggal))
                        {
                            MessageBox.Show("Sudah Closing!");
                            return;
                        }
                    }

                    Guid rowIDBBM = (Guid)gridBBM.SelectedCells[0].OwningRow.Cells["RowID"].Value;
                    if ((int)_dtDetail.Compute("count(Nomor)", "") > 0)
                    {
                        MessageBox.Show("Masih ada detail");
                        return;
                    }

                    if (MessageBox.Show("Data Ini Akan Dihapus?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        try
                        {
                            using (Database db = new Database(GlobalVar.DBName))
                            {
                                BBM.DeleteBBM(db, rowIDBBM);
                            }



                            #region "Tambahan"
                            int i = 0;
                            int n = 0;
                            i = gridBBM.SelectedCells[0].RowIndex;
                            n = gridBBM.SelectedCells[0].ColumnIndex;
                            DataRowView dv = (DataRowView)gridBBM.SelectedCells[0].OwningRow.DataBoundItem;

                            DataRow dr = dv.Row;

                            dr.Delete();
                            _dtHeader.AcceptChanges();
                            gridBBM.Focus();
                            gridBBM.RefreshEdit();
                            if (gridBBM.RowCount > 0)
                            {
                                if (i == 0)
                                {
                                    gridBBM.CurrentCell = gridBBM.Rows[0].Cells[n];
                                    gridBBM.RefreshEdit();
                                }
                                else
                                {
                                    gridBBM.CurrentCell = gridBBM.Rows[i - 1].Cells[n];
                                    gridBBM.RefreshEdit();
                                }
                            }
                            #endregion
                        }
                        catch (Exception ex)
                        {
                            Error.LogError(ex);
                        }
                    }
                }
                break;
            }
        }