コード例 #1
0
        private void buttonPelanggan_Click(object sender, EventArgs e)
        {
            CariPelanggan form = new CariPelanggan();

            form.ParentForm = this;
            form.ShowDialog();
        }
コード例 #2
0
        private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                int  kodePelanggan;
                bool IsValidKodePelanggan = int.TryParse(textBoxKodePelanggan.Text, out kodePelanggan);

                float diskon;

                var pelanggan = pelangganService.Get(kodePelanggan);

                if (pelanggan != null)
                {
                    diskon = pelanggan.Member.Diskon;
                }
                else
                {
                    diskon = 0;
                }

                int    row = dataGridViewTransaksiPenjualan.Rows.Count;
                string id  = dataGridViewTransaksiPenjualan[0, row - 1].Value.ToString();

                var barang = service.FindByKodeBarang(id);

                if (barang == null)
                {
                    MessageBox.Show("Tidak ada barang dengan ID tersebut", "Pesan", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                var stockBarang = shuService.FindByBarangId(barang.Id);

                bool IsHabis = true;
                foreach (var d in stockBarang)
                {
                    if (d.Stock > 0)
                    {
                        IsHabis = false;
                        break;
                    }
                }

                if (IsHabis)
                {
                    MessageBox.Show("Stok barang habis", "Pesan", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }


                dataGridViewTransaksiPenjualan.Rows[row - 1].Cells[0].Value = barang.KodeBarang;
                dataGridViewTransaksiPenjualan.Rows[row - 1].Cells[1].Value = barang.NamaBarang;

                List <StokHargaUkuran>   shus = shuService.FindByBarangId(barang.Id);
                DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell();
                cell.DataSource    = shus;
                cell.DisplayMember = "Ukuran";
                cell.ValueMember   = "Ukuran";

                dataGridViewTransaksiPenjualan.Rows[row - 1].Cells[2]       = cell;
                dataGridViewTransaksiPenjualan.Rows[row - 1].Cells[3].Value = 1;

                //dataGridViewTransaksiPenjualan.Rows[row - 1].Cells[3].Value = barang.HargaJual.ToString("N2", CultureInfo.GetCultureInfo("de"));
                dataGridViewTransaksiPenjualan.Rows[row - 1].Cells[5].Value = diskon;
                //dataGridViewTransaksiPenjualan.Rows[row - 1].Cells[5].Value = (barang.HargaJual - (barang.HargaJual * (decimal) (diskon/100) )).ToString("N2", CultureInfo.GetCultureInfo("de"));

                dataGridViewTransaksiPenjualan.Rows.Add("", "", "", "");
            }

            if (e.KeyCode == Keys.F12)
            {
                int  kodePelanggan;
                bool IsValidKodePelanggan = int.TryParse(textBoxKodePelanggan.Text, out kodePelanggan);

                float diskon;

                var pelanggan = pelangganService.Get(kodePelanggan);

                if (pelanggan != null)
                {
                    diskon = pelanggan.Member.Diskon;
                }
                else
                {
                    diskon = 0;
                }

                int row             = dataGridViewTransaksiPenjualan.Rows.Count;
                int currentRowIndex = dataGridViewTransaksiPenjualan.CurrentCell.RowIndex;

                if (row < 2 || currentRowIndex == row - 1)
                {
                    return;
                }

                if (dataGridViewTransaksiPenjualan.Rows[currentRowIndex].Cells[4].Value == null)
                {
                    MessageBox.Show("Silahkan pilih ukuran", "Pesan", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                int n = int.Parse(dataGridViewTransaksiPenjualan.Rows[currentRowIndex].Cells[3].Value.ToString());

                string id = dataGridViewTransaksiPenjualan[0, currentRowIndex].Value.ToString();

                var    barang = service.FindByKodeBarang(id);
                string ukuran = (dataGridViewTransaksiPenjualan.Rows[currentRowIndex].Cells[2] as DataGridViewComboBoxCell).FormattedValue.ToString();
                var    shu    = shuService.FindByBarangIdAndUkuran(barang.Id, ukuran);

                if ((n + 1) > shu.Stock)
                {
                    MessageBox.Show("Stok barang tidak memadahi", "Pesan", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                dataGridViewTransaksiPenjualan.Rows[currentRowIndex].Cells[3].Value = n + 1;

                n = int.Parse(dataGridViewTransaksiPenjualan.Rows[currentRowIndex].Cells[3].Value.ToString());
                decimal price = decimal.Parse(dataGridViewTransaksiPenjualan.Rows[currentRowIndex].Cells[4].Value.ToString(), NumberStyles.Number, CultureInfo.GetCultureInfo("de"));
                dataGridViewTransaksiPenjualan.Rows[currentRowIndex].Cells[6].Value = ((price - (price * (decimal)(diskon / 100))) * n).ToString("N2", CultureInfo.GetCultureInfo("de"));

                decimal total = 0;
                for (int i = 0; i < row - 1; i++)
                {
                    total += decimal.Parse(dataGridViewTransaksiPenjualan.Rows[i].Cells[6].Value.ToString(), NumberStyles.Number, CultureInfo.GetCultureInfo("de"));
                }

                labelTotal.Text     = total.ToString("N2", CultureInfo.GetCultureInfo("de"));
                labelTerbilang.Text = Terbilang.Bilang(total) + " Rupiah";

                dataGridViewTransaksiPenjualan.Refresh();
            }

            if (e.KeyCode == Keys.F11)
            {
                int  kodePelanggan;
                bool IsValidKodePelanggan = int.TryParse(textBoxKodePelanggan.Text, out kodePelanggan);

                float diskon;

                var pelanggan = pelangganService.Get(kodePelanggan);

                if (pelanggan != null)
                {
                    diskon = pelanggan.Member.Diskon;
                }
                else
                {
                    diskon = 0;
                }

                int row             = dataGridViewTransaksiPenjualan.Rows.Count;
                int currentRowIndex = dataGridViewTransaksiPenjualan.CurrentCell.RowIndex;

                if (row < 2 || currentRowIndex == row - 1)
                {
                    return;
                }

                int n = int.Parse(dataGridViewTransaksiPenjualan.Rows[currentRowIndex].Cells[3].Value.ToString());

                if (n == 1)
                {
                    return;
                }

                dataGridViewTransaksiPenjualan.Rows[currentRowIndex].Cells[3].Value = n - 1;

                n = int.Parse(dataGridViewTransaksiPenjualan.Rows[currentRowIndex].Cells[3].Value.ToString());
                decimal price = decimal.Parse(dataGridViewTransaksiPenjualan.Rows[currentRowIndex].Cells[4].Value.ToString(), NumberStyles.Number, CultureInfo.GetCultureInfo("de"));
                dataGridViewTransaksiPenjualan.Rows[currentRowIndex].Cells[6].Value = ((price - (price * (decimal)(diskon / 100))) * n).ToString("N2", CultureInfo.GetCultureInfo("de"));

                decimal total = 0;
                for (int i = 0; i < row - 1; i++)
                {
                    total += decimal.Parse(dataGridViewTransaksiPenjualan.Rows[i].Cells[6].Value.ToString(), NumberStyles.Number, CultureInfo.GetCultureInfo("de"));
                }

                labelTotal.Text     = total.ToString("N2", CultureInfo.GetCultureInfo("de"));
                labelTerbilang.Text = Terbilang.Bilang(total) + " Rupiah";

                dataGridViewTransaksiPenjualan.Refresh();
            }

            if (e.KeyCode == Keys.Delete)
            {
                //EMANG KOMEN
                //MessageBox.Show(dataGridViewTransaksiPenjualan.CurrentCell.RowIndex.ToString());
                //return;

                int row             = dataGridViewTransaksiPenjualan.Rows.Count;
                int currentRowIndex = dataGridViewTransaksiPenjualan.CurrentCell.RowIndex;

                if (row > 1 && currentRowIndex != row - 1)
                {
                    dataGridViewTransaksiPenjualan.Rows.RemoveAt(currentRowIndex);
                    //EMANG KOMEN
                    //dataGridViewTransaksiPenjualan.Rows.RemoveAt(row - 2);
                    //dataGridViewTransaksiPenjualan.Rows.Add();
                }

                decimal total = 0;
                row = dataGridViewTransaksiPenjualan.Rows.Count;

                dataGridViewTransaksiPenjualan.CurrentCell = dataGridViewTransaksiPenjualan.Rows[row - 1].Cells[0];

                for (int i = 0; i < row - 1; i++)
                {
                    total += decimal.Parse(dataGridViewTransaksiPenjualan.Rows[i].Cells[6].Value.ToString(), NumberStyles.Number, CultureInfo.GetCultureInfo("de"));
                }

                labelTotal.Text     = total.ToString("N2", CultureInfo.GetCultureInfo("de"));
                labelTerbilang.Text = Terbilang.Bilang(total) + " Rupiah";

                dataGridViewTransaksiPenjualan.Refresh();
            }

            if (e.KeyCode == Keys.F8)
            {
                int row             = dataGridViewTransaksiPenjualan.Rows.Count;
                int currentRowIndex = dataGridViewTransaksiPenjualan.CurrentCell.RowIndex;

                if (row < 2 || currentRowIndex == row - 1)
                {
                    MessageBox.Show("Tidak ada barang yang dipilih", "Pesan", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                ApplyHarga form = new ApplyHarga();
                form.ParentForm = this;
                form.ShowDialog();
            }

            //NO LONGER
            //if (e.KeyCode == Keys.F5)
            //{
            //    Pembayaran form = new Pembayaran();
            //    form.ParentForm = this;
            //    form.PopulateData();
            //    form.ShowDialog();
            //}

            if (e.KeyCode == Keys.F6)
            {
                CariPelanggan form = new CariPelanggan();
                form.ParentForm = this;
                form.ShowDialog();
            }

            if (e.KeyCode == Keys.F7)
            {
                CariBarang form = new CariBarang();
                form.ParentForm = this;
                form.ShowDialog();
            }
        }