/// <summary> /// SQL実行 /// </summary> /// <param name="strSql"></param> private void ExcuteSql(string strSql) { var db = new OleDbIf(); try { db.Connect(); db.BeginTransaction(); db.ExecuteSql(strSql); db.CommitTransaction(); MessageBox.Show("処理が完了しました。", "通知"); } catch (Exception) { db.RollbackTransaction(); MessageBox.Show("処理に失敗しました。", "通知"); } finally { this.Close(); db.Dispose(); } }
/// <summary> /// 更新 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnUpdate_Click(object sender, EventArgs e) { var db = new OleDbIf(); try { string strSql = null; var f = this.MdiParent as MainMDI; var tbl = this.dgv.DataSource as DataTable; var lst = new List <string>(); // 編集された行をコミットする foreach (DataRow row in tbl.Rows) { if (row.RowState != DataRowState.Unchanged) { string cd_co = row["CD_CO", DataRowVersion.Original].ToString(); if (this.m_strInitId.Equals(CommonConstants.MasterMode.BUMON)) { string cd_dept = (row["CD_DEPT", DataRowVersion.Original] != null) ? row["CD_DEPT", DataRowVersion.Original].ToString() : null; strSql = "UPDATE M_DEPT SET CD_CO='{0}', CD_DEPT='{1}', NM_DEPT='{2}', TXT_REM='{3}', CD_UPDATE='{4}', DTM_UPDATE=SYSDATE, FLG_ACTIVE='Y' WHERE CD_CO='{5}' AND CD_DEPT='{6}'"; strSql = String.Format( strSql, row["CD_CO", DataRowVersion.Current].ToString(), row["CD_DEPT", DataRowVersion.Current].ToString(), row["NM_DEPT", DataRowVersion.Current].ToString(), row["TXT_REM", DataRowVersion.Current].ToString(), f.lblUserName.Text, cd_co, cd_dept); } else { string cd_emp = (row["CD_EMP", DataRowVersion.Original] != null) ? row["CD_EMP", DataRowVersion.Original].ToString() : null; strSql = "UPDATE M_EMP SET CD_CO='{0}', CD_EMP='{1}', NM_EMP='{2}', TXT_PASSWD='{3}', CD_DEPT='{4}', TXT_ZIP='{5}', TXT_ADDR1='{6}', TXT_ADDR2='{7}', TXT_ADDR3='{8}', TXT_TEL='{9}', TXT_FAX='{10}', TXT_REM='{11}', CD_UPDATE='{12}', DTM_UPDATE=SYSDATE, FLG_ACTIVE='Y' WHERE CD_CO='{13}' AND CD_EMP='{14}'"; strSql = String.Format( strSql, row["CD_CO", DataRowVersion.Current].ToString(), row["CD_EMP", DataRowVersion.Current].ToString(), row["NM_EMP", DataRowVersion.Current].ToString(), row["TXT_PASSWD", DataRowVersion.Current].ToString(), row["CD_DEPT", DataRowVersion.Current].ToString(), row["TXT_ZIP", DataRowVersion.Current].ToString(), row["TXT_ADDR1", DataRowVersion.Current].ToString(), row["TXT_ADDR2", DataRowVersion.Current].ToString(), row["TXT_ADDR3", DataRowVersion.Current].ToString(), row["TXT_TEL", DataRowVersion.Current].ToString(), row["TXT_FAX", DataRowVersion.Current].ToString(), row["TXT_REM", DataRowVersion.Current].ToString(), f.lblUserName.Text, cd_co, cd_emp); } lst.Add(strSql); } } if (DialogResult.Yes == MessageBox.Show("登録します。よろしいですか?", "通知", MessageBoxButtons.YesNo)) { // SQL実行 db.Connect(); db.BeginTransaction(); lst.ForEach(n => db.ExecuteSql(n)); db.CommitTransaction(); MessageBox.Show("登録を完了しました。", "通知"); } } catch (Exception) { db.RollbackTransaction(); MessageBox.Show("登録に失敗しました。", "通知"); } finally { btnSearch_Click(sender, e); db.Dispose(); } }
/// <summary> /// 更新 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnUpdate_Click(object sender, EventArgs e) { var db = new OleDbIf(); try { string strSql = null; var f = this.MdiParent as MainMDI; var tbl = this.dgv.DataSource as DataTable; var lst = new List<string>(); // 編集された行をコミットする foreach (DataRow row in tbl.Rows) { if (row.RowState != DataRowState.Unchanged) { string cd_co = row["CD_CO", DataRowVersion.Original].ToString(); if (this.m_strInitId.Equals(CommonConstants.MasterMode.BUMON)) { string cd_dept = (row["CD_DEPT", DataRowVersion.Original] != null) ? row["CD_DEPT", DataRowVersion.Original].ToString() : null; strSql = "UPDATE M_DEPT SET CD_CO='{0}', CD_DEPT='{1}', NM_DEPT='{2}', TXT_REM='{3}', CD_UPDATE='{4}', DTM_UPDATE=SYSDATE, FLG_ACTIVE='Y' WHERE CD_CO='{5}' AND CD_DEPT='{6}'"; strSql = String.Format( strSql, row["CD_CO", DataRowVersion.Current].ToString(), row["CD_DEPT", DataRowVersion.Current].ToString(), row["NM_DEPT", DataRowVersion.Current].ToString(), row["TXT_REM", DataRowVersion.Current].ToString(), f.lblUserName.Text, cd_co, cd_dept); } else { string cd_emp = (row["CD_EMP", DataRowVersion.Original] != null) ? row["CD_EMP", DataRowVersion.Original].ToString() : null; strSql = "UPDATE M_EMP SET CD_CO='{0}', CD_EMP='{1}', NM_EMP='{2}', TXT_PASSWD='{3}', CD_DEPT='{4}', TXT_ZIP='{5}', TXT_ADDR1='{6}', TXT_ADDR2='{7}', TXT_ADDR3='{8}', TXT_TEL='{9}', TXT_FAX='{10}', TXT_REM='{11}', CD_UPDATE='{12}', DTM_UPDATE=SYSDATE, FLG_ACTIVE='Y' WHERE CD_CO='{13}' AND CD_EMP='{14}'"; strSql = String.Format( strSql, row["CD_CO", DataRowVersion.Current].ToString(), row["CD_EMP", DataRowVersion.Current].ToString(), row["NM_EMP", DataRowVersion.Current].ToString(), row["TXT_PASSWD", DataRowVersion.Current].ToString(), row["CD_DEPT", DataRowVersion.Current].ToString(), row["TXT_ZIP", DataRowVersion.Current].ToString(), row["TXT_ADDR1", DataRowVersion.Current].ToString(), row["TXT_ADDR2", DataRowVersion.Current].ToString(), row["TXT_ADDR3", DataRowVersion.Current].ToString(), row["TXT_TEL", DataRowVersion.Current].ToString(), row["TXT_FAX", DataRowVersion.Current].ToString(), row["TXT_REM", DataRowVersion.Current].ToString(), f.lblUserName.Text, cd_co, cd_emp); } lst.Add(strSql); } } if (DialogResult.Yes == MessageBox.Show("登録します。よろしいですか?", "通知", MessageBoxButtons.YesNo)) { // SQL実行 db.Connect(); db.BeginTransaction(); lst.ForEach(n => db.ExecuteSql(n)); db.CommitTransaction(); MessageBox.Show("登録を完了しました。", "通知"); } } catch (Exception) { db.RollbackTransaction(); MessageBox.Show("登録に失敗しました。", "通知"); } finally { btnSearch_Click(sender, e); db.Dispose(); } }
/// <summary> /// SQL実行 /// </summary> /// <param name="strSql"></param> private void ExcuteSql(string strSql) { var db = new OleDbIf(); try { db.Connect(); db.BeginTransaction(); db.ExecuteSql(strSql); db.CommitTransaction(); MessageBox.Show("処理が完了しました。", "通知"); } catch (Exception) { db.RollbackTransaction(); MessageBox.Show("登録に失敗しました。", "通知"); } finally { this.Close(); db.Dispose(); } }