public void UpdateCost(int CostId, CostDetail cost) { var data = context.CostDetails.SingleOrDefault(s => s.CostId == CostId); data.Amount = cost.Amount; data.Tax = cost.Tax; data.TotelCost = cost.TotelCost; context.SaveChanges(); }
public ActionResult UpdateCost(int CostId, CostDetail cost) { try { repository.UpdateCost(CostId, cost); return(Ok("Data is Updated Successfully")); } catch (Exception e) { return(BadRequest(e)); } }
public ActionResult InsertCost(CostDetail cost) { try { repository.InsertCost(cost); return(Ok("Data is Inserted Successfully")); } catch (Exception e) { return(BadRequest(e)); } }
public CCostDetailPage() { InitializeComponent(); using (SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=ClassSystem;User ID=sa;Password=root")) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = "select * from Cost_Detail"; SqlDataAdapter adapter = new SqlDataAdapter(cmd); DataSet dataset = new DataSet(); adapter.Fill(dataset); //把查询结果填充到dataset DataTable table = dataset.Tables[0]; DataRowCollection rows = table.Rows; List <CostDetail> t = new List <CostDetail>(); for (int i = 0; i < rows.Count; i++) { DataRow row = rows[i]; string CostTime = (string)row["CostTime"]; string CostProj = (string)row["CostProj"]; string CostPlace = (string)row["CostPlace"]; Int16 JoinNum = (Int16)row["JoinNum"]; Int32 OCost = (Int32)row["OCost"]; Int32 CostSum = (Int32)row["CostSum"]; Int32 RCost = (Int32)row["RCost"]; Int32 ID = (Int32)row["ID"]; CostDetail info = new CostDetail { CostTime = CostTime, CostProj = CostProj, CostPlace = CostPlace, JoinNum = JoinNum, OCost = OCost, CostSum = CostSum, RCost = RCost }; t.Add(info); TB_RCOST.Text = Convert.ToString(RCost); TB_ATY.Text = Convert.ToString(ID); } this.datagrid1.ItemsSource = t; } } }
public void InsertCost(CostDetail cost) { context.CostDetails.Add(cost); context.SaveChanges(); }