Beispiel #1
0
        public ActionResult Create([Bind(Include = "Id,Name,Processor,Motherboard,Ram,Hard_drive,Delivery,Order,image")] Komputers komputers, HttpPostedFileBase upload)
        {
            if (ModelState.IsValid)
            {
                if (upload != null && upload.ContentLength > 0)
                {
                    using (var reader = new System.IO.BinaryReader(upload.InputStream))
                    {
                        komputers.image = reader.ReadBytes(upload.ContentLength);
                    }
                }

                db.Komputers.Add(komputers);
                db.SaveChanges();
                return(RedirectToAction("admin_index"));
            }

            ViewBag.Delivery    = new SelectList(db.Deliveries, "id", "date", komputers.Delivery);
            ViewBag.Hard_drive  = new SelectList(db.Hard_disks, "Id", "Name", komputers.Hard_drive);
            ViewBag.Motherboard = new SelectList(db.Motherboards, "Id", "Name", komputers.Motherboard);
            ViewBag.Order       = new SelectList(db.Orders, "id", "date", komputers.Order);
            ViewBag.Processor   = new SelectList(db.Processors, "Id", "Name", komputers.Processor);
            ViewBag.Ram         = new SelectList(db.Rams, "Id", "Name", komputers.Ram);
            return(View(komputers));
        }
Beispiel #2
0
        public ActionResult Create(Cources cource)
        {
            if (ModelState.IsValid)
            {
                _db.Cources.Add(cource);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(cource));
        }
        public ActionResult Create([Bind(Include = "Id,yardName")] yard yard)
        {
            if (ModelState.IsValid)
            {
                db.yards.Add(yard);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(yard));
        }
Beispiel #4
0
        public ActionResult Create([Bind(Include = "Id,location_name,longitude,latitude")] Place place)
        {
            if (ModelState.IsValid)
            {
                db.Places.Add(place);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(place));
        }
Beispiel #5
0
        public ActionResult Create([Bind(Include = "Id,Login,Password")] Admin admin)
        {
            if (ModelState.IsValid)
            {
                db.Admin.Add(admin);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(admin));
        }
Beispiel #6
0
        public ActionResult Create([Bind(Include = "Id,ConName")] container container)
        {
            if (ModelState.IsValid)
            {
                db.containers.Add(container);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(container));
        }
        public ActionResult Create([Bind(Include = "Id,Date,Num_Delivery")] Deliveries deliveries)
        {
            if (ModelState.IsValid)
            {
                db.Deliveries.Add(deliveries);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(deliveries));
        }
Beispiel #8
0
        public ActionResult Create([Bind(Include = "Id,DescricaoTipo,DataCadastro")] TipoDocumento tipoDocumento)
        {
            if (ModelState.IsValid)
            {
                db.TipoDocumentoes.Add(tipoDocumento);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tipoDocumento));
        }
        public ActionResult Create([Bind(Include = "Id,time,date,depart,arrive")] schedule schedule)
        {
            if (ModelState.IsValid)
            {
                db.schedules.Add(schedule);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(schedule);
        }
Beispiel #10
0
        public ActionResult Create([Bind(Include = "Id,Date,Num_Order")] Orders orders)
        {
            if (ModelState.IsValid)
            {
                db.Orders.Add(orders);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(orders));
        }
Beispiel #11
0
        public ActionResult Create([Bind(Include = "Id,Name")] Makers makers)
        {
            if (ModelState.IsValid)
            {
                db.Makers.Add(makers);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(makers));
        }
Beispiel #12
0
        public ActionResult Create([Bind(Include = "Id,Name,Price,Delivery,Order,Maker")] Motherboards motherboards)
        {
            if (ModelState.IsValid)
            {
                db.Motherboards.Add(motherboards);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Delivery = new SelectList(db.Deliveries, "Id", "date", motherboards.Delivery);
            ViewBag.Maker    = new SelectList(db.Makers, "Id", "Name", motherboards.Maker);
            ViewBag.Order    = new SelectList(db.Orders, "Id", "date", motherboards.Order);
            return(View(motherboards));
        }
Beispiel #13
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (dataGridView2.Rows.Count <= 0)
            {
                MessageBox.Show("Belum ada barang yang di retur", "Warning!", MessageBoxButtons.OK);
            }
            else
            {
                db_Retur_Penjualan frpen = new db_Retur_Penjualan()
                {
                    No_Retur_Penjualan       = labelID.Text,
                    No_Form_Penjualan_Grosir = comboBoxPenjGrosir.SelectedItem.ToString(),
                    Tanggal = dateTimePicker1.Text,
                };
                db.AddTodb_Retur_Penjualan(frpen);
                db.SaveChanges();

                for (int i = 0; i < dataGridView2.RowCount; i++)
                {
                    string ih = "";
                    string ah = "";
                    int    h  = 0;
                    string eh = "";

                    try
                    {
                        ih = dataGridView2.Rows[i].Cells[0].Value.ToString();
                        ah = dataGridView2.Rows[i].Cells[1].Value.ToString();
                        h  = int.Parse(dataGridView2.Rows[i].Cells[2].Value.ToString());
                        eh = dataGridView2.Rows[i].Cells[3].Value.ToString();
                    }
                    catch (Exception) { }

                    db_Detail_Retur_Penjualan dt = new db_Detail_Retur_Penjualan()
                    {
                        No_Retur_Penjualan = labelID.Text,
                        ID_Barang          = ih,
                        Jumlah             = h,
                        Deskripsi          = eh,
                        Nama_Barang        = ah,
                    };
                    db.AddTodb_Detail_Retur_Penjualan(dt);
                    db.SaveChanges();
                }
                MessageBox.Show("Add Retur berhasil", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                button2.Enabled = false;
                button3.Enabled = false;
                button4.Enabled = false;
            }
        }
        public ActionResult Upload(ClassArquivoUploadForm arq)
        {
            string[] allowedFiletypes = { ".doc", ".docx", ".pdf", ".xls", ".xlsx", ".xlsm", ".ppt", ".pptx" };
            string   ext = Path.GetExtension(arq.Arquivo.FileName);

            if (arq.Arquivo.ContentLength > 0 && allowedFiletypes.Contains(ext))
            {
                byte[] arquivoBytes = new byte[arq.Arquivo.ContentLength];
                using (BinaryReader binReader = new BinaryReader(arq.Arquivo.InputStream))
                {
                    arquivoBytes = binReader.ReadBytes(arq.Arquivo.ContentLength);
                }
                arquivos clsArq = new arquivos()
                {
                    NomeArquivo           = arq.Arquivo.FileName,
                    ContentType           = arq.Arquivo.ContentType,
                    Visualizado           = 0,
                    IdDepartamento        = arq.IdDepartamento,
                    IdTipoDoc             = arq.IdTipoDoc,
                    IdUsuarioRemetente    = arq.IdUsuarioRemetente,
                    IdUsuarioDestinatario = arq.IdUsuarioDestinatario,
                    Descricao             = arq.Descricao,
                    DataUpload            = DateTime.Now,
                    ContDownloads         = 0,
                    arquivo = arquivoBytes
                };
                try
                {
                    ctx.arquivos.Add(clsArq);
                    if (ctx.SaveChanges() != 0)
                    {
                        //Envio de email
                    }
                    ModelState.Clear();
                    TempData["Message"] = "Arquivo enviado com sucesso!";
                    return(RedirectToAction("EnviarArquivo", "Arquivo"));
                }
                catch
                {
                    ModelState.Clear();
                    return(Content("<script type='text/javascript'>alert('Ocorreu um erro inesperado no banco de dados.'); window.location = '/Arquivo/EnviarArquivo'</script>"));
                }
            }
            else
            {
                ModelState.Clear();
                return(Content("<script type='text/javascript'>alert('Por favor, selecione um tipo de arquivo válido.'); window.location = '/Arquivo/EnviarArquivo';</script>"));
            }
        }
Beispiel #15
0
 private void DeleteKaryawan(string id)
 {
     if (id == "")
     {
         MessageBox.Show("Pilih data yang ingin dihapus!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     else if (MessageBox.Show(this, "Are you sure want to delete Karyawan " + textBox1.Text + " ?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         var t = (from a in db.db_Karyawan.ToList()
                  where a.ID_Karyawan == id
                  select a).First();
         db.DeleteObject(t);
         db.SaveChanges();
     }
 }
        private void button5_Click(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count <= 0)
            {
                MessageBox.Show("Tidak ada data untuk di simpan", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                db_Faktur_Pemesanan df = new db_Faktur_Pemesanan()
                {
                    No_Faktur_Pemesanan = textBox1.Text,
                    ID_Karyawan         = textBox9.Text,
                    ID_Supplier         = textBox7.Text,
                    Tanggal             = dateTimePicker1.Text
                };
                db.AddTodb_Faktur_Pemesanan(df);
                db.SaveChanges();

                for (int i = 0; i < dataGridView1.RowCount; i++)
                {
                    string ih = "";
                    string ah = "";
                    int    h  = 0;
                    int    hh = 0;
                    try {
                        ih = dataGridView1.Rows[i].Cells[1].Value.ToString();
                        ah = dataGridView1.Rows[i].Cells[3].Value.ToString();
                        hh = int.Parse(dataGridView1.Rows[i].Cells[5].Value.ToString());
                        h  = int.Parse(dataGridView1.Rows[i].Cells[6].Value.ToString());
                    }
                    catch (Exception) { }

                    db_Detail_Faktur_Pemesanan dbf = new db_Detail_Faktur_Pemesanan()
                    {
                        No_Faktur_Pemesanan = textBox1.Text,
                        ID_Barang           = ih,
                        Nama_Barang         = ah,
                        Harga  = hh,
                        Jumlah = h
                    };
                    db.AddTodb_Detail_Faktur_Pemesanan(dbf);
                    db.SaveChanges();
                }
                MessageBox.Show("Transaksi berhasil", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                button2.Enabled = false;
                button5.Enabled = false; button3.Enabled = false;
            }
        }
Beispiel #17
0
        public HttpResponseMessage Delete(int id)
        {
            try
            {
                using (databaseEntities dbEntities = new databaseEntities())
                {
                    var entity = dbEntities.Lends.FirstOrDefault(loanId => loanId.Id == id);

                    if (entity != null)
                    {
                        //remove from database
                        dbEntities.Lends.Remove(entity);
                        dbEntities.SaveChanges();

                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                    else
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "There is no loan associated with the requested id: " + id.ToString()));
                    }
                }
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e));
            }
        }
        public Transaction CreateNewTransaction(int userId, List <int> productIds, List <int> productAmounts)
        {
            using (var context = new databaseEntities())
            {
                var u         = (from x in context.Users where x.Id == userId select x).First();
                var purchases = new List <Purchase>();

                for (int i = 0; i < productIds.Count; i++)
                {
                    var currentId     = productIds[i];
                    var currentAmount = productAmounts[i];
                    purchases.Add(new Purchase(currentId, currentAmount, context.Products.Where(x => x.Id == currentId).First().Price));
                }

                var totalPrice = purchases.Sum(x => x.TotalPrice);
                var stocks     = (from x in context.Stocks from y in productIds where x.ProductId == y select x);

                if (!(u.Funds >= totalPrice))
                {
                    return(null);
                }

                for (int i = 0; i < productIds.Count; i++)
                {
                    var currentId     = productIds[i];
                    var currentAmount = productAmounts[i];
                    var stock         = stocks.Single(x => x.Id == currentId);

                    if (stock.Amount < currentAmount)
                    {
                        return(null);
                    }
                }

                var t = new Transaction {
                    UserId = userId
                };
                context.Transactions.Add(t);

                u.Funds -= totalPrice;

                for (int i = 0; i < productIds.Count; i++)
                {
                    var currentId     = productIds[i];
                    var currentAmount = productAmounts[i];
                    var currentPrice  = (from x in context.Products where x.Id == currentId select x).First().Price;
                    (from y in stocks where y.ProductId == currentId select y).First().Amount -= currentAmount;
                    context.TransactionRows.Add(new TransactionRow {
                        ProductId = currentId, Amount = currentAmount, TransactionId = t.Id, Price = currentPrice
                    });
                }

                context.SaveChanges();

                return(t);
            }
        }
Beispiel #19
0
        public ActionResult Delete(int id)
        {
            //db.sp_delete_branch(id);
            //return RedirectToAction("Index");

            var res = db.Branches.Where(x => x.BranchId == id).First();

            db.Branches.Remove(res);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Beispiel #20
0
        public ActionResult Cadastro(ClassUsuario user)
        {
            if (user.Senha == user.ConfirmarSenha)
            {
                try
                {
                    var consultaUsuario = ctx.usuarios.Where(u => u.NomeUsuario == user.NomeUsuario || u.Email == user.Email).FirstOrDefault();
                    if (consultaUsuario == null)
                    {
                        int tipoUsu;
                        if (user.TipoUsuario == "cliente")
                        {
                            tipoUsu = 1;
                        }
                        else
                        {
                            tipoUsu = 2;
                        }
                        var passwordBytes = Encoding.UTF8.GetBytes(user.Senha);
                        var usu           = new usuarios()
                        {
                            NomeUsuario = user.NomeUsuario,
                            Email       = user.Email,
                            Senha       = Convert.ToBase64String(passwordBytes),
                            IdTipoUsu   = tipoUsu,
                        };
                        ctx.usuarios.Add(usu);
                        ctx.SaveChanges();

                        ModelState.Clear();
                        ViewBag.Message = "Cadastro efetuado com sucesso!!";
                        return(View("~/Views/Workflow/PaginaCadastro.cshtml"));
                    }
                    else
                    {
                        ModelState.Clear();
                        return(Content("<script type='text/javascript'>alert('Este usuário/E-mail já está cadastrado no sistema. Por favor,tente novamente.'); window.location = '/Workflow/PaginaCadastro';</script>"));
                    }
                }
                catch
                {
                    ViewBag.Message = "Ocorreu um erro inesperado no cadastro. Tente novamente mais tarde.";
                    ModelState.Clear();
                    return(View("~/Views/Workflow/PaginaCadastro.cshtml"));
                }
            }
            else
            {
                ModelState.Clear();
                return(Content("<script type='text/javascript'>alert('senha e confirmar senha não são idênticos. Por favor,tente novamente.'); window.location = '/Workflow/PaginaCadastro';</script>"));
            }
        }
Beispiel #21
0
        public User CreateNewUser(string username)
        {
            using (var context = new databaseEntities())
            {
                var u = new User {
                    Username = username, Password = new string(username.ToCharArray().Reverse().ToArray()), Funds = 100
                };
                context.Users.Add(u);
                context.SaveChanges();

                return(u);
            }
        }
Beispiel #22
0
        //[Route("post")]
        public HttpResponseMessage Post(Lend loan)
        {
            try
            {
                using (databaseEntities dbEntities = new databaseEntities())
                {
                    //add to database
                    dbEntities.Lends.Add(loan);
                    dbEntities.SaveChanges();

                    //get the response code of 201 for successful post and return the newly added loan
                    var message = Request.CreateResponse(HttpStatusCode.Created, loan);
                    message.Headers.Location = new Uri(Request.RequestUri + loan.Id.ToString());

                    return(message);
                }
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e));
            }
        }
Beispiel #23
0
        public ActionResult RegisterConfirmed([Bind(Include = "Id,Login,Password")] Admin adm)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //Хранимая процедура "NewAdmin" для регистрации нового администратора
                    var regInfo = db.NewAdmin(adm.Login, adm.Password).ToList();
                    if (regInfo != null && Convert.ToInt32(regInfo[0]) != -1)
                    {
                        db.SaveChanges();
                        return(RedirectToAction("Auth"));
                    }
                    else
                    {
                        ModelState.AddModelError("Email", "ПОЛЬЗОВАТЕЛЬ С ТАКИМ ИМЕНЕМ (E-MAIL) УЖЕ СУЩЕСТВУЕТ.");
                    }
                }
            }
            catch (Exception ex)
            { }

            return(View());
        }
Beispiel #24
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (dataGridViewDetail.Rows.Count <= 0)
            {
                MessageBox.Show("Belum ada barang yang di retur", "Warning!", MessageBoxButtons.OK);
            }
            else
            {
                string tampID = "";
                if (status == "FRJ")
                {
                    try
                    {
                        tampID = listBoxID.Text;
                        db_Retur_Pembelian frpem = new db_Retur_Pembelian()
                        {
                            No_Retur_Pembelian  = labelID.Text,
                            No_Retur_Penjualan  = tampID,
                            No_Faktur_Pemesanan = "",
                            Tanggal             = dateTimePicker3.Text,
                        };
                        db.AddTodb_Retur_Pembelian(frpem);
                        db.SaveChanges();


                        for (int i = 0; i < dataGridViewDetail.RowCount; i++)
                        {
                            string ih = "";
                            string ah = "";
                            int    h  = 0;
                            string eh = "";

                            try
                            {
                                ih = dataGridViewDetail.Rows[i].Cells[0].Value.ToString();
                                ah = dataGridViewDetail.Rows[i].Cells[1].Value.ToString();
                                h  = int.Parse(dataGridViewDetail.Rows[i].Cells[2].Value.ToString());
                                eh = dataGridViewDetail.Rows[i].Cells[3].Value.ToString();
                            }
                            catch (Exception) { }

                            db_Detail_Retur_Pembelian dd = new db_Detail_Retur_Pembelian()
                            {
                                No_Retur_Pembelian = labelID.Text,
                                ID_Barang          = ih,
                                Jumlah             = h,
                                Deskripsi          = eh,
                                Nama_Barang        = ah,
                            };
                            db.AddTodb_Detail_Retur_Pembelian(dd);
                            db.SaveChanges();

                            //var t = (from a in db.db_Detail_Retur_Penjualan where a.No_Retur_Penjualan == tampID && a.ID_Barang ==ih select a).First();
                            //t.Jumlah = t.Jumlah - h;
                            //db.SaveChanges();
                        }
                    }
                    catch (Exception) { }
                }
                else if (status == "FPE")
                {
                    try
                    {
                        tampID = listBoxID.Text;
                        db_Retur_Pembelian frpem = new db_Retur_Pembelian()
                        {
                            No_Retur_Pembelian  = labelID.Text,
                            No_Retur_Penjualan  = "",
                            No_Faktur_Pemesanan = tampID,
                            Tanggal             = dateTimePicker3.Text,
                        };
                        db.AddTodb_Retur_Pembelian(frpem);
                        db.SaveChanges();



                        for (int i = 0; i < dataGridViewDetail.RowCount; i++)
                        {
                            string ih = "";
                            string ah = "";
                            int    h  = 0;
                            string eh = "";

                            try
                            {
                                ih = dataGridViewDetail.Rows[i].Cells[0].Value.ToString();
                                ah = dataGridViewDetail.Rows[i].Cells[1].Value.ToString();
                                h  = int.Parse(dataGridViewDetail.Rows[i].Cells[2].Value.ToString());
                                eh = dataGridViewDetail.Rows[i].Cells[3].Value.ToString();
                            }
                            catch (Exception) { }

                            db_Detail_Retur_Pembelian dt = new db_Detail_Retur_Pembelian()
                            {
                                No_Retur_Pembelian = labelID.Text,
                                ID_Barang          = ih,
                                Jumlah             = h,
                                Deskripsi          = eh,
                                Nama_Barang        = ah,
                            };
                            db.AddTodb_Detail_Retur_Pembelian(dt);
                            db.SaveChanges();
                            //try
                            //{
                            //    var t = (from a in db.db_Detail_Faktur_Pemesanan where a.No_Faktur_Pemesanan == tampID && a.ID_Barang == ih select a).First();
                            //    t.Jumlah = t.Jumlah - h;
                            //}
                            //catch (Exception) { }
                        }
                    }catch (Exception) { }
                }
                MessageBox.Show("Add Retur berhasil", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                button2.Enabled = false;
                button1.Enabled = false;
                button4.Enabled = false;
            }
        }
        private void button5_Click(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count <= 0)
            {
                MessageBox.Show("Tidak ada data untuk di simpan", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                db_Form_Penjualan_Eceran fe = new db_Form_Penjualan_Eceran()
                {
                    No_Form_Penjualan_Eceran = textBox6.Text,
                    ID_Karyawan = textBox1.Text,
                    Tanggal     = dateTimePicker1.Text
                };
                db.AddTodb_Form_Penjualan_Eceran(fe);
                db.SaveChanges();


                for (int i = 0; i < dataGridView1.RowCount; i++)
                {
                    string ih = "";
                    string ah = "";
                    int    h = 0, l = 0;
                    try
                    {
                        ih = dataGridView1.Rows[i].Cells[1].Value.ToString();
                        h  = int.Parse(dataGridView1.Rows[i].Cells[3].Value.ToString());
                        l  = int.Parse(dataGridView1.Rows[i].Cells[4].Value.ToString());
                        ah = dataGridView1.Rows[i].Cells[2].Value.ToString();
                    }
                    catch (Exception) { }

                    db_Detail_Form_Penjualan_Eceran dfe = new db_Detail_Form_Penjualan_Eceran()
                    {
                        No_Form_Penjualan_Eceran = textBox6.Text,
                        ID_Barang   = ih,
                        Harga       = h,
                        Jumlah      = l,
                        Nama_Barang = ah
                    };
                    db.AddTodb_Detail_Form_Penjualan_Eceran(dfe);
                    db.SaveChanges();



                    try
                    {
                        var up = (from a in db.db_Barang where a.ID_Barang == ih select a).FirstOrDefault();
                        if (up.Stock != null)
                        {
                            up.Stock = up.Stock - l;
                            db.SaveChanges();
                            if (up.Stock <= 500)
                            {
                                MessageBox.Show("Stock " + dataGridView1.Rows[i].Cells[2].Value.ToString() + " mulai menipis, harap segera buat Faktur Pemesanan! ", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                    }
                    catch (Exception) { }
                }
                MessageBox.Show("Transaksi berhasil", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                button4.Enabled = false;
                button5.Enabled = false;
                button6.Enabled = false;
                id = textBox6.Text;
            }
        }