public Order_Master GetOrder_Master(SqlConnection con, int OrderMasterID) { DataTable dt = new DataTable(); Order_Master obOrderMaster = new Order_Master(); try { SqlDataAdapter da = new SqlDataAdapter("select * from Order_Master WHERE OrderMID=@OrderMID ", con); da.SelectCommand.Parameters.Add("@OrderMID", SqlDbType.Int).Value = OrderMasterID; da.Fill(dt); da.Dispose(); if (dt.Rows.Count == 0) { return(null); } obOrderMaster.OrderMID = dt.Rows[0].Field <int>("OrderMID"); obOrderMaster.OrderNo = dt.Rows[0].Field <string>("OrderNo"); obOrderMaster.LedgerNo = dt.Rows[0].Field <object>("LedgerNo") == DBNull.Value || dt.Rows[0].Field <object>("LedgerNo") == null ? "" : dt.Rows[0].Field <string>("LedgerNo"); obOrderMaster.OrderDate = dt.Rows[0].Field <DateTime>("OrderDate"); obOrderMaster.OrderValue = Convert.ToDouble(dt.Rows[0].Field <object>("OrderValue")); obOrderMaster.TotalOrderQty = dt.Rows[0].Field <object>("TotalOrderQty") == DBNull.Value ? 0 : Convert.ToDouble(dt.Rows[0].Field <object>("TotalOrderQty")); obOrderMaster.UnitID = dt.Rows[0].Field <object>("UnitID") == DBNull.Value || dt.Rows[0].Field <object>("UnitID") == null ? 0 : dt.Rows[0].Field <int>("UnitID"); obOrderMaster.FactoryID = dt.Rows[0].Field <object>("FactoryID") == DBNull.Value || dt.Rows[0].Field <object>("FactoryID") == null ? -1 : dt.Rows[0].Field <int>("FactoryID"); obOrderMaster.DeliveryDate = dt.Rows[0].Field <object>("DeliveryDate") == DBNull.Value || dt.Rows[0].Field <object>("DeliveryDate") == null ? new DateTime(1900, 1, 1) : dt.Rows[0].Field <DateTime>("DeliveryDate"); obOrderMaster.CustomerID = dt.Rows[0].Field <int>("CustomerID"); obOrderMaster.CurrencyID = dt.Rows[0].Field <object>("CurrencyID") == DBNull.Value || dt.Rows[0].Field <object>("CurrencyID") == null ? -1 : dt.Rows[0].Field <int>("CurrencyID"); obOrderMaster.Buyer_ref = dt.Rows[0].Field <string>("Buyer_ref"); } catch (Exception ex) { throw ex; } return(obOrderMaster); }
public ActionResult DeleteConfirmed(int id) { Order_Master order_Master = db.Order_Master.Find(id); db.Order_Master.Remove(order_Master); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "Id,UserId,Comments,CreatedBy,CreatedDate,CustomerId,Discount,UpdatedBy,UpdatedDate")] Order_Master order_Master, List <Order_Details> order_Details) { if (ModelState.IsValid) { string UserId = System.Web.HttpContext.Current.User.Identity.Name; order_Master.CreatedBy = UserId; string ordNo = "Ord00000001"; int? max = (from o in db.Order_Master select(int?) o.Id).Max(); if (max == 0 || max == null) { max = 1; ordNo = max.ToString().PadLeft(5, '0'); ordNo = "ORD" + ordNo; } else { int?nextmax = max + 1; ordNo = nextmax.ToString().PadLeft(5, '0'); ordNo = "ORD" + ordNo;; } order_Master.Order_No = ordNo; order_Master.CreatedDate = DateTime.Now; db.Order_Master.Add(order_Master); db.SaveChanges(); int id = db.Order_Master.FirstOrDefault(s => s.Order_No == order_Master.Order_No).Id; int OrderLine = 1; foreach (var detail in order_Details) { detail.OrderId = id; detail.Order_Line = OrderLine; detail.CreatedBy = UserId; detail.CreatedDate = DateTime.Now; Stock stock = db.Stocks.Find(detail.StockId); if (stock != null) { stock.Qty = stock.Qty - detail.Quantity; if (stock.Qty < 0) { stock.Qty = 0; } db.Entry(stock).State = EntityState.Modified; } OrderLine++; } db.Order_Details.AddRange(order_Details); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(order_Master)); }
public ActionResult Edit([Bind(Include = "Id,UserId,Comments,CreatedBy,CreatedDate,CustomerId,Discount,UpdatedBy,UpdatedDate")] Order_Master order_Master) { if (ModelState.IsValid) { db.Entry(order_Master).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserId = new SelectList(db.AspNetUsers, "Id", "Email", order_Master.UserId); return(View(order_Master)); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request.QueryString["id"] != null) { A1 = new Order_Master(); int ID = Convert.ToInt32(Request.QueryString["id"]); show_data(ID); } } }
// GET: Orders/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Order_Master order_Master = db.Order_Master.Find(id); if (order_Master == null) { return(HttpNotFound()); } return(View(order_Master)); }
// GET: Orders/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Order_Master order_Master = db.Order_Master.Find(id); if (order_Master == null) { return(HttpNotFound()); } ViewBag.UserId = new SelectList(db.AspNetUsers, "Id", "Email", order_Master.UserId); return(View(order_Master)); }
public IHttpActionResult Checkout(Order_Master O) { var DB = new AngularDemoEntities(); try { var user_id = User.Identity.GetUserId(); O.OrderDate = DateTime.Now; O.DeliveryDate = DateTime.Now.AddDays(5); O.UserID = user_id; DB.Order_Master.Add(O); DB.SaveChanges(); int InsertedOrderID = O.OrderID; List <Cart_Master> C = DB.Cart_Master.Where(x => x.UserID == user_id).ToList(); if (C.Count > 0) { foreach (var i in C) { OrderItems_Master OI = new OrderItems_Master { OrderID = InsertedOrderID, ProductID = Convert.ToInt32(i.ProductID), Quantity = Convert.ToDecimal(i.ProductQuantity), UserID = i.UserID, UnitPrice = Convert.ToDecimal(i.Product_Master.ProductPrice) }; DB.OrderItems_Master.Add(OI); DB.Cart_Master.Remove(i); DB.SaveChanges(); } return(Ok("success")); } else { return(Ok("Some problem")); } } catch (Exception ex) { throw ex.InnerException; } }
public static string PlaceOrder(OrderViewModel model) { int O_ID = 0; try { PAWDStoreEntities context = new PAWDStoreEntities(); int UserID = (HttpContext.Current.Session["User"] as AdminLoginMaster).User_ID; Random generator = new Random(); string Order_NO = generator.Next(0, 999999).ToString("D6"); if (model.User_Address_ID == 0) { var address = new User_Address_Master { BName = model.BName, BAddress = model.BAddress, BCity = model.BCity, BEmail = model.BEmail, BMobile = model.BMobile, BState = model.BState, BZipcode = model.BZipcode, CreatedDate = DateTime.Now, SName = !string.IsNullOrEmpty(model.SName) ? model.SName : model.BName, SCity = !string.IsNullOrEmpty(model.SCity) ? model.SCity : model.BCity, SAddress = !string.IsNullOrEmpty(model.SAddress) ? model.SAddress : model.BAddress, SEmail = !string.IsNullOrEmpty(model.SEmail) ? model.SEmail : model.BEmail, SMobile = !string.IsNullOrEmpty(model.SMobile) ? model.SMobile : model.BMobile, SState = !string.IsNullOrEmpty(model.SState) ? model.SState : model.BState, SZipcode = !string.IsNullOrEmpty(model.SZipcode) ? model.SZipcode : model.BZipcode, User_ID = UserID }; context.User_Address_Master.Add(address); context.SaveChanges(); model.User_Address_ID = address.User_Address_ID; } var obj = new Order_Master { Order_No = Order_NO, Order_Status = "Processing", Order_Type = model.paymentMethod, CreatedDate = DateTime.Now, User_Address_ID = model.User_Address_ID, User_ID = UserID }; context.Order_Master.Add(obj); context.SaveChanges(); var CartItem = context.Cart_Master.Where(x => x.User_ID == UserID).ToList(); var Items = CartItem.Select(x => new Order_Item_Master() { Order_ID = obj.Order_ID, Quantity = x.Quantity, Price = x.Product_Master.Product_Price, Size = x.Size, Product_ID = x.Product_ID }).ToList(); context.Order_Item_Master.AddRange(Items); context.Cart_Master.RemoveRange(CartItem); context.SaveChanges(); O_ID = obj.Order_ID; SendMail.SendConfirmationMail(model, obj, Items); return(JsonConvert.SerializeObject(obj.Order_ID)); } catch (Exception ex) { return(JsonConvert.SerializeObject(O_ID)); } }
public void show_data(int ID) { A_Handler = new Order_MasterHandler(); A1 = new Order_Master(); A1 = A_Handler.GetOrder_MasterDetails(ID); txtOm_id.Text = A1.Om_id.ToString(); ddlReg_id.Text = A1.Reg_id.ToString(); ddlMem_id.Text = A1.Mem_id.ToString(); txtOm_number.Text = A1.Om_number.ToString(); txtOm_date.Text = A1.Om_date.ToString(); txtOrder_bill_no.Text = A1.Order_bill_no.ToString(); txtOrd_date.Text = A1.Ord_date.ToString(); txtSup_name.Text = A1.Sup_name.ToString(); txtSup_address.Text = A1.Sup_address.ToString(); txtSup_city.Text = A1.Sup_city.ToString(); txtSup_mobile.Text = A1.Sup_mobile.ToString(); txtSup_email.Text = A1.Sup_email.ToString(); txtGross_amt.Text = A1.Gross_amt.ToString(); txtDis_amt.Text = A1.Dis_amt.ToString(); txtNet_amt.Text = A1.Net_amt.ToString(); ddlPaid.Text = A1.Is_paid.ToString(); txtUser1.Text = A1.User1.ToString(); ddlStatus.Text = A1.Status.ToString(); btnSubmit.Text = "Update"; btnReset.Text = "Cancel"; if (Request.QueryString["action"] == "del") { Label1.Text = "Are U Sure, U want to Delete a Record ?"; txtOm_id.ReadOnly = false; ddlReg_id.Enabled = false; ddlMem_id.Enabled = false; txtOm_number.ReadOnly = false; txtOm_date.ReadOnly = false; txtOrder_bill_no.ReadOnly = false; txtOrd_date.ReadOnly = false; txtSup_name.ReadOnly = false; txtSup_address.ReadOnly = false; txtSup_city.ReadOnly = false; txtSup_mobile.ReadOnly = false; txtSup_email.ReadOnly = false; txtGross_amt.ReadOnly = false; txtDis_amt.ReadOnly = false; txtNet_amt.ReadOnly = false; ddlPaid.Enabled = false; txtUser1.ReadOnly = false; ddlStatus.Enabled = false; btnSubmit.Text = "Delete"; } }
protected void btnSubmit_Click(object sender, EventArgs e) { A_Handler = new Order_MasterHandler(); A1 = new Order_Master(); //A1.Om_id = Convert.ToInt32(txtOm_id.Text); A1.Reg_id = Convert.ToInt32(ddlReg_id.SelectedValue); A1.Mem_id = Convert.ToInt32(ddlMem_id.SelectedValue); A1.Om_number = Convert.ToInt32(txtOm_number.Text); A1.Om_date = Convert.ToDateTime(txtOm_date.Text); A1.Order_bill_no = Convert.ToInt32(txtOrder_bill_no.Text); A1.Ord_date = Convert.ToDateTime(txtOrd_date.Text); A1.Sup_name = txtSup_name.Text; A1.Sup_address = txtSup_address.Text; A1.Sup_city = txtSup_city.Text; A1.Sup_mobile = Convert.ToDecimal(txtSup_mobile.Text); A1.Sup_email = txtSup_email.Text; A1.Gross_amt = Convert.ToDecimal(txtGross_amt.Text); A1.Dis_amt = Convert.ToDecimal(txtDis_amt.Text); A1.Net_amt = Convert.ToDecimal(txtNet_amt.Text); A1.Is_paid = ddlPaid.Text; A1.User1 = txtUser1.Text; A1.Status = Convert.ToInt32(ddlStatus.Text); if (btnSubmit.Text == "Submit") { bool B = A_Handler.AddNewOrder_Master(A1); if (B == true) { Label1.Text = "Record Inserted"; MSG = "Record Inserted"; } else { Label1.Text = "Record Not Inserted"; MSG = "Record Not Inserted"; } } else if (btnSubmit.Text == "Update") { A1.Om_id = Convert.ToInt32(txtOm_id.Text); bool B = A_Handler.UpdateOrder_Master(A1); if (B == true) { Label1.Text = "Record Updated"; MSG = "Record Not Updated"; } else { Label1.Text = "Record Not Updated"; MSG = "Record Not Updated"; } } else if (btnSubmit.Text == "Delete") { A1.Om_id = Convert.ToInt32(txtOm_id.Text); bool B = A_Handler.DeleteOrder_Master(A1); if (B == true) { Label1.Text = "Record Deleted"; MSG = "Record Deleted"; } else { Label1.Text = "Record Not Deleted"; MSG = "Record Not Deleted"; } } //Response.Redirect("~/ADMIN/Order_Master_list.aspx?msg="+MSG); }
// This fuction does not contain any business logic, it simply returns the // list of order_masters, we can put some logic here if needed public bool AddNewOrder_Master(Order_Master b1) { return(order_masterDb.AddNewOrder_Master(b1)); }
// This fuction does not contain any business logic, it simply returns the // list of order_masters, we can put some logic here if needed public bool DeleteOrder_Master(Order_Master b1) { return(order_masterDb.DeleteOrder_Master(b1)); }
// This fuction does not contain any business logic, it simply returns the // list of order_masters, we can put some logic here if needed public bool UpdateOrder_Master(Order_Master b1) { return(order_masterDb.UpdateOrder_Master(b1)); }
public int saveUpdateOrderMaster(Order_Master obOrder_Master, SqlConnection con) { SqlCommand com = null; SqlTransaction trans = null; int lastID = 0; try { com = new SqlCommand(); trans = con.BeginTransaction("11"); com.Transaction = trans; com.Connection = con; com.CommandText = "spSaveUpdateOrder_Master"; com.CommandType = CommandType.StoredProcedure; com.Parameters.Add("@OrderMID", SqlDbType.Int).Value = obOrder_Master.OrderMID; com.Parameters.Add("@OrderNo", SqlDbType.VarChar, 100).Value = obOrder_Master.OrderNo; com.Parameters.Add("@OrderType", SqlDbType.VarChar, 50).Value = obOrder_Master.OrderType; com.Parameters.Add("@OrderDate", SqlDbType.DateTime).Value = obOrder_Master.OrderDate; com.Parameters.Add("@CustomerID", SqlDbType.Int).Value = obOrder_Master.CustomerID; if (obOrder_Master.DeliveryDate == new DateTime(1900, 1, 1)) { com.Parameters.Add("@DeliveryDate", SqlDbType.DateTime).Value = DBNull.Value; } else { com.Parameters.Add("@DeliveryDate", SqlDbType.DateTime).Value = obOrder_Master.DeliveryDate; } if (obOrder_Master.FactoryID <= 0) { com.Parameters.Add("@FactoryID", SqlDbType.Int).Value = DBNull.Value; } else { com.Parameters.Add("@FactoryID", SqlDbType.Int).Value = obOrder_Master.FactoryID; } com.Parameters.Add("@LedgerNo", SqlDbType.VarChar, 100).Value = obOrder_Master.LedgerNo; com.Parameters.Add("@TotalOrderQty", SqlDbType.Money).Value = obOrder_Master.TotalOrderQty; if (obOrder_Master.UnitID <= 0) { com.Parameters.Add("@UnitID", SqlDbType.Int).Value = DBNull.Value; } else { com.Parameters.Add("@UnitID", SqlDbType.Int).Value = obOrder_Master.UnitID; } com.Parameters.Add("@OrderValue", SqlDbType.Money).Value = obOrder_Master.OrderValue; if (obOrder_Master.CurrencyID <= 0) { com.Parameters.Add("@CurrencyID", SqlDbType.Int).Value = DBNull.Value; } else { com.Parameters.Add("@CurrencyID", SqlDbType.Int).Value = obOrder_Master.CurrencyID; } com.Parameters.Add("@CompanyID", SqlDbType.Int).Value = LogInInfo.CompanyID; com.Parameters.Add("@UserID", SqlDbType.Int).Value = LogInInfo.UserID; com.ExecuteNonQuery(); trans.Commit(); if (obOrder_Master.OrderMID == 0) { lastID = ConnectionHelper.GetID(con, "OrderMID", "Order_Master"); } else { lastID = obOrder_Master.OrderMID; } //com.Parameters["@OrderMID"].Value; } catch (Exception ex) { trans.Rollback("11"); throw new Exception("Unable to Save or Update " + ex.Message); } return(lastID); }
public int saveUpdateOrderMaster(Order_Master obOrder_Master, SqlTransaction trans, SqlConnection con) { SqlCommand com = null; int lastID = 0; try { com = new SqlCommand("spSaveUpdateOrder_Master", con, trans); com.CommandType = CommandType.StoredProcedure; com.Parameters.Add("@OrderMID", SqlDbType.Int).Value = obOrder_Master.OrderMID; com.Parameters.Add("@OrderNo", SqlDbType.VarChar, 100).Value = obOrder_Master.OrderNo; com.Parameters.Add("@OrderType", SqlDbType.VarChar, 50).Value = obOrder_Master.OrderType; com.Parameters.Add("@OrderDate", SqlDbType.DateTime).Value = obOrder_Master.OrderDate; com.Parameters.Add("@CustomerID", SqlDbType.Int).Value = obOrder_Master.CustomerID; if (obOrder_Master.DeliveryDate == new DateTime(1900, 1, 1)) { com.Parameters.Add("@DeliveryDate", SqlDbType.DateTime).Value = DBNull.Value; } else { com.Parameters.Add("@DeliveryDate", SqlDbType.DateTime).Value = obOrder_Master.DeliveryDate; } if (obOrder_Master.FactoryID <= 0) { com.Parameters.Add("@FactoryID", SqlDbType.Int).Value = DBNull.Value; } else { com.Parameters.Add("@FactoryID", SqlDbType.Int).Value = obOrder_Master.FactoryID; } com.Parameters.Add("@LedgerNo", SqlDbType.VarChar, 100).Value = obOrder_Master.LedgerNo; com.Parameters.Add("@TotalOrderQty", SqlDbType.Money).Value = obOrder_Master.TotalOrderQty; if (obOrder_Master.UnitID <= 0) { com.Parameters.Add("@UnitID", SqlDbType.Int).Value = DBNull.Value; } else { com.Parameters.Add("@UnitID", SqlDbType.Int).Value = obOrder_Master.UnitID; } com.Parameters.Add("@OrderValue", SqlDbType.Money).Value = obOrder_Master.OrderValue; if (obOrder_Master.CurrencyID <= 0) { com.Parameters.Add("@CurrencyID", SqlDbType.Int).Value = DBNull.Value; } else { com.Parameters.Add("@CurrencyID", SqlDbType.Int).Value = obOrder_Master.CurrencyID; } com.Parameters.Add("@CompanyID", SqlDbType.Int).Value = LogInInfo.CompanyID; com.Parameters.Add("@UserID", SqlDbType.Int).Value = LogInInfo.UserID; com.Parameters.Add("@Rate", SqlDbType.Money).Value = obOrder_Master.Rate; com.Parameters.Add("@Buyer_ref", SqlDbType.VarChar, 500).Value = obOrder_Master.Buyer_ref; com.ExecuteNonQuery(); //trans.Commit(); if (obOrder_Master.OrderMID == 0) { SqlCommand cmd = new SqlCommand("SELECT ISNULL(MAX(OrderMID),0) FROM Order_Master", con, trans); lastID = Convert.ToInt32(cmd.ExecuteScalar()); } else { lastID = obOrder_Master.OrderMID; } } catch (Exception ex) { //trans.Rollback("11"); throw new Exception("Unable to Save or Update " + ex.Message); } return(lastID); }