Beispiel #1
0
        private void btnSimpan_Click(object sender, EventArgs e)
        {
            if (WithErrors())
            {
                val.validateTextBox(txtNoIdentitas, errorProvider1, "No identitas harus terisi.");
                val.validateTextBox(txtNama, errorProvider1, "Nama harus terisi.");
                val.validateTextBox(txtTelp, errorProvider1, "Telp harus terisi.");
                val.validateTextBox(txtJmlPenumpang, errorProvider1, "Jumlah penumpang harus terisi.");
                val.validateTextBox(txtOngkos, errorProvider1, "Ongkos harus terisi.");
                val.validateTextBox(txtDibayar, errorProvider1, "Dibayar harus terisi.");
            }
            else
            {
                int cnt = 0;
                int av = 0;
                int booked = 0;
                IsFirstTime = false;
                int trxId;
                val.validateReset(errorProvider1);

                var qry = (from a in context.TRX_PENJUALANs
                           where a.ID_JADWAL == Convert.ToInt32(txtIdJadwal.Text)
                           select new {a.QTY_PENUMPANG}).ToList();
                booked = Convert.ToInt32(qry.Select(b => b.QTY_PENUMPANG).Sum());
                cnt = booked + Convert.ToInt32(txtJmlPenumpang.Text);
                av = max - booked;
                if (cnt <= max)
                {
                    var jual = new TRX_PENJUALAN();
                    jual.TGL_PENJUALAN = DateTime.Now;
                    jual.ID_KONSUMEN = Convert.ToInt32(txtIdKonsumen.Text);
                    jual.ID_JADWAL = Convert.ToInt32(cbJadwal.SelectedValue);
                    jual.QTY_PENUMPANG = Convert.ToInt32(txtJmlPenumpang.Text);
                    jual.ONGKOS = Convert.ToDecimal(txtOngkos.Text);
                    jual.JUMLAH = Convert.ToDecimal(txtJumlah.Text);
                    jual.DP = Convert.ToDecimal(txtDibayar.Text);
                    jual.SISA = Convert.ToDecimal(txtSisa.Text);
                    if (rbUloYa.Checked)
                        jual.ID_KOMISI = 2;
                    else
                        jual.ID_KOMISI = 1;
                    context.TRX_PENJUALANs.InsertOnSubmit(jual);
                    context.SubmitChanges();
                    int currentId = jual.ID_PENJUALAN;

                    string[] seat = seatCol.Split(',');

                    for (int i = 0; i < seat.Count() - 1; i++)
                    {
                        var detail = new TRX_PENJUALAN_DETAIL();
                        detail.ID_PENJUALAN = currentId;
                        detail.NAMA_PENUMPANG = txtNama.Text;
                        detail.NO_KURSI = Convert.ToInt32(seat[i]);
                        context.TRX_PENJUALAN_DETAILs.InsertOnSubmit(detail);
                        context.SubmitChanges();
                    }

                    var histori = new TRX_HISTORI_TRANSAKSI();
                    Random rdm = new Random();
                    histori.NO_TRANSAKSI = rdm.Next(100000000, 999999999).ToString();
                    histori.TGL = DateTime.Now;
                    histori.JML_TAGIH = Convert.ToDecimal(txtJumlah.Text);
                    histori.DIBAYAR = Convert.ToDecimal(txtDibayar.Text);
                    histori.SISA = Convert.ToDecimal(txtSisa.Text);
                    histori.ID_PENJUALAN = currentId;
                    context.TRX_HISTORI_TRANSAKSIs.InsertOnSubmit(histori);
                    context.SubmitChanges();
                    trxId = histori.ID_TRANSAKSI;
                    //trxId = 2;

                    string query =
                        "SELECT ID_PENJUALAN_DETAIL, ID_PENJUALAN, NAMA_PENUMPANG, NO_KURSI FROM TRX_PENJUALAN_DETAIL " +
                        "WHERE ID_PENJUALAN = {0}";

                    query = string.Format(query, currentId);
                    var dtAdapter = new SqlDataAdapter(query, DbConnection.GetConnection());

                    var table = new DataTable { Locale = System.Globalization.CultureInfo.InvariantCulture };
                    dtAdapter.Fill(table);
                    dgvKonsumen.DataSource = table;
                    dgvKonsumen.Columns[0].Visible = false;
                    dgvKonsumen.Columns[1].Visible = false;
                    dgvKonsumen.Columns[2].HeaderText = "Nama";
                    dgvKonsumen.Columns[3].HeaderText = "No Kursi";
                    dgvKonsumen.Columns[1].MinimumWidth = 100;
                    dgvKonsumen.Columns[2].MinimumWidth = 150;
                    dgvKonsumen.Columns[3].MinimumWidth = 100;
                    PopulateList();
                    MessageBox.Show("Berhasil disimpan.", "Transaksi", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    btnBatal_Click(sender, e);

                    var rpt = new FrPrintReceipt(trxId);
                    rpt.ShowDialog();

                }
                else
                {
                    if (chkCarter.Checked)
                        MessageBox.Show("Jadwal carter ini sudah dipesan.", "Transaksi", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    else
                        MessageBox.Show("Sisa kursi yang tersedia " + av + " kursi.", "Transaksi", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                }

            }
        }
Beispiel #2
0
 partial void DeleteTRX_PENJUALAN_DETAIL(TRX_PENJUALAN_DETAIL instance);
Beispiel #3
0
 partial void UpdateTRX_PENJUALAN_DETAIL(TRX_PENJUALAN_DETAIL instance);
Beispiel #4
0
		private void detach_TRX_PENJUALAN_DETAILs(TRX_PENJUALAN_DETAIL entity)
		{
			this.SendPropertyChanging();
			entity.TRX_PENJUALAN = null;
		}
Beispiel #5
0
 partial void InsertTRX_PENJUALAN_DETAIL(TRX_PENJUALAN_DETAIL instance);