public void insert(StatisticsProduction obj) { using (ColorimeterDBDataContext DBContext = new ColorimeterDBDataContext()) { DBContext.StatisticsProduction.InsertOnSubmit(obj); DBContext.SubmitChanges(); } }
/// <summary> /// 获取列表单行信息,进行修改或者删除的方法 /// </summary> /// <param name="command"></param> private void GetDataAboutChoose(String command) { try { //当选中某一项时,自动让该行也被选中 dataGridView_CommomShow.Rows[dataGridView_CommomShow.CurrentCellAddress.Y].Selected = true; StatisticsProduction stap = new StatisticsProduction(); //去遍历datagridview每一行 foreach (DataGridViewRow r in dataGridView_CommomShow.SelectedRows) { if (!r.IsNewRow) { //获取界面上选中行隐藏的batchGuid //batchGuid = r.Cells[30].Value.ToString(); //获取界面上选中行的所有数据 //stap.GUID =(Guid)r.Cells[1].Value; stap.ProductTime = (DateTime)r.Cells[2].Value;//生产时间 stap.RollNumber = r.Cells[3].Value.ToString(); stap.ColorCode = r.Cells[4].Value.ToString(); stap.DeltaL_Mean = (float)r.Cells[5].Value; stap.DeltaA_Mean = (float)r.Cells[6].Value; stap.DeltaB_Mean = (float)r.Cells[7].Value; stap.DeltaE_Mean = (float)r.Cells[8].Value; stap.DeltaL_MSE = (float)r.Cells[9].Value; stap.DeltaA_MSE = (float)r.Cells[10].Value; stap.DeltaB_MSE = (float)r.Cells[11].Value; stap.DeltaE_MSE = (float)r.Cells[12].Value; stap.flag = (float)r.Cells[13].Value; stap.GoodNumber = (int)r.Cells[14].Value; stap.BadNumber = (int)r.Cells[15].Value; stap.GUID = (Guid)r.Cells[16].Value; if (command == "delete") { //SqlCommand cmd = new SqlCommand("select * from tb_users where GUID = @guid ", constr); //SqlDataReader data = cmd.ExecuteReader(); var result = from u in DBContext.StatisticsProduction where u.GUID == stap.GUID select u; DBContext.StatisticsProduction.DeleteAllOnSubmit(result); DBContext.SubmitChanges(); //重新刷新页面 QueryResult(); } //else if (command == "update") //{ // //弹出修改记录的窗口 // var result = from u in DBContext.RealTimeProduction where u.GUID == stap.GUID select u; // DBContext.RealTimeProduction.DeleteAllOnSubmit(result); // DBContext.SubmitChanges(); //} } } } catch { } }