public int Estimate_Insert(EstimateData estd) { if (estd == null) { return(-1); } string sqlStr = "INSERT INTO D_Estimate (TaskEntryID, VersionNo, Total, Budgets, MinimalBid, Contract, OfficeCode, Department, Note) " + "VALUES (@tenID, @verN, @total, @bget, @mBid, @cont, @oCod, @dept, @note)"; string sqlStr2 = "SELECT EstimateID FROM D_Estimate WHERE TaskEntryID = " + Convert.ToString(estd.TaskEntryID) + " AND VersionNo = " + Convert.ToString(estd.VersionNo) + " AND OfficeCode = '" + estd.OfficeCode + "' AND Department = '" + estd.Department + "'"; int id = -1; using (TransactionScope tran = new TransactionScope()) using (SqlConnection conn = new SqlConnection(ConnectionString)) { try { conn.Open(); SqlCommand cmd = new SqlCommand(sqlStr, conn); cmd = estim_cmd(cmd, estd); if (TryExecute(conn, cmd) < 0) { return(-1); } cmd = new SqlCommand(sqlStr2, conn); SqlDataReader dr = TryExReader(conn, cmd); if (dr == null) { return(-1); } while (dr.Read()) { id = Convert.ToInt32(dr["EstimateID"]); } dr.Close(); } catch (SqlException sqle) { MessageBox.Show("SQLエラー errorno " + Convert.ToString(sqle.Number) + " " + sqle.Message); conn.Close(); return(-1); } conn.Close(); tran.Complete(); } return(id); }
//--------------------------------------------------------// // Method //--------------------------------------------------------// public new object Clone() { EstimateData cloneData = new EstimateData(); cloneData.EstimateID = this.EstimateID; cloneData.TaskEntryID = this.TaskEntryID; cloneData.VersionNo = this.VersionNo; cloneData.Total = this.Total; cloneData.Budgets = this.Budgets; cloneData.MinimalBid = this.MinimalBid; cloneData.Contract = this.Contract; cloneData.OfficeCode = this.OfficeCode; cloneData.Department = this.Department; cloneData.Note = this.Note; return(cloneData); }
private SqlCommand estim_cmd(SqlCommand cmd, EstimateData estd) { cmd.Parameters.Add("@tenID", SqlDbType.Int); cmd.Parameters.Add("@verN", SqlDbType.Int); cmd.Parameters.Add("@total", SqlDbType.Decimal); cmd.Parameters.Add("@bget", SqlDbType.Decimal); cmd.Parameters.Add("@mBid", SqlDbType.Decimal); cmd.Parameters.Add("@cont", SqlDbType.Decimal); cmd.Parameters.Add("@oCod", SqlDbType.Char); cmd.Parameters.Add("@dept", SqlDbType.Char); cmd.Parameters.Add("@note", SqlDbType.NVarChar); cmd.Parameters["@tenID"].Value = estd.TaskEntryID; cmd.Parameters["@verN"].Value = estd.VersionNo; cmd.Parameters["@total"].Value = estd.Total; cmd.Parameters["@bget"].Value = estd.Budgets; cmd.Parameters["@mBid"].Value = estd.MinimalBid; cmd.Parameters["@cont"].Value = estd.Contract; cmd.Parameters["@oCod"].Value = estd.OfficeCode; cmd.Parameters["@dept"].Value = estd.Department; cmd.Parameters["@note"].Value = estd.Note; return(cmd); }
public bool Estimate_Update(EstimateData estd) { if (estd == null) { return(false); } string sqlStr = "UPDATE D_Estimate SET TaskEntryID = @tenID, VersionNo = @verN, Total = @total, Budgets = @bget, MinimalBid = @mBid," + "Contract = @cont, OfficeCode = @oCod, Department = @dept, Note=@note WHERE EstimateID = @estID"; using (TransactionScope tran = new TransactionScope()) using (SqlConnection conn = new SqlConnection(ConnectionString)) { try { conn.Open(); SqlCommand cmd = new SqlCommand(sqlStr, conn); cmd = estim_cmd(cmd, estd); cmd.Parameters.Add("@estID", SqlDbType.Int); cmd.Parameters["@estID"].Value = Convert.ToInt32(estd.EstimateID); if (TryExecute(conn, cmd) < 0) { return(false); } } catch (SqlException sqle) { MessageBox.Show("SQLエラー errorno " + Convert.ToString(sqle.Number) + " " + sqle.Message); conn.Close(); return(false); } conn.Close(); tran.Complete(); } return(true); }