Beispiel #1
0
        public ActionResult Create(orderentry NewOrder)
        {
            try
            {
                //var order = new OrderTB
                //{
                //    CustomerId = NewOrder.CustomerId,
                //    Date = Convert.ToDateTime(NewOrder.Date),
                //    TotalAmount=NewOrder.TotalAmount

                //};
                //var orderdetail = new OrderDetailTB();
                //using (var context = new ProductsDataContext())
                //{
                //    context.OrderTBs.InsertOnSubmit(order);
                //    orderdetail.OrderId = order.OrderId;
                //    context.OrderDetailTBs.InsertOnSubmit(orderdetail);
                //    //etc add your other classes
                //    context.SubmitChanges();

                //}
                // TODO: Add insert logic here


                OrderTB order = new OrderTB();



                order.CustomerId  = NewOrder.CustomerId;
                order.Date        = Convert.ToDateTime(NewOrder.Date);
                order.TotalAmount = NewOrder.TotalAmount;



                objorder.OrderTBs.InsertOnSubmit(order);

                objorder.SubmitChanges();
                int latestid = order.OrderId;

                OrderDetailTB odetail = new OrderDetailTB();

                odetail.ProductId = NewOrder.ProductId;
                odetail.OrderId   = latestid;
                odetail.Rate      = NewOrder.Rate;
                odetail.Qty       = NewOrder.Qty;

                objorder.OrderDetailTBs.InsertOnSubmit(odetail);
                objorder.SubmitChanges();

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(View(ex.ToString()));
            }
        }
 public ActionResult Create(ProductsTB NewProduct)
 {
     try
     {
         // TODO: Add insert logic here
         objProduct.ProductsTBs.InsertOnSubmit(NewProduct);
         objProduct.SubmitChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Beispiel #3
0
        public ActionResult Create(CustomerTB cust)
        {
            try
            {
                objcust.CustomerTBs.InsertOnSubmit(cust);
                objcust.SubmitChanges();
                // TODO: Add insert logic here

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #4
0
    public int SaveChanges(bool IsNewRecord)
    {
        Products ObjTable;

        if (IsNewRecord)
        {
            ObjTable = new Products();
            dataContext.Products.InsertOnSubmit(ObjTable);
        }
        else
        {
            ObjTable = dataContext.Products.Single(p => p.Code.Equals(this.Code));
        }
        try
        {
            #region Save Controls
            string BaseID = this.ToString().Substring(3, this.ToString().Length - 3);
            Tools  tools  = new Tools();
            tools.AccessList = tools.GetAccessList(BaseID);
            foreach (WebControl wc in ObjectList)
            {
                if ((wc as AKP.Web.Controls.Common.ICustomControlsBase).DisplayMode == AKP.Web.Controls.Common.EnmDisplayMode.EditMode)
                {
                    string       Property     = wc.ID.Substring(3, wc.ID.Length - 3);
                    PropertyInfo pi           = ObjTable.GetType().GetProperty(Property);
                    string       FullPropName = BaseID + "." + Property;
                    if (tools.HasAccess("Edit", BaseID + "." + Property))
                    {
                        pi.SetValue(ObjTable, Tools.GetControlValue(wc), new object[] { });
                    }
                }
            }
            #endregion

            if (tools.HasAccess("Edit", "Products"))
            {
                dataContext.SubmitChanges();
            }
        }
        catch (Exception exp)
        {
            throw exp;
        }

        return(ObjTable.Code);
    }
        public static void Initialize()
        {
            using (var dc = new ProductsDataContext(ProductsDataContext.ConnectionString))
            {
                //dc.DeleteDatabase();
                if (dc.DatabaseExists() == false)
                {
                    dc.CreateDatabase();

                    dc.SubmitChanges();
                }
            }
        }
 protected void Button3_Click(object sender, EventArgs e)
 {
     pdc = new ProductsDataContext();
     Products newprod = new Products();
     newprod.ProductName = "新添加的一项产品";
     newprod.SupplierID = 13;
     newprod.CategoryID = 5;
     newprod.UnitPrice = 57;
     newprod.UnitsInStock = 13;
     newprod.ReorderLevel = 15;
     //这里使用InsertOnSubmit将新创建的对象添插入到集合中。
     pdc.Products.InsertOnSubmit(newprod);
     //向数据库提交更改
     pdc.SubmitChanges();
     //再次绑定
     GridView1.DataSource = GetQuery(50);
     GridView1.DataBind();
 }
Beispiel #7
0
    protected void Button4_Click(object sender, EventArgs e)
    {
        pdc = new ProductsDataContext();
        IEnumerable <Products> query = from product in pdc.Products
                                       where product.ProductID == 79
                                       select product;

        //可以使用DeleteOnSubmit一次删除一条记录
        //foreach (Products prod in query)
        //{
        //    pdc.Products.DeleteOnSubmit(prod);
        //}
        //也可以使用DeleteAllOnSubmit一次删除一批记录
        pdc.Products.DeleteAllOnSubmit(query);
        pdc.SubmitChanges();
        //再次绑定
        GridView1.DataSource = GetQuery(50);
        GridView1.DataBind();
    }
Beispiel #8
0
    protected void Button3_Click(object sender, EventArgs e)
    {
        pdc = new ProductsDataContext();
        Products newprod = new Products();

        newprod.ProductName  = "新添加的一项产品";
        newprod.SupplierID   = 13;
        newprod.CategoryID   = 5;
        newprod.UnitPrice    = 57;
        newprod.UnitsInStock = 13;
        newprod.ReorderLevel = 15;
        //这里使用InsertOnSubmit将新创建的对象添插入到集合中。
        pdc.Products.InsertOnSubmit(newprod);
        //向数据库提交更改
        pdc.SubmitChanges();
        //再次绑定
        GridView1.DataSource = GetQuery(50);
        GridView1.DataBind();
    }
Beispiel #9
0
 //修改数据
 protected void Button2_Click(object sender, EventArgs e)
 {
     foreach (Products prod in GetQuery(50))
     {
         prod.UnitPrice += (decimal)0.5;
     }
     try
     {
         //使用DataContext的SupmitChange提交更改
         pdc.SubmitChanges();
     }
     catch (System.Data.Linq.ChangeConflictException ex)
     {
         Response.Write(string.Format("出现更新冲突!错误消息是:{0}", ex.Message));
     }
     //再次绑定
     GridView1.DataSource = GetQuery(50);
     GridView1.DataBind();
 }
 protected void Button4_Click(object sender, EventArgs e)
 {
     pdc = new ProductsDataContext();
     IEnumerable<Products> query = from product in pdc.Products
                                  where product.ProductID == 79
                                  select product;
     //可以使用DeleteOnSubmit一次删除一条记录
     //foreach (Products prod in query)
     //{
     //    pdc.Products.DeleteOnSubmit(prod);
     //}
     //也可以使用DeleteAllOnSubmit一次删除一批记录
     pdc.Products.DeleteAllOnSubmit(query);
     pdc.SubmitChanges();
     //再次绑定
     GridView1.DataSource = GetQuery(50);
     GridView1.DataBind();
 }