public async Task <IActionResult> Edit(int id, [Bind("IdoutOrder,IdShippingCompany,IdStore,IdEmployee,Date")] OutOrder outOrder) { if (id != outOrder.IdoutOrder) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(outOrder); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OutOrderExists(outOrder.IdoutOrder)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IdEmployee"] = new SelectList(_context.Employee, "Idemployee", "name", outOrder.IdEmployee); ViewData["IdShippingCompany"] = new SelectList(_context.ShippingCompany, "IdshippingCompany", "Namecompany", outOrder.IdShippingCompany); ViewData["IdStore"] = new SelectList(_context.Store, "Idstore", "Idstore", outOrder.IdStore); return(View(outOrder)); }
public async Task <IActionResult> Create([Bind("IdoutOrder,IdShippingCompany,IdStore,IdEmployee,Date")] OutOrder outOrder) { if (ModelState.IsValid) { _context.Add(outOrder); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IdEmployee"] = new SelectList(_context.Employee, "Idemployee", "name", outOrder.IdEmployee); ViewData["IdShippingCompany"] = new SelectList(_context.ShippingCompany, "IdshippingCompany", "Namecompany", outOrder.IdShippingCompany); ViewData["IdStore"] = new SelectList(_context.Store, "Idstore", "Idstore", outOrder.IdStore); return(View(outOrder)); }
public static string InsertOutboundOrder(OutOrder ord) { string res = ""; string sql = ""; int headID; int msgID; if (!string.IsNullOrEmpty(ord.AddrName)) { ord.AddrName = new string(ord.AddrName.Where(c => !char.IsPunctuation(c)).ToArray()).ToUpper().Trim(); } if (!string.IsNullOrEmpty(ord.AddrPhone)) { ord.AddrPhone = new string(ord.AddrPhone.Where(c => char.IsDigit(c)).ToArray()); if (ord.AddrPhone.Length == 10) { ord.AddrPhone = "8" + ord.AddrPhone; } } try { SqlConnection con = new SqlConnection(connStr); con.Open(); // insert header into tblOutboundOrder using (SqlCommand cmd = new SqlCommand()) { sql = sqlHeader02(); sql += (ord.OrderNo == null) ? "NULL," : "N'" + ord.OrderNo + "',"; sql += (ord.OrderDate == null) ? "NULL," : "N'" + ord.OrderDate + "',"; sql += (ord.OrderType == null) ? "NULL," : "N'" + ord.OrderType + "',"; sql += ord.Sku_Type.ToString() + ","; sql += (ord.OwnerID == null) ? "NULL," : "N'" + ord.OwnerID + "',"; sql += (ord.DateScheduled == null) ? "NULL," : "N'" + ord.DateScheduled + "',"; sql += (ord.ConsigneeID == null) ? "NULL," : "N'" + ord.ConsigneeID + "',"; sql += (ord.AddrName == null) ? "NULL," : "N'" + ord.AddrName + "',"; sql += (ord.AddrCountry == null) ? "NULL," : "N'" + ord.AddrCountry + "',"; sql += (ord.AddrPostIndx == null) ? "NULL," : "N'" + ord.AddrPostIndx + "',"; sql += (ord.AddrRegion == null) ? "NULL," : "N'" + ord.AddrRegion + "',"; sql += (ord.AddrCity == null) ? "NULL," : "N'" + ord.AddrCity.strTrim(20) + "',"; sql += (ord.AddrAddress == null) ? "NULL," : "N'" + ord.AddrAddress + "',"; sql += (ord.AddrPhone == null) ? "NULL," : "N'" + ord.AddrPhone + "',"; sql += (ord.AddrFax == null) ? "NULL," : "N'" + ord.AddrFax + "',"; sql += (ord.AddrEmail == null) ? "NULL," : "N'" + ord.AddrEmail + "',"; sql += (ord.AddrOrdCode == null) ? "NULL," : "N'" + ord.AddrOrdCode + "',"; sql += (ord.Notes == null) ? "NULL," : "N'" + ord.Notes + "',"; sql += (ord.CarrierCode == null) ? "NULL," : "N'" + ord.CarrierCode + "',"; sql += ord.IsAddDocs + ","; sql += (ord.Move == null) ? "NULL," : "N'" + ord.Move + "',"; sql += (ord.Req == null) ? "NULL," : "N'" + ord.Req + "',"; sql += (ord.PickSlip == null) ? "NULL," : "N'" + ord.PickSlip + "',"; sql += (ord.PkpTerminalNo == null) ? "NULL," : "N'" + ord.PkpTerminalNo + "',"; sql += (ord.PkpTerminalName == null) ? "NULL," : "N'" + ord.PkpTerminalName + "',"; sql += (ord.PkpTerminalAddress == null) ? "NULL," : "N'" + ord.PkpTerminalAddress + "',"; sql += (ord.DeliveryNo == null) ? "NULL," : "N'" + ord.DeliveryNo + "',"; sql += ord.OrderAmount.ToString() + ","; sql += ord.IsApproved.ToString() + ","; sql += (ord.OwnerDeptID == null) ? "NULL," : "N'" + ord.OwnerDeptID + "',"; sql += ord.temperatureControl.ToString() + ","; sql += (ord.ClientID == null) ? "NULL," : "N'" + ord.ClientID + "',"; sql += (ord.Status == null) ? "NULL," : "N'" + ord.Status + "'"; sql += "); select * from @tID;"; cmd.CommandType = CommandType.Text; cmd.Connection = con; cmd.CommandText = sql; if (!int.TryParse(cmd.ExecuteScalar().ToString(), out headID)) { throw new Exception("Wrong Header ID"); } } // insert details into tblOutboundOrderDetails if (ord.Items.Item != null) { foreach (OutOrderItemsItem item in ord.Items.Item) { int UOM_SET = 0; int _qtyUOM = 1; if (ord.OwnerID == "HERBALIFE") { item.SKU = CheckSKU(item.SKU, ord.OrderType); if ((item.UnitCode != null) && (item.UnitCode != "PC")) { try { using (SqlCommand cmd1 = new SqlCommand()) { cmd1.CommandType = CommandType.StoredProcedure; cmd1.Connection = con; cmd1.CommandText = "[dbo].[ANT_FIL_UOMtoPC]"; //cmd1.Parameters.AddWithValue("@SKU", item.SKU); cmd1.Parameters.AddWithValue("@SKU", item.SKU); cmd1.Parameters.AddWithValue("@SKUtype", 2); cmd1.Parameters.AddWithValue("@UoM", item.UnitCode); var r1 = cmd1.ExecuteScalar(); if (r1 == null) { throw (new Exception("Error: No unit " + item.UnitCode + " for item " + item.SKU)); } else { _qtyUOM = Convert.ToInt32((decimal)r1); if (_qtyUOM > 0) { UOM_SET = 1; } else { throw (new Exception("Error: No unit " + item.UnitCode + " for item " + item.SKU)); } } } } catch (Exception ex1) { EventLog.WriteEntry("BT_InsertOutboundOrder", ex1.Message, EventLogEntryType.Error); res += ex1.Message; _qtyUOM = 1; UOM_SET = 0; } } } using (SqlCommand cmd = new SqlCommand()) { sql = "INSERT INTO [ExchangeDB].[dbo].[tblOutboundOrderDetail] ([HeaderID],[UnitCode],[Qty],[SKU],[LOT],[DateExp],[DateProd],[RevNo],[UOM_SET]) VALUES ("; sql += headID.ToString() + ","; if (UOM_SET == 1) { sql += "N'PC',"; } else { sql += (item.UnitCode == null) ? "NULL," : "N'" + item.UnitCode + "',"; } sql += (item.Qty * _qtyUOM).ToString() + ","; sql += (item.SKU == null) ? "NULL," : "N'" + item.SKU + "',"; sql += (item.LOT == null) ? "NULL," : "N'" + item.LOT + "',"; sql += (item.DateExp == null) ? "NULL," : "N'" + item.DateExp + "',"; sql += (item.DateProd == null) ? "NULL," : "N'" + item.DateProd + "',"; sql += (item.RevNo == null) ? "NULL," : "N'" + item.RevNo + "',"; sql += UOM_SET.ToString() + ")"; cmd.CommandType = CommandType.Text; cmd.Connection = con; cmd.CommandText = sql; int r = cmd.ExecuteNonQuery(); if (r != 1) { res += "Item:" + item.SKU + " was not added!"; } } } } // insert new message into ExMsg using (SqlCommand cmd = new SqlCommand()) { sql = "declare @tID table (ID int);INSERT INTO [ExchangeDB].[dbo].[ExMsg] ([TypeID],[ObjectID],[HighPriority]) output inserted.ID into @tID VALUES (9,"; sql += headID.ToString() + ",0); select * from @tID;"; cmd.CommandType = CommandType.Text; cmd.Connection = con; cmd.CommandText = sql; if (!int.TryParse(cmd.ExecuteScalar().ToString(), out msgID)) { throw new Exception("Wrong Message ID"); } } // insert status message into ExMsgStatus using (SqlCommand cmd = new SqlCommand()) { sql = "INSERT INTO [ExchangeDB].[dbo].[ExMsgStatus] ([ExMsgID],[SystemID],[Status],[StatusDateTime],[ErrMsg]) VALUES("; sql += msgID.ToString() + ",0,0,GETDATE(),N'" + res + "')"; //sql += DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "'; cmd.CommandType = CommandType.Text; cmd.Connection = con; cmd.CommandText = sql; int r = cmd.ExecuteNonQuery(); if (r != 1) { res += "Status for message:" + msgID.ToString() + " was not added!"; } } } catch (Exception ex) { res += "ERROR InsertOutboundOrder() \r\nOrderNo " + ord.OrderNo + "\r\n" + ex.Message; EventLog.WriteEntry("BT_InsertOutboundOrder", res, EventLogEntryType.Error); } return(res); }