Beispiel #1
0
        private void btn_simpan_Click(object sender, EventArgs e)
        {
            ObjectCache cache = MemoryCache.Default;
            dynamic     user  = cache.Get("userLogin");
            var         jenis = 0;

            if (this.cmb_jenis.SelectedItem == "Makanan")
            {
                jenis = 1;
            }
            else if (this.cmb_jenis.SelectedItem == "Minuman")
            {
                jenis = 2;
            }

            var menu = new tbl_menu()
            {
                is_active    = 1,
                created_by   = user.username,
                created_date = DateTime.Now,
                nama_menu    = this.txt_nama_menu.Text,
                harga_satuan = decimal.Parse(this.txt_harga.Text),
                keterangan   = this.txt_keterangan.Text,
                foto         = this.txt_foto.Text,
                jenis        = jenis
            };

            var date = menu.created_date.Value.ToString("yyyy-M-dd hh:mm:ss");

            using (var ctx = new db_dataEntities())
            {
                //ctx.tbl_menu.Add(menu);
                //ctx.SaveChanges();
                ctx.Database.ExecuteSqlCommand("INSERT INTO tbl_menu (is_active,created_by,created_date," +
                                               "nama_menu,harga_satuan,keterangan,foto,jenis) " +
                                               " VALUES (" +
                                               "" + menu.is_active + "," +
                                               "'" + menu.created_by + "'," +
                                               " CAST('" + date + "' AS DATETIME2)," +
                                               "'" + menu.nama_menu + "'," +
                                               "" + menu.harga_satuan + "," +
                                               "'" + menu.keterangan + "'," +
                                               "'" + menu.foto + "'," +
                                               "" + menu.jenis + ")");
                var id = ctx.tbl_menu.OrderByDescending(o => o.id).FirstOrDefault();
            }

            MessageBox.Show("Sukses Simpan");

            Initial();
        }
Beispiel #2
0
        private void btn_simpan_Click(object sender, EventArgs e)
        {
            ObjectCache cache = MemoryCache.Default;
            dynamic     user  = cache.Get("userLogin");
            var         jenis = 0;

            if (this.cmb_jenis.SelectedItem == "Makanan")
            {
                jenis = 1;
            }
            else if (this.cmb_jenis.SelectedItem == "Minuman")
            {
                jenis = 2;
            }

            var menu = new tbl_menu()
            {
                is_active    = 1,
                created_by   = user.username,
                created_date = DateTime.Now,
                nama_menu    = this.txt_nama_menu.Text,
                harga_satuan = decimal.Parse(this.txt_harga.Text),
                keterangan   = this.txt_keterangan.Text,
                foto         = this.txt_foto.Text,
                jenis        = jenis
            };

            using (var ctx = new db_dataEntities())
            {
                ctx.tbl_menu.Add(menu);
                ctx.SaveChanges();
            }

            MessageBox.Show("Sukses Simpan");

            Initial();
        }