예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            var subTotal = listOrder.Sum(o => o.harga_total);
            var idOrder  = 0;

            if (listOrder.Count > 0)
            {
                var data = new tbl_order
                {
                    created_by   = "user",
                    created_date = DateTime.Now,
                    no_meja      = no_meja.Text,
                    subtotal     = subTotal,
                    status       = 0,
                    is_active    = 1
                };
                using (var ctx = new db_dataEntities())
                {
                    var id = ctx.tbl_order.Add(data);
                    ctx.SaveChanges();
                    idOrder = id.id;
                }
            }

            foreach (var order in listOrder)
            {
                var detailOrder = new tbl_detail_order
                {
                    created_by   = "user",
                    created_date = DateTime.Now,
                    id_order     = idOrder,
                    id_menu      = order.id_menu,
                    qty          = order.qty,
                    harga_satuan = order.harga_satuan,
                    harga_total  = order.harga_total,
                    is_active    = 1
                };

                using (var ctx = new db_dataEntities())
                {
                    ctx.tbl_detail_order.Add(detailOrder);
                    ctx.SaveChanges();
                }
            }

            MessageBox.Show("Menu Telah Di Order");

            Initial();
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            var subTotal = listOrder.Sum(o => o.harga_total);
            var idOrder  = 0;

            if (listOrder.Count > 0)
            {
                var data = new tbl_order
                {
                    created_by   = "user",
                    created_date = DateTime.Now,
                    no_meja      = no_meja.Text,
                    subtotal     = subTotal,
                    status       = 0,
                    is_active    = 1
                };

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

                using (var ctx = new db_dataEntities())
                {
                    var query = "INSERT INTO tbl_order (is_active,created_by,created_date," +
                                "no_meja,subtotal,status) " +
                                " VALUES (" +
                                "" + data.is_active + "," +
                                "'" + data.created_by + "'," +
                                " CAST('" + date + "' AS DATETIME2)," +
                                "'" + data.no_meja + "'," +
                                "" + data.subtotal + "," +
                                "" + data.status + ")";

                    ctx.Database.ExecuteSqlCommand(query);

                    var id = ctx.tbl_order.OrderByDescending(o => o.id).FirstOrDefault();

                    //var id = ctx.tbl_order.Add(data);
                    //ctx.SaveChanges();
                    idOrder = id.id;
                }
            }

            foreach (var order in listOrder)
            {
                var detailOrder = new tbl_detail_order
                {
                    created_by   = "user",
                    created_date = DateTime.Now,
                    id_order     = idOrder,
                    id_menu      = order.id_menu,
                    qty          = order.qty,
                    harga_satuan = order.harga_satuan,
                    harga_total  = order.harga_total,
                    is_active    = 1
                };

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

                using (var ctx = new db_dataEntities())
                {
                    var query = "INSERT INTO tbl_detail_order ([is-active],created_by,created_date," +
                                "id_order,id_menu,qty,harga_satuan,harga_total) " +
                                " VALUES (" +
                                "" + detailOrder.is_active + "," +
                                "'" + detailOrder.created_by + "'," +
                                " CAST('" + date + "' AS DATETIME2)," +
                                "" + detailOrder.id_order + "," +
                                "" + detailOrder.id_menu + "," +
                                "" + detailOrder.qty + "," +
                                "" + detailOrder.harga_satuan + "," +
                                "" + detailOrder.harga_total + ")";

                    ctx.Database.ExecuteSqlCommand(query);

                    //ctx.tbl_detail_order.Add(detailOrder);
                    //ctx.SaveChanges();
                }
            }

            MessageBox.Show("Menu Telah Di Order");

            Initial();
        }