private void Button_Save_Click(object sender, EventArgs e) { //String TestRoomCode = Yqun.Common.ContextCache.ApplicationContext.Current.InTestRoom.Code; string UserName = Yqun.Common.ContextCache.ApplicationContext.Current.UserName; try { using (DataTable dt = FpSpread_Info.GetDataView(true).Table) { int IsUpdated = 0; for (int i = 0; i < dt.Rows.Count; i++) { IsUpdated = int.Parse(dt.Rows[i][10].ToString()); if (IsUpdated == 0) { dt.Rows.Remove(dt.Rows[i]); i--; } } if (dt.Rows.Count > 0) { int TemperatureType = 0; if (rbSDNei.Checked) { TemperatureType = 1; } if (bool.Parse(ModuleHelperClient.SaveTemperatures(TestRoomCode, UserName, dt, TemperatureType)))// FpSpread_Info.GetDataView(true).Table { MessageBox.Show("实验记录保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("实验记录保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("没有更改任何数据,不需要保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } BindDayList(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Button_Save_Click(object sender, EventArgs e) { string UserName = Yqun.Common.ContextCache.ApplicationContext.Current.UserName; try { //using (DataTable dt = FpSpread_Info.GetDataView(true).Table) //{ DataTable dt = new DataTable(); #region 构建dt dt.Columns.Add("ID", System.Type.GetType("System.String")); dt.Columns.Add("TestRoomCode", System.Type.GetType("System.String")); dt.Columns.Add("TestTime", System.Type.GetType("System.String")); dt.Columns.Add("Temperature1", System.Type.GetType("System.String")); dt.Columns.Add("Temperature2", System.Type.GetType("System.String")); dt.Columns.Add("Temperature3", System.Type.GetType("System.String")); dt.Columns.Add("TemperatureAvg", System.Type.GetType("System.String")); dt.Columns.Add("Comment", System.Type.GetType("System.String")); dt.Columns.Add("LastEditUser", System.Type.GetType("System.String")); dt.Columns.Add("LastEditTime", System.Type.GetType("System.String")); dt.Columns.Add("IsUpdated", System.Type.GetType("System.String")); dt.Columns.Add("TemperatureType", System.Type.GetType("System.String")); #endregion DataRow row; int IsUpdated = 0; for (int i = 0; i < FpSpread_Info.Rows.Count; i++) { IsUpdated = int.Parse(FpSpread_Info.Cells[i, 10].Value.ToString()); if (IsUpdated == 1) { row = dt.NewRow(); row["ID"] = FpSpread_Info.Cells[i, 0].Value; row["TestRoomCode"] = FpSpread_Info.Cells[i, 1].Value; row["TestTime"] = FpSpread_Info.Cells[i, 2].Value; row["Temperature1"] = FpSpread_Info.Cells[i, 3].Value; row["Temperature2"] = FpSpread_Info.Cells[i, 4].Value; row["Temperature3"] = FpSpread_Info.Cells[i, 5].Value; row["TemperatureAvg"] = FpSpread_Info.Cells[i, 6].Value; row["Comment"] = FpSpread_Info.Cells[i, 7].Value; row["LastEditUser"] = FpSpread_Info.Cells[i, 8].Value; row["LastEditTime"] = FpSpread_Info.Cells[i, 9].Value; row["IsUpdated"] = FpSpread_Info.Cells[i, 10].Value; row["TemperatureType"] = FpSpread_Info.Cells[i, 11].Value; dt.Rows.Add(row); //dt.Rows.Remove(dt.Rows[i]); //i--; } } if (dt.Rows.Count > 0) { int TemperatureType = Convert.ToInt32(ComboTemperature.SelectedValue); if (bool.Parse(ModuleHelperClient.SaveTemperatures(TestRoomCode, UserName, dt, TemperatureType)))// FpSpread_Info.GetDataView(true).Table { MessageBox.Show("实验记录保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("实验记录保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("没有更改任何数据,不需要保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } BindDayList(); //} } catch (Exception ex) { MessageBox.Show(ex.Message); } }