public ActionResult DeleteConfirmed(int id) { EmployeeOrder employeeOrder = db.EmployeeOrders.Find(id); db.EmployeeOrders.Remove(employeeOrder); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(EmployeeOrder employeeOrder) { if (ModelState.IsValid) { db.Entry(employeeOrder).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(employeeOrder)); }
public static EmployeeOrder Validate(this EmployeeOrder order) { order.orderDescription = order.orderDescription.Trim(); if (order.orderDescription.Length > 50) { order.orderDescription = order.orderDescription.Substring(0, 49); } return(order); }
public ActionResult Create(EmployeeOrder employeeOrder) { if (ModelState.IsValid) { db.EmployeeOrders.Add(employeeOrder); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(employeeOrder)); }
// GET: EmployeeOrders/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } EmployeeOrder employeeOrder = db.EmployeeOrders.Find(id); if (employeeOrder == null) { return(HttpNotFound()); } return(View(employeeOrder)); }
public ActionResult Add(EmployeeOrder order) { //order.eOrderID = context.EmployeeOrders.Max(x => x.eOrderID) + 1; order = order.Validate(); using (var repository = new Repository <EmployeeOrder>()) { if (repository.Add(order)) { repository.Save(); } else { return(HttpNotFound()); } } return(RedirectToAction("Index")); }
public ActionResult UpdateConfirmed(EmployeeOrder order) { if (order == null) { return(HttpNotFound()); } order = order.Validate(); using (var repository = new Repository <EmployeeOrder>()) { if (repository.Update(order)) { repository.Save(); } else { return(HttpNotFound()); } } return(RedirectToAction("Index")); }
public HttpResponseMessage AddOrdersToEmployee(HttpRequestMessage request, JObject objData) { //**** SOURCE URL SAMPLE: http://www.dotnetcurry.com/aspnet/1278/aspnet-webapi-pass-multiple-parameters-action-method return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState.Keys.SelectMany(k => ModelState[k].Errors) .Select(m => m.ErrorMessage).ToArray()); } else { dynamic jsonData = Newtonsoft.Json.JsonConvert.DeserializeObject(objData.ToString()); var employeeIdJson = jsonData.jsonObj.employeeId; var ordersJson = jsonData.jsonObj.orders; List <EmployeeOrder> EmployeeOrderobj = new List <EmployeeOrder>(); foreach (var orderid in ordersJson) { EmployeeOrderViewModel employeeorderVM = new EmployeeOrderViewModel(); EmployeeOrder newemployeeorder = new EmployeeOrder(); newemployeeorder.OrderId = orderid.Id; newemployeeorder.CommissionedEmployeeId = employeeIdJson; _employeeordersRepository.Add(newemployeeorder); _unitOfWork.Commit(); EmployeeOrderobj.Add(newemployeeorder); } IEnumerable <EmployeeOrderViewModel> EmployeeordersVM = Mapper.Map <IEnumerable <EmployeeOrder>, IEnumerable <EmployeeOrderViewModel> >(EmployeeOrderobj); response = request.CreateResponse <IEnumerable <EmployeeOrderViewModel> >(HttpStatusCode.OK, EmployeeordersVM); } return response; })); }
//注文状態を保存する private void SaveOrder_Click(object sender, RoutedEventArgs e) { //貸出 if (isBorrow == 1) { if (DepartmentName.Text != null & DepartmentName.Text != "") { EmployeeOrder empOrderParam = new EmployeeOrder(); empOrderParam.AccountID = AccountNameToSave.Text; if (EquipmentIdTbl.Text == null || EquipmentIdTbl.Text == "") { CustomizeDialog dialog = new CustomizeDialog("取られた設備の情報が削除された!"); dialog.ShowDialog(); } else { SqlConnection thisConnection = new SqlConnection(@"Server=tcp:bmkprojbnsqr01v.database.windows.net,1433;Initial Catalog=DB_BMK;Persist Security Info=False;User ID=bmkDataAdmin;Password=Setsubi2019;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"); using (thisConnection) { try { //sql実施結果 int result = 0; //integerフォーマット変換する int intequipmentID = int.Parse(EquipmentIdTbl.Text); empOrderParam.EquipmentID = intequipmentID; empOrderParam.OrderDate = DateTime.Now; //sqlcommand List <string> sqlCommandList = new List <string>(); // insert command string sql1 = "INSERT INTO dbo.EmployeeOrder (" + " AccountID " + " ,EquipmentID " + " ,OrderDate " + " ) " + " VALUES ( " + " '" + empOrderParam.AccountID + "' " + " ," + empOrderParam.EquipmentID + " ,'" + empOrderParam.OrderDate.ToString() + "'" + " )"; sqlCommandList.Add(sql1); // update command string sql2 = "UPDATE dbo.Equipment " + " SET EquipStatus = " + 0 + " WHERE EquipmentID = " + empOrderParam.EquipmentID; sqlCommandList.Add(sql2); thisConnection.Open(); using (SqlTransaction trans = thisConnection.BeginTransaction()) { using (SqlCommand command = new SqlCommand("", thisConnection, trans)) { command.CommandType = System.Data.CommandType.Text; foreach (var commandString in sqlCommandList) { command.CommandText = commandString; result = command.ExecuteNonQuery(); } } if (result > 0) { trans.Commit(); SuccessDialog dialog = new SuccessDialog("注文が完了しました!"); dialog.ShowDialog(); AccountName.Text = ""; AccountNameToSave.Text = ""; resetTextBox(); resetEquipmentTable(); } else { trans.Rollback(); CustomizeDialog dialog = new CustomizeDialog("貸出情報を登録することが失敗しました!\n再度登録してください!"); dialog.ShowDialog(); } } send_http_message(g_read_cmd_header + "3start");//インベントリ開始 } catch (FormatException) //設備IDのフォーマットエラー発生 { CustomizeDialog dialog = new CustomizeDialog("その設備IDフォーマットが登録されていない!"); dialog.ShowDialog(); } catch (Exception) //DBへ接続できない { CustomizeDialog dialog = new CustomizeDialog("データベースへ接続できない!"); dialog.ShowDialog(); } } //using (thisConnection) //{ // try // { // intequipmentID = int.Parse(EquipmentIdTbl.Text); // empOrderParam.EquipmentID = intequipmentID; // empOrderParam.OrderDate = DateTime.Now; // //sql実施結果 // int result; // // 貸出情報を登録 // string insertSql = // "INSERT INTO dbo.EmployeeOrder (" // + " AccountID " // + " ,EquipmentID " // + " ,OrderDate " // + " ) " // + " VALUES ( " // + " '" + empOrderParam.AccountID + "' " // + " ," + empOrderParam.EquipmentID // + " ,'" + empOrderParam.OrderDate.ToString() + "'" // + " )"; // thisConnection.Open(); // SqlCommand insertCmd = thisConnection.CreateCommand(); // insertCmd.CommandText = insertSql; // SqlDataAdapter sda = new SqlDataAdapter(insertCmd); // sda.InsertCommand = insertCmd; // result = sda.InsertCommand.ExecuteNonQuery(); // // 設備情報のステータスを貸し出しに変更 // string updateSql = // "UPDATE dbo.Equipment " // + " SET EquipStatus = " + 0 // + " WHERE EquipmentID = " + empOrderParam.EquipmentID; // SqlCommand updateCmd = thisConnection.CreateCommand(); // updateCmd.CommandText = updateSql; // SqlDataAdapter updateSqlDataAdapter = new SqlDataAdapter(updateCmd); // updateSqlDataAdapter.UpdateCommand = updateCmd; // result = updateSqlDataAdapter.UpdateCommand.ExecuteNonQuery(); // if (result > 0) // { // MessageBoxResult checkNotice = MessageBox.Show("注文が完了しました!", "成功メッセージ", MessageBoxButton.OK); // AccountName.Text = ""; // AccountNameToSave.Text = ""; // resetTextBox(); // resetEquipmentTable(); // } // else // { // CustomizeDialog dialog = new CustomizeDialog("貸出情報を登録することが失敗しました!"); // dialog.ShowDialog(); // } // } // catch (FormatException) // { // CustomizeDialog dialog = new CustomizeDialog("その設備IDフォーマットが登録されていない!"); // dialog.ShowDialog(); // } //} } } else { CustomizeDialog dialog = new CustomizeDialog("ユーザー情報を入力してください!"); dialog.ShowDialog(); } } //返却 else if (isBorrow == 0) { if (OrderIDTbl.Text != null && OrderIDTbl.Text != "" && EquipmentIdTbl.Text != null && EquipmentIdTbl.Text != "") { SqlConnection thisConnection = new SqlConnection(@"Server=tcp:bmkprojbnsqr01v.database.windows.net,1433;Initial Catalog=DB_BMK;Persist Security Info=False;User ID=bmkDataAdmin;Password=Setsubi2019;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"); using (thisConnection) { try { //新規ユーザー定義する EmployeeOrder empOrderParam = new EmployeeOrder(); //sql実施結果 int result = 0; //integerフォーマット変換する int intOrderID = int.Parse(OrderIDTbl.Text); int intequipmentID = int.Parse(EquipmentIdTbl.Text); empOrderParam.OrderID = intOrderID; empOrderParam.ReturnedDate = DateTime.Now; empOrderParam.EquipmentID = intequipmentID; //sqlcommand List <string> sqlCommandList = new List <string>(); //update command1 string sql1 = "UPDATE dbo.EmployeeOrder " + " SET ReturnedDate = '" + empOrderParam.ReturnedDate.ToString() + "'" + " WHERE EquipmentID = " + empOrderParam.EquipmentID + " AND OrderID = " + empOrderParam.OrderID; sqlCommandList.Add(sql1); //update command2 string sql2 = "UPDATE dbo.Equipment " + " SET EquipStatus = " + 1 + " WHERE EquipmentID = " + empOrderParam.EquipmentID; sqlCommandList.Add(sql2); thisConnection.Open(); using (SqlTransaction trans = thisConnection.BeginTransaction()) { using (SqlCommand command = new SqlCommand("", thisConnection, trans)) { command.CommandType = System.Data.CommandType.Text; foreach (var commandString in sqlCommandList) { command.CommandText = commandString; result = command.ExecuteNonQuery(); } } if (result > 0) { trans.Commit(); SuccessDialog dialog = new SuccessDialog("返却が完了しました!"); dialog.ShowDialog(); AccountName.Text = ""; AccountNameToSave.Text = ""; resetEquipmentTable(); resetTextBox(); } else { trans.Rollback(); CustomizeDialog dialog = new CustomizeDialog("返却情報を登録することが失敗しました!\n再度登録してください!"); dialog.ShowDialog(); } } } catch (FormatException) //注文IDのフォーマットエラー発生 { CustomizeDialog dialog = new CustomizeDialog("その注文IDまたは設備IDフォーマットが登録されていない!"); dialog.ShowDialog(); } catch (Exception) ////DBへ接続できない { CustomizeDialog dialog = new CustomizeDialog("データベースへ接続できない!"); dialog.ShowDialog(); } } } else { CustomizeDialog dialog = new CustomizeDialog("乗せられた設備の情報が削除された!"); dialog.ShowDialog(); } //EmployeeOrder empOrderParam = new EmployeeOrder(); //int intOrderID = 0; //int intequipmentID = 0; //try //{ // intOrderID = int.Parse(OrderIDTbl.Text); // intequipmentID = int.Parse(EquipmentIdTbl.Text); //} //catch (Exception) //{ // CustomizeDialog dialog = new CustomizeDialog("その設備の貸出時間が登録されていない!"); // dialog.ShowDialog(); //} //empOrderParam.OrderID = intOrderID; //empOrderParam.ReturnedDate = DateTime.Now; //empOrderParam.EquipmentID = intequipmentID; //SqlConnection thisConnection = new SqlConnection(@"Server=tcp:bmkprojbnsqr01v.database.windows.net,1433;Initial Catalog=DB_BMK;Persist Security Info=False;User ID=bmkDataAdmin;Password=Setsubi2019;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"); //thisConnection.Open(); ////sql実施結果 //int result; //// 返却情報を登録 //string updateSql = // "UPDATE dbo.EmployeeOrder " // + " SET ReturnedDate = '" + empOrderParam.ReturnedDate.ToString() + "'" // + " WHERE EquipmentID = " + empOrderParam.EquipmentID // + " AND OrderID = " + empOrderParam.OrderID; //SqlCommand updateCmd = thisConnection.CreateCommand(); //updateCmd.CommandText = updateSql; //SqlDataAdapter updateSqlDataAdapter = new SqlDataAdapter(updateCmd); //updateSqlDataAdapter.UpdateCommand = updateCmd; //result = updateSqlDataAdapter.UpdateCommand.ExecuteNonQuery(); //// 設備情報のステータスを返却に変更 //string updateEquipmentSql = // "UPDATE dbo.Equipment " // + " SET EquipStatus = " + 1 // + " WHERE EquipmentID = " + empOrderParam.EquipmentID; //SqlCommand updateEquipmentCmd = thisConnection.CreateCommand(); //updateEquipmentCmd.CommandText = updateEquipmentSql; //SqlDataAdapter updateEquipmentSqlDataAdapter = new SqlDataAdapter(updateEquipmentCmd); //updateEquipmentSqlDataAdapter.UpdateCommand = updateEquipmentCmd; //result = updateEquipmentSqlDataAdapter.UpdateCommand.ExecuteNonQuery(); //if (result > 0) //{ // MessageBoxResult checkNotice = MessageBox.Show("返却が完了しました!", "成功メッセージ", MessageBoxButton.OK); // AccountName.Text = ""; // AccountNameToSave.Text = ""; // resetEquipmentTable(); // resetTextBox(); //} //else //{ // CustomizeDialog dialog = new CustomizeDialog("データベースへ接続できない!"); // dialog.ShowDialog(); //} } else { CustomizeDialog dialog = new CustomizeDialog("設備情報がありません!"); dialog.ShowDialog(); } }