void edit_pro(FishEntity.ProgramEntity list, Hashtable SQLString, StringBuilder strSql) { strSql = new StringBuilder( ); strSql.Append("update t_program set "); strSql.Append("programName=@programName,"); strSql.Append("programTable=@programTable,"); strSql.Append("modifyTime=@modifyTime,"); strSql.Append("modifyMan=@modifyMan "); strSql.Append("where programId=@programId"); MySqlParameter [] parameter = { new MySqlParameter("@programId", MySqlDbType.VarChar, 45), new MySqlParameter("@programName", MySqlDbType.VarChar, 45), new MySqlParameter("@programTable", MySqlDbType.VarChar, 45), new MySqlParameter("@modifyTime", MySqlDbType.DateTime), new MySqlParameter("@modifyMan", MySqlDbType.VarChar, 45) }; parameter [0].Value = list.programId; parameter [1].Value = list.programName; parameter [2].Value = list.programTable; parameter [3].Value = list.modifyTime; parameter [4].Value = list.modifyMan; SQLString.Add(strSql, parameter); }
void add_pro(FishEntity.ProgramEntity list, Hashtable SQLString, StringBuilder strSql) { strSql = new StringBuilder( ); strSql.Append("insert into t_program ("); strSql.Append("programId,programName,programTable,createTime,createMan,modifyTime,modifyMan) "); strSql.Append("values ("); strSql.Append("@programId,@programName,@programTable,@createTime,@createMan,@modifyTime,@modifyMan) "); MySqlParameter [] parameter = { new MySqlParameter("@programId", MySqlDbType.VarChar, 45), new MySqlParameter("@programName", MySqlDbType.VarChar, 45), new MySqlParameter("@programTable", MySqlDbType.VarChar, 45), new MySqlParameter("@createTime", MySqlDbType.DateTime), new MySqlParameter("@createMan", MySqlDbType.VarChar, 45), new MySqlParameter("@modifyTime", MySqlDbType.DateTime), new MySqlParameter("@modifyMan", MySqlDbType.VarChar, 45) }; parameter [0].Value = list.programId; parameter [1].Value = list.programName; parameter [2].Value = list.programTable; parameter [3].Value = list.createTime; parameter [4].Value = list.createMan; parameter [5].Value = list.modifyTime; parameter [6].Value = list.modifyMan; SQLString.Add(strSql, parameter); }
private void dataGridView1_CellClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e) { if (e.ColumnIndex < 0 || e.RowIndex < 0) { return; } if (dataGridView1.Columns [e.ColumnIndex].Name.Equals("programId", System.StringComparison.OrdinalIgnoreCase)) { FormProgram from = new FormProgram( ); from.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; if (from.ShowDialog( ) != System.Windows.Forms.DialogResult.OK) { return; } FishEntity.ProgramEntity model = from.model; dataGridView1.Rows [e.RowIndex].Cells ["programId"].Value = model.programId; dataGridView1.Rows [e.RowIndex].Cells ["programName"].Value = model.programName; } if (dataGridView1.Columns [e.ColumnIndex].Name.Equals("userName", System.StringComparison.OrdinalIgnoreCase)) { FormUserList from = new FormUserList(true); from.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; if (from.ShowDialog( ) != System.Windows.Forms.DialogResult.OK) { return; } FishEntity.PersonEntity model = from.SelectedPersion; dataGridView1.Rows [e.RowIndex].Cells ["userName"].Value = model.username; dataGridView1.Rows [e.RowIndex].Cells ["userNum"].Value = model.realname; } }
public override void Save( ) { dataGridView1.EndEdit( ); List <FishEntity.ProgramEntity> modelList = new List <FishEntity.ProgramEntity> ( ); foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.IsNewRow) { continue; } list = new FishEntity.ProgramEntity( ); list.programId = row.Cells ["programId"].Value == null ? string.Empty : row.Cells ["programId"].Value.ToString( ); list.programName = row.Cells ["programName"].Value == null ? string.Empty : row.Cells ["programName"].Value.ToString( ); list.programTable = row.Cells ["programTable"].Value == null ? string.Empty : row.Cells ["programTable"].Value.ToString( ); modelList.Add(list); } if (modelList == null) { return; } bool result = _bll.add(modelList, FishEntity.Variable.User.username); if (result == true) { MessageBox.Show("保存成功"); dataGridView1.AllowUserToAddRows = false; dataGridView1.AllowUserToDeleteRows = false; dataGridView1.ReadOnly = true; tmiAdd.Visible = true; tmiQuery.Visible = true; tmiModify.Visible = false; tmiDelete.Visible = false; tmiReview.Visible = false; tmiSave.Visible = false; tmiCancel.Visible = false; tmiExport.Visible = false; tmiNext.Visible = false; tmiPrevious.Visible = false; tmiClose.Visible = true; } else { MessageBox.Show("保存失败,请重试"); } base.Save( ); }
/// <summary> /// 保存数据 /// </summary> /// <param name="modelList"></param> /// <param name="userName"></param> /// <returns></returns> public bool add(List <FishEntity.ProgramEntity> modelList, string userName) { Hashtable SQLString = new Hashtable( ); StringBuilder strSql = new StringBuilder( ); foreach (FishEntity.ProgramEntity list in modelList) { list.createMan = list.modifyMan = userName; list.createTime = list.modifyTime = dt( ); if (Exists(list.programId) == false) { add_pro(list, SQLString, strSql); } else { edit_pro(list, SQLString, strSql); } } DataTable tab = table( ); if (tab != null && tab.Rows.Count > 0) { string id = string.Empty; FishEntity.ProgramEntity list = new FishEntity.ProgramEntity( ); for (int i = 0; i < tab.Rows.Count; i++) { id = list.programId = tab.Rows [i] ["programId"].ToString( ); list = modelList.Find((t) => { return(t.programId.Equals(list.programId)); }); if (list == null) { delete_pro(id, SQLString, strSql); } } } return(MySqlHelper.ExecuteSqlTran(SQLString)); }
public FishEntity.ProgramEntity getModel(DataRow row) { FishEntity.ProgramEntity model = new FishEntity.ProgramEntity( ); if (row != null) { if (row ["programId"] != null) { model.programId = row ["programId"].ToString( ); } if (row ["programName"] != null) { model.programName = row ["programName"].ToString( ); } if (row ["programTable"] != null && row ["programTable"].ToString( ) != "") { model.programTable = row ["programTable"].ToString( ); } } return(model); }