internal List <clsUnitRevaluation> GetRevaluationList() { List <clsUnitRevaluation> lst = new List <clsUnitRevaluation>(); using (SqlConnection conn = new SqlConnection(strConn)) { conn.Open(); using (SqlCommand cmd = new SqlCommand("TMR_USP_GetReavluationList")) { cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = conn; SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { var info = new clsUnitRevaluation(); info.strProject = reader["ProjectID"].ToString(); info.strBlock = reader["BlockID"].ToString(); info.dateRevaluationDate = Convert.ToDateTime(reader["RevalueDate"]); info.ApprovalStatusDescription = reader["ApprovalStatusDescription"].ToString(); info.id = Convert.ToInt32(reader["id"].ToString()); lst.Add(info); } conn.Close(); } } return(lst); }
public bool AddUnitRevaluation(clsUnitRevaluation info, ref int id) { int st = 0; try { using (SqlConnection conn = new SqlConnection(strConn)) { conn.Open(); { using (SqlCommand cmd = new SqlCommand("TMR_USP_AddUnitRevaluation")) { cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = conn; cmd.Parameters.AddWithValue("@ProjectID", info.strProject); cmd.Parameters.AddWithValue("@BlockID", info.strBlock); cmd.Parameters.AddWithValue("@RevalueDate", info.dateRevaluationDate); cmd.Parameters.AddWithValue("@Revaluationid", info.id); cmd.Parameters.AddWithValue("@ApprovalStatusCode", info.ApprovalStatusCode); cmd.Parameters.AddWithValue("@ApprovalActionUser", info.ApprovalActionUser); cmd.Parameters.AddWithValue("@ApprovalActionDate", info.ApprovalActionDate); cmd.Parameters.AddWithValue("@CreatedBy", info.CreatedBy); cmd.Parameters.AddWithValue("@CreationDate", info.CreationDate); cmd.Parameters.AddWithValue("@LastUpdateUser", info.LastUpdateUser); cmd.Parameters.AddWithValue("@LastUpdateDate", info.LastUpdateDate); SqlParameter parm = new SqlParameter(); parm.ParameterName = "@Outid"; parm.SqlDbType = SqlDbType.Int; parm.Direction = ParameterDirection.Output; //parm.Value = info.id; cmd.Parameters.Add(parm); st = cmd.ExecuteNonQuery(); id = (int)parm.Value; } } conn.Close(); } } catch (Exception ex) { } if (st > 0) { return(true); } else { return(false); } }
private void LoadInformation() { dgList.Rows.Clear(); clsUnitRevaluation reval = da.GetUnitRevaluationById(id); if (reval == null) { return; } cmbProject.Text = reval.strProject; cmbBlock.Text = reval.strBlock; dtpDate.Value = reval.dateRevaluationDate; cmbProject.Enabled = false; cmbBlock.Enabled = false; EntryApproved = (ApprovalStatus)reval.ApprovalStatusCode; if ((ApprovalStatus)reval.ApprovalStatusCode == ApprovalStatus.Pending) { cmbApprovalStatus.Text = "Pending"; } else if ((ApprovalStatus)reval.ApprovalStatusCode == ApprovalStatus.Approved) { cmbApprovalStatus.Text = "Approved"; } else if ((ApprovalStatus)reval.ApprovalStatusCode == ApprovalStatus.Rejected) { cmbApprovalStatus.Text = "Rejected"; } List <clsUnitRevaluationListItem> revalList = da.GetUnitRevaluationListItemsById(id); foreach (var item in revalList) { int index = dgList.Rows.Add(); dgList.Rows[index].Cells["BlockID"].Value = item.BlockID; dgList.Rows[index].Cells["SizeCode"].Value = item.SizeCode; dgList.Rows[index].Cells["RowId"].Value = item.id; dgList.Rows[index].Cells["NewPrice"].Value = item.NewPrice; dgList.Rows[index].Cells["OldPrice"].Value = item.OldPrice; clspricelist.strProjectID = cmbProject.Text; clspricelist.strBlockID = cmbBlock.Text; clspricelist.strSizeCode = item.SizeCode; } }
public clsUnitRevaluation GetUnitRevaluationById(int id) { clsUnitRevaluation info = new clsUnitRevaluation(); using (SqlConnection conn = new SqlConnection(strConn)) { conn.Open(); using (SqlCommand cmd = new SqlCommand("TMR_USP_GetUnitRevaluationByID")) { cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = conn; cmd.Parameters.AddWithValue("@id", id); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { info.strProject = reader["ProjectID"].ToString(); info.strBlock = reader["BlockID"].ToString(); info.dateRevaluationDate = Convert.ToDateTime(reader["RevalueDate"]); info.ApprovalStatusCode = Convert.ToInt32(reader["ApprovalStatusCode"].ToString()); info.ApprovalStatusDescription = reader["ApprovalStatusDescription"].ToString(); info.ApprovalActionUser = reader["ApprovalActionUser"].ToString(); info.ApprovalActionDate = Convert.ToDateTime(reader["ApprovalActionDate"].ToString()); info.CreatedBy = reader["CreatedBy"].ToString(); info.CreationDate = Convert.ToDateTime(reader["CreationDate"].ToString()); info.LastUpdateUser = reader["LastUpdateUser"].ToString(); info.LastUpdateDate = Convert.ToDateTime(reader["LastUpdateDate"].ToString()); info.id = Convert.ToInt32(reader["id"]); } conn.Close(); } } return(info); }
private void tsbSave_Click(object sender, EventArgs e) { if (cmbProject.SelectedIndex == -1) { MessageBox.Show("Please select a project."); return; } if (cmbBlock.SelectedIndex == -1) { MessageBox.Show("Please select a block."); return; } decimal value; bool result; List <clsUnitRevaluationListItem> lst = new List <clsUnitRevaluationListItem>(); List <clsSizeCodePriceList> lst2 = new List <clsSizeCodePriceList>(); foreach (DataGridViewRow dgr in dgList.Rows) { if (dgr.Cells["NewPrice"].Value == null) { MessageBox.Show("Please enter a valid old price."); return; } else { result = decimal.TryParse(dgr.Cells["OldPrice"].Value.ToString(), out value); } if (result == false) { MessageBox.Show("Please enter a valid old price."); return; } if (dgr.Cells["OldPrice"].Value == null) { MessageBox.Show("Please enter a valid old price."); return; } else { result = decimal.TryParse(dgr.Cells["OldPrice"].Value.ToString(), out value); } if (result == false) { MessageBox.Show("Please enter a valid old price."); return; } lst.Add(new clsUnitRevaluationListItem { id = Convert.ToInt32(dgr.Cells["Rowid"].Value), NewPrice = Convert.ToDecimal(dgr.Cells["NewPrice"].Value), OldPrice = Convert.ToDecimal(dgr.Cells["OldPrice"].Value), SizeCode = (dgr.Cells["SizeCode"].Value.ToString()), BlockID = (dgr.Cells["BlockID"].Value.ToString()), }); lst2.Add(new clsSizeCodePriceList { id = Convert.ToInt32(dgr.Cells["Rowid"].Value), strSizeCode = (dgr.Cells["SizeCode"].Value.ToString()), dPrice = Convert.ToDecimal(dgr.Cells["NewPrice"].Value), strProjectID = cmbProject.Text, strBlockID = (dgr.Cells["BlockID"].Value.ToString()), }); } clsUnitRevaluation revaluation = new clsUnitRevaluation() { strProject = cmbProject.Text, strBlock = cmbBlock.Text, dateRevaluationDate = dtpDate.Value.Date }; if (id == 0) { revaluation.CreatedBy = Program._userid; revaluation.CreationDate = DateTime.Now; revaluation.ApprovalStatusCode = (int)ApprovalStatus.Pending; revaluation.LastUpdateDate = new DateTime(1900, 1, 1); revaluation.LastUpdateUser = ""; revaluation.ApprovalActionUser = ""; revaluation.ApprovalActionDate = new DateTime(1900, 1, 1); } else if (id != 0) { revaluation.ApprovalStatusCode = (int)ApprovalStatus.Pending; revaluation.LastUpdateDate = DateTime.Now; revaluation.LastUpdateUser = Program._userid; revaluation.ApprovalActionUser = ""; revaluation.ApprovalActionDate = new DateTime(1900, 1, 1); } int intRevalID = 0; result = da.AddUnitRevaluation(revaluation, ref intRevalID); if (result == false) { MessageBox.Show("Error saving unit revaluation."); return; } else { foreach (var item in lst) { item.Revaluationid = intRevalID; result = da.AddUnitRevaluationItem(item); if (result == false) { MessageBox.Show("Error saving unit revaluation."); return; } } } foreach (var item in lst2) { item.Fk_RevaluationID = intRevalID; result = da.AddSizeCodePriceList(item); if (result == false) { MessageBox.Show("Error saving unit revaluation."); return; } } id = intRevalID; LoadInformation(); DataGridRefresh(); }