Esempio n. 1
0
        public ActionResult Create([Bind(Include = "OwnerID,OwnerName")] OWNER oWNER)
        {
            if (ModelState.IsValid)
            {
                db.OWNER.Add(oWNER);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(oWNER));
        }
Esempio n. 2
0
        public ActionResult Create([Bind(Include = "CustId,CustLoginName,CustPassword")] CustomerInfo custLogin)
        {
            if (ModelState.IsValid)
            {
                db.CustomerInfoes.Add(custLogin);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(custLogin));
        }
        public ActionResult Create([Bind(Include = "DealID,StockID,OwnerID,StockQuantity")] APPLICATION aPPLICATION)
        {
            if (ModelState.IsValid)
            {
                db.APPLICATION.Add(aPPLICATION);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.OwnerID = new SelectList(db.OWNER, "OwnerID", "OwnerName", aPPLICATION.OwnerID);
            return(View(aPPLICATION));
        }
Esempio n. 4
0
        public ActionResult Addproduct(Product model)
        {
            if (ModelState.IsValid)
            {
                Product obj = new Product();
                obj.productname  = model.productname;
                obj.categoryname = model.categoryname;

                dbObj.Products.Add(obj);
                dbObj.SaveChanges();
            }
            ModelState.Clear();
            return(View("product"));
        }
Esempio n. 5
0
        public ActionResult SalvarFornecedor(Fornecedor f)
        {
            string        resultado = "OK";
            List <string> mensagens = new List <string>();
            string        idSalvo   = string.Empty;

            if (!ModelState.IsValid)
            {
                resultado = "AVISO";
                mensagens = ModelState.Values.SelectMany(m => m.Errors).Select(m => m.ErrorMessage).ToList();
            }
            else
            {
                try
                {
                    // Verifica se o fornecedor já existe
                    var forn = stock.Fornecedor.FirstOrDefault(x => x.Id == f.Id);

                    // Se não existe, adiciona e salva (create)
                    if (forn == null)
                    {
                        forn = f;
                        stock.Fornecedor.Add(forn);
                        stock.SaveChanges();
                    }
                    // Se existe, salva somente as alterações (update)
                    else
                    {
                        forn.Nome     = f.Nome;
                        forn.Telefone = f.Telefone;
                        forn.Endereco = f.Endereco;
                        forn.Cidade   = f.Cidade;
                        forn.Pais     = f.Pais;
                        stock.SaveChanges();
                    }

                    idSalvo = f.Id.ToString();
                }
                catch (Exception ex)
                {
                    resultado = "ERRO: " + ex.Message;
                }
            }

            return(Json(new { Resultado = resultado, Mensagens = mensagens, IdSalvo = idSalvo }));
        }
Esempio n. 6
0
 public ActionResult Register(CustomerInfo data)
 {
     try {
         db.CustomerInfoes.Add(data);
         db.SaveChanges();
         return(RedirectToAction("Index", "Home"));
     } catch {
         return(View(data));
     }
 }
Esempio n. 7
0
        public ActionResult SalvarCategoriaProduto(CategoriaProduto cp)
        {
            string        resultado = "OK";
            List <string> mensagens = new List <string>();
            string        idSalvo   = string.Empty;

            if (!ModelState.IsValid)
            {
                resultado = "AVISO";
                mensagens = ModelState.Values.SelectMany(m => m.Errors).Select(m => m.ErrorMessage).ToList();
            }
            else
            {
                try
                {
                    // Verifica se a categoria já existe
                    var c = stock.CategoriaProduto.FirstOrDefault(x => x.Id == cp.Id);

                    // Se não existe, adiciona e salva (create)
                    if (c == null)
                    {
                        c = cp;
                        stock.CategoriaProduto.Add(c);
                        stock.SaveChanges();
                    }
                    // Se existe, salva somente as alterações (update)
                    else
                    {
                        c.Nome   = cp.Nome;
                        c.Estado = cp.Estado;
                        stock.SaveChanges();
                    }

                    idSalvo = c.Id.ToString();
                }
                catch (Exception ex)
                {
                    resultado = "ERRO: " + ex.Message;
                }
            }

            return(Json(new { Resultado = resultado, Mensagens = mensagens, IdSalvo = idSalvo }));
        }
Esempio n. 8
0
        public ActionResult Register(CustomerInfo data)
        {
            var loginData = new CustLogin();

            //int q = Convert.ToInt32(Session["CustId"]);
            //return Content(q.ToString());
            try {
                loginData.CustId        = data.CustId;
                loginData.CustLoginName = data.CustLoginName;
                loginData.CustPassword  = data.CustPassword;
                db.CustomerInfoes.Add(data);
                db.SaveChanges();
                db.CustLogins.Add(loginData);
                db.SaveChanges();
                //var CustLogin = db.CustLogins.Add(loginData);
                return(RedirectToAction("Index", "Home"));
            } catch {
                //return Content(data.CustId.ToString());
                return(View(data));
            }
        }
Esempio n. 9
0
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                var cbxCell = (DataGridViewCheckBoxCell)this.dataGridView1.Rows[e.RowIndex].Cells[0];

                //取得cbxCell EditingCellFormattedValue屬性值
                if (cbxCell != null && ((bool)cbxCell.EditingCellFormattedValue == false || (bool)cbxCell.FormattedValue == false))
                {
                    DataGridViewRow s = this.dataGridView1.Rows[e.RowIndex];
                    //取出headertext
                    //string h = s.Cells[1].OwningColumn.HeaderText;
                    //取出value
                    //string v = s.Cells[1].Value.ToString();
                    datasave.account = member.account;
                    datasave.證券代號    = s.Cells[1].Value.ToString();
                    datasave.證券名稱    = s.Cells[2].Value.ToString();
                    datasave.成交股數    = s.Cells[3].Value.ToString();
                    datasave.成交筆數    = s.Cells[4].Value.ToString();
                    datasave.成交金額    = s.Cells[5].Value.ToString();
                    datasave.開盤價     = s.Cells[6].Value.ToString();
                    datasave.最高價     = s.Cells[7].Value.ToString();
                    datasave.最低價     = s.Cells[8].Value.ToString();
                    datasave.收盤價     = s.Cells[9].Value.ToString();
                    datasave.漲跌正or負  = s.Cells[10].Value.ToString();
                    datasave.漲跌價差    = s.Cells[11].Value.ToString();

                    db.datasave.Add(datasave);
                    db.SaveChanges();
                }
                //else
                //{
                //    dataModel.Delete(datasave);
                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 10
0
 public ActionResult Register(CustomerInfo data)
 {
     try {
         //data.CustId = data.CustId.ToString();
         db.CustomerInfoes.Add(data);
         db.SaveChanges();
         return(RedirectToAction("Index", "Home"));
     } catch {
         return(View(data));
         //string s=data.
         //return Content()
     }
 }
Esempio n. 11
0
        internal int create(members formData)
        {
            members result = db.members.Where(m => m.account == formData.account).FirstOrDefault();

            if (result == null)
            {
                db.members.Add(formData);
                return(db.SaveChanges());
            }
            else
            {
                return(0);
            }
        }
Esempio n. 12
0
 public int AddProduit(Produit Produit)
 {
     Context.Produit.Add(Produit);
     try
     {
         Context.SaveChanges();
     }
     catch (DbEntityValidationException e)
     {
         foreach (var eve in e.EntityValidationErrors)
         {
             Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                               eve.Entry.Entity.GetType().Name, eve.Entry.State);
             foreach (var ve in eve.ValidationErrors)
             {
                 Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                   ve.PropertyName, ve.ErrorMessage);
             }
         }
         throw;
     }
     return(Context.Produit.Add(Produit).Id);
 }
Esempio n. 13
0
        public ActionResult MyOrderDetail(Ship postback)
        {
            //Cart cart = new Cart();
            if (this.ModelState.IsValid)     //取得目前購物車
            {
                var currentcart = Cart.Operation.GetCurrentCart();

                //取得目前登入使用者Id
                int userId = Convert.ToInt32(Session["CustId"]);

                using (StockEntities db = new StockEntities()) {
                    //建立Order物件
                    var order = new OrderInfo()
                    {
                        //    UserId = userId,
                        //    RecieverName = postback.RecieverName,
                        //    RecieverPhone = postback.RecieverPhone,
                        //    RecieverAddress = postback.RecieverAddress
                        CustId     = userId,
                        OrderTotal = currentcart.TotalAmount, //cartitem.Price,
                        OrderTime  = DateTime.Now,
                    };
                    ////加其入Orders資料表後,儲存變更
                    db.OrderInfoes.Add(order);
                    db.SaveChanges();
                    //取得購物車中OrderDetai物件
                    var orderDetails = currentcart.ToOrderDetail(order.OrderId);

                    //將其加入OrderDetails資料表後,儲存變更
                    db.OrderDetails.AddRange(orderDetails);
                    db.SaveChanges();
                }
                return(Content("訂購成功"));
            }
            return(View());
        }
Esempio n. 14
0
        /// <summary>
        /// 新增法人持股
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        internal int InsertForeignOwn(List <ForeignOwn> models)
        {
            var count = 0;

            using (var db = new StockEntities())
            {
                // 有相同日期不上傳
                if (models.Count > 0 && models[0] != null && !db.ForeignOwn.AsEnumerable().Any(c => c.Date == models[0].Date))
                {
                    db.ForeignOwn.AddRange(models);
                    count = db.SaveChanges();
                }
            }
            return(count);
        }
Esempio n. 15
0
        /// <summary>
        /// 新增三大買賣超
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        internal int Insert3BigBuySell(List <ThreeBigBuySell> models)
        {
            var count = 0;

            using (var db = new StockEntities())
            {
                // 有相同日期不上傳
                if (models.Count > 0 && models[0] != null && !db.ThreeBigBuySell.AsEnumerable().Any(c => c.Date == models[0].Date))
                {
                    db.ThreeBigBuySell.AddRange(models);
                    count = db.SaveChanges();
                }
            }
            return(count);
        }
Esempio n. 16
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                member = (members)this.Tag;
                string oldpassword = txtoldpassword.Text.Trim();
                oldpassword = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(oldpassword, "SHA1");
                string newpassword = txtnewpassword.Text.Trim();

                string newpasswordcheck = txtnewpasswoedcheck.Text.Trim();



                if (oldpassword == member.password)
                {
                    if (newpassword != "" && newpasswordcheck != "")
                    {
                        newpassword      = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(newpassword, "SHA1");
                        newpasswordcheck = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(newpasswordcheck, "SHA1");
                        if (newpassword == newpasswordcheck)
                        {
                            members Loginmember = db.members.Where(m => m.account == member.account).FirstOrDefault();
                            Loginmember.password = newpassword;

                            db.SaveChanges();
                            MessageBox.Show("密碼變更成功!!", "密碼變更", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("新密碼與新密碼確認不一致!!", "密碼變更", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show("請輸入新密碼", "密碼變更", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("舊密碼輸入錯誤!!", "密碼變更", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 17
0
        public ActionResult Index(Ship postback)
        {
            StockEntities db    = new StockEntities();
            int           usrId = Convert.ToInt32(Session["CustId"]);
            var           q     = from s in db.CustomerInfoes
                                  where s.CustId == usrId
                                  select s;
            var result = q.ToList();
            var q1     = (from s in db.OrderInfoes
                          orderby s.OrderId descending
                          select s.OrderId).FirstOrDefault();
            int orderId = q1 + 1;

            //StockEntities db = new StockEntities();
            //int usrId = Convert.ToInt32(Session["CustId"]);
            //    var q = from s in db.VW_OrderAndDetailAndCust
            //            where s.CustId == usrId
            //            select s;
            //    var result = q.ToList();

            //Cart cart = new Cart();
            if (this.ModelState.IsValid == false)
            {
                /*if (this.ModelState.IsValid) {*/   //取得目前購物車
                var currentcart = Cart.Operation.GetCurrentCart();
                var q2          = (from s in db.OrderInfoes
                                   orderby s.OrderId descending
                                   select s.OrderId).FirstOrDefault();
                int orderid = q2 + 1;
                //取得目前登入使用者Id
                //int userId = Convert.ToInt32(Session["CustId"]);
                //int userId = Convert.ToInt32(Session["CustId"]);

                using (StockEntities db1 = new StockEntities()) {
                    //建立Order物件
                    var order = new OrderInfo()
                    {
                        //    UserId = userId,
                        //    RecieverName = postback.RecieverName,
                        //    RecieverPhone = postback.RecieverPhone,
                        //    RecieverAddress = postback.RecieverAddress
                        OrderId    = orderid,
                        CustId     = usrId,
                        OrderTotal = currentcart.TotalAmount, //cartitem.Price,
                        OrderTime  = DateTime.Now,
                    };
                    ////加其入Orders資料表後,儲存變更
                    db1.OrderInfoes.Add(order);
                    db1.SaveChanges();

                    //var q2 = (from s in db.OrderInfoes
                    //          orderby s.OrderId descending
                    //          select s.OrderId).FirstOrDefault();
                    //int orderid = q2 + 1;
                    //取得購物車中OrderDetai物件
                    //var orderDetails = currentcart.ToOrderDetail(order.OrderId);

                    var orderDetails = currentcart.ToOrderDetail(orderid);
                    //將其加入OrderDetails資料表後,儲存變更
                    db1.OrderDetails.AddRange(orderDetails);
                    db1.SaveChanges();
                }
                var qTotal = (from s in db.OrderDetails
                              where s.OrderId == orderid
                              select s).ToList();
                int sum = 0;
                foreach (var item in qTotal)
                {
                    sum += item.ProdPrice * item.ProdQuantity;
                }
                //var order = new OrderInfo() {
                //    //    UserId = userId,
                //    //    RecieverName = postback.RecieverName,
                //    //    RecieverPhone = postback.RecieverPhone,
                //    //    RecieverAddress = postback.RecieverAddress
                //    //OrderId =orderId,
                //    CustId = usrId,
                //    OrderTotal = sum, //cartitem.Price,
                //    OrderTime = DateTime.Now,

                //};
                //////加其入Orders資料表後,儲存變更
                //db.OrderInfoes.Add(order);
                //db.SaveChanges();
                //return Content("訂購成功");
                return(RedirectToAction("MyOrder", "Home"));
            }
            return(View(result));
        }
 public int AddMouvement(Mouvement Mouvement)
 {
     Context.Mouvement.Add(Mouvement);
     Context.SaveChanges();
     return(Context.Mouvement.Add(Mouvement).Id);
 }
Esempio n. 19
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                members member = this.member;

                if (string.IsNullOrEmpty(this.txtNum.Text) || this.txtNum.Text == "0")
                {
                    MessageBox.Show("請輸入賣出張數!!");
                    this.txtMoney.Text = "0";
                    return;
                }
                else if (int.Parse(this.txtNum.Text) > int.Parse(buttonRow.Cells[6].Value.ToString()))
                {
                    MessageBox.Show("賣出張數超出庫存張數@@,請重新輸入!!");
                    this.txtNum.Text   = "";
                    this.txtMoney.Text = "0";
                    return;
                }
                else
                {
                    MessageBox.Show("賣出成功!!");
                }

                //賣出張數,修改資料表
                if (int.Parse(this.txtNum.Text) == int.Parse(buttonRow.Cells[6].Value.ToString()))
                {
                    stocksave save = db.stocksave.AsEnumerable().Where(s => s.證券代號 == buttonRow.Cells[3].Value.ToString() && s.account == member.account).FirstOrDefault();
                    datamodel.Delete(save);
                    stockremain remain = db.stockremain.AsEnumerable().Where(r => r.證券代號 == buttonRow.Cells[3].Value.ToString() && r.account == member.account).FirstOrDefault();
                    datamodel.Delete(remain);
                }
                else if (int.Parse(this.txtNum.Text) < int.Parse(buttonRow.Cells[6].Value.ToString()))
                {
                    stocksave save = db.stocksave.AsEnumerable().Where(s => s.證券代號 == buttonRow.Cells[3].Value.ToString() && s.account == member.account).FirstOrDefault();

                    datamodel.Updatestocksave(save, int.Parse(this.txtNum.Text));

                    stockremain remainsave = db.stockremain.AsEnumerable().Where(r => r.證券代號 == buttonRow.Cells[3].Value.ToString() && r.account == member.account).FirstOrDefault();
                    datamodel.Updatestockremain(remainsave, int.Parse(this.txtNum.Text));
                }

                double remainmoney = (double)member.bankmoney + double.Parse(txtMoney.Text);

                member.bankmoney = (int)remainmoney;
                var mem = (from m in db.members
                           where m.account == member.account
                           select m).FirstOrDefault();

                if (mem == null)
                {
                    return;
                }
                mem.bankmoney = member.bankmoney;
                db.SaveChanges();

                //frmHomePage傳值
                FrmHomePage frmHomePage = this.frmHomePage;
                frmHomePage.lblbankmoney.Text = member.bankmoney.ToString();
                frmHomePage.lblmoney.Text     = member.bankmoney.ToString();
                frmHomePage.lblbank.Text      = member.bankmoney.ToString();

                //frmHomePage.dataGridView3.DataSource = null;
                //frmHomePage.dataGridView4.DataSource = null;
                frmHomePage.dataGridView4.DataSource            = db.stockremain.Where(s => s.account == member.account).ToList();
                frmHomePage.dataGridView4.Columns["id"].Visible = false;
                frmHomePage.dataGridView3.DataSource            = db.stocksave.Where(s => s.account == member.account).ToList();
                frmHomePage.dataGridView3.Columns["id"].Visible = false;

                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 20
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                //member傳值
                members member = this.member;

                if (string.IsNullOrEmpty(this.txtNum.Text) || this.txtNum.Text == "0")
                {
                    MessageBox.Show("請輸入購買張數!!");
                    this.txtMoney.Text = "0";
                    return;
                }
                else if (double.Parse(txtMoney.Text) > member.bankmoney)
                {
                    MessageBox.Show("買進總金額超過帳戶金額QQ,請重新輸入!!");
                    this.txtNum.Text   = "";
                    this.txtMoney.Text = "0";
                    return;
                }
                else
                {
                    MessageBox.Show("買入成功!!");
                }

                double remainmoney = (double)member.bankmoney - double.Parse(txtMoney.Text);

                member.bankmoney = (int)remainmoney;
                var mem = (from m in db.members
                           where m.account == member.account
                           select m).FirstOrDefault();

                if (mem == null)
                {
                    return;
                }
                mem.bankmoney = member.bankmoney;
                db.SaveChanges();

                //frmHomePage傳值
                FrmHomePage frmHomePage = this.frmHomePage;
                frmHomePage.lblbankmoney.Text = member.bankmoney.ToString();
                frmHomePage.lblmoney.Text     = member.bankmoney.ToString();
                frmHomePage.lblbank.Text      = member.bankmoney.ToString();

                //存入我的庫存 stocksave
                stock.account = this.txtAccount.Text;
                stock.證券代號    = this.txtStocknum.Text;
                stock.證券名稱    = this.txtStockName.Text;
                stock.買進價格    = this.txtPrice.Text;
                stock.張數      = this.txtNum.Text;
                stock.總金額     = this.txtMoney.Text;

                db.stocksave.Add(stock);

                db.SaveChanges();


                //取得收盤價,存入未實現損益
                var price = (from d in db.data
                             join s in db.stocksave.Where(s => s.account == member.account)
                             on d.證券代號 equals s.證券代號
                             select d.收盤價).ToList();

                stockRemain.account = member.account;
                stockRemain.證券代號    = stock.證券代號;
                stockRemain.證券名稱    = stock.證券名稱;
                stockRemain.成交均價    = stock.買進價格;
                stockRemain.張數      = stock.張數;
                stockRemain.持有成本    = stock.總金額;
                for (int i = 0; i < price.Count(); i++)
                {
                    var code = (from d in db.data
                                join s in db.stocksave.Where(s => s.account == member.account)
                                on d.證券代號 equals s.證券代號
                                select d.證券代號).ToList();
                    if (stockRemain.證券代號 == code[i])
                    {
                        stockRemain.現價 = price[i].ToString();
                    }
                }

                stockRemain.現值    = (double.Parse(stockRemain.現價) * double.Parse(stock.張數.ToString()) * number).ToString();
                stockRemain.預估收入  = (double.Parse(stockRemain.現價) * double.Parse(stock.張數.ToString()) * number).ToString();
                stockRemain.預估損益  = (double.Parse(stockRemain.預估收入) - double.Parse(stockRemain.持有成本)).ToString();
                stockRemain.預估獲利率 = ((double.Parse(stockRemain.預估損益) / double.Parse(stockRemain.持有成本)) * 100).ToString("f2") + "%";

                db.stockremain.Add(stockRemain);
                db.SaveChanges();

                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }