Пример #1
0
        private void cmdSave_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                StringBuilder sb = GetMessages();
                if (sb.Length > 0)
                {
                    MessageBox.Show(sb.ToString());
                    return;
                }

                Guid   rowId      = Guid.NewGuid();
                string nomor      = Numerator.GetNumeratorPeriode("BIAYA_OPERASIONAL");
                string publicKey  = ISA.Pin.Generator.CreateKey(GlobalVar.Gudang + Class.PinId.ModulId.BiayaOperasional);
                string recordID   = Tools.CreateFingerPrint(GlobalVar.PerusahaanID, SecurityManager.UserInitial);
                string KodeGudang = GlobalVar.Gudang;

                using (Database db = new Database(GlobalVar.DBName))
                {
                    db.BeginTransaction();

                    try
                    {
                        db.Commands.Add(db.CreateCommand("usp_BiayaOperasional_INSERT"));
                        db.Commands[0].Parameters.Add(new Parameter("@RowID", SqlDbType.UniqueIdentifier, rowId));
                        db.Commands[0].Parameters.Add(new Parameter("@NIP", SqlDbType.VarChar, lupStaff.Nip.Trim()));
                        db.Commands[0].Parameters.Add(new Parameter("@Nama", SqlDbType.VarChar, lupStaff.Nama.Trim()));
                        //db.Commands[0].Parameters.Add(new Parameter("@UnitKerja", SqlDbType.VarChar, txtUnitKerja.Text));
                        db.Commands[0].Parameters.Add(new Parameter("@Nomor", SqlDbType.VarChar, nomor));
                        db.Commands[0].Parameters.Add(new Parameter("@Tanggal", SqlDbType.DateTime, txtTanggal.DateValue));
                        db.Commands[0].Parameters.Add(new Parameter("@Keperluan", SqlDbType.VarChar, txtKeperluan.Text.Trim()));
                        db.Commands[0].Parameters.Add(new Parameter("@PublicKey", SqlDbType.VarChar, publicKey));
                        db.Commands[0].Parameters.Add(new Parameter("@LastUpdatedBy", SqlDbType.VarChar, SecurityManager.UserID));
                        db.Commands[0].Parameters.Add(new Parameter("@KodeGudang", SqlDbType.VarChar, KodeGudang));
                        db.Commands[0].Parameters.Add(new Parameter("@RecordID", SqlDbType.VarChar, recordID));
                        db.Commands[0].ExecuteNonQuery();

                        int counter = 0;
                        foreach (DataGridViewRow row in dgvDetail.Rows)
                        {
                            Guid   rowIdDet    = Guid.NewGuid();
                            string uraian      = Tools.isNull(row.Cells["Uraian"].Value, string.Empty).ToString();
                            double rpBiaya     = double.Parse(Tools.isNull(row.Cells["RpBiaya"].Value, "0").ToString().Replace(",", string.Empty).Replace(".", string.Empty));
                            string keterangan  = Tools.isNull(row.Cells["Keterangan"].Value, string.Empty).ToString();
                            string NoPerkiraan = Tools.isNull(row.Cells["NoPerkiraan"].Value, string.Empty).ToString();

                            if (uraian != string.Empty && rpBiaya > 0)
                            {
                                counter++;

                                db.Commands.Add(db.CreateCommand("usp_BiayaOperasionalDetail_INSERT"));
                                db.Commands[counter].Parameters.Add(new Parameter("@RowID", SqlDbType.UniqueIdentifier, rowIdDet));
                                db.Commands[counter].Parameters.Add(new Parameter("@BiayaOperasionalRowID", SqlDbType.UniqueIdentifier, rowId));
                                db.Commands[counter].Parameters.Add(new Parameter("@Uraian", SqlDbType.VarChar, uraian.ToUpper()));
                                db.Commands[counter].Parameters.Add(new Parameter("@RpBiaya", SqlDbType.Money, rpBiaya));
                                db.Commands[counter].Parameters.Add(new Parameter("@Keterangan", SqlDbType.VarChar, keterangan.ToUpper()));
                                db.Commands[counter].Parameters.Add(new Parameter("@LastUpdatedBy", SqlDbType.VarChar, SecurityManager.UserID));
                                db.Commands[counter].Parameters.Add(new Parameter("@NoPerkiraan", SqlDbType.VarChar, NoPerkiraan.ToUpper()));
                                db.Commands[counter].ExecuteNonQuery();
                            }
                        }

                        db.CommitTransaction();
                        //txtUraian.Text = Uraian.ToString();
                        txtNomor.Text = nomor;
                        _headerRowId  = rowId;

                        MessageBox.Show(Messages.Confirm.UpdateSuccess);

                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        db.RollbackTransaction();
                        Cursor.Current = Cursors.Default;
                        Error.LogError(ex);
                    }
                }
            }
            catch (Exception ex) { Error.LogError(ex); }
            finally { Cursor.Current = Cursors.Default; }
        }