protected void btnSubmit_Click(object sender, EventArgs e) { Contractor _Contractor = new Contractor(); _Contractor.Name = Name.Text; _Contractor.Description = Description.Text; _Contractor.IsDeleted = false; lblMessage.Text = Contractor_DA.InsertContractor(_Contractor); if (lblMessage.Text == Constants.ALREADY_EXIST) { lblMessage.ForeColor = System.Drawing.Color.Red; } else lblMessage.ForeColor = System.Drawing.Color.Green; }
public static string InsertContractor(Contractor _Contractor) { DbCommand command = Catalog_Access.CreateCommand(); command.CommandText = "sp_insertContractor"; DbParameter param; param = command.CreateParameter(); param.ParameterName = "@Name"; param.Value = _Contractor.Name; param.DbType = DbType.String; command.Parameters.Add(param); param = command.CreateParameter(); param.ParameterName = "@Description"; param.Value = _Contractor.Description; param.DbType = DbType.String; command.Parameters.Add(param); param = command.CreateParameter(); param.ParameterName = "@IsDeleted"; param.Value = _Contractor.IsDeleted; param.DbType = DbType.Boolean; command.Parameters.Add(param); param = command.CreateParameter(); param.ParameterName = "@Return"; param.DbType = DbType.String; param.Size = 2; param.Direction = ParameterDirection.Output; command.Parameters.Add(param); Catalog_Access.ExecuteNonQuery(command); string Return = command.Parameters["@Return"].Value.ToString(); if (Return == Constants.SP_ALREADY_EXIST) { return Constants.ALREADY_EXIST; } else { return Constants.SUCESS_INSERT; } }
public static string UpdateContractor(Contractor _Contractor) { DbCommand command = Catalog_Access.CreateCommand(); command.CommandText = "sp_UpdateContractor"; DbParameter param; param = command.CreateParameter(); param.ParameterName = "@Id"; param.Value = _Contractor.Id; param.DbType = DbType.Int32; command.Parameters.Add(param); param = command.CreateParameter(); param.ParameterName = "@Name"; param.Value = _Contractor.Name; param.DbType = DbType.String; command.Parameters.Add(param); param = command.CreateParameter(); param.ParameterName = "@Description"; param.Value = _Contractor.Description; param.DbType = DbType.String; command.Parameters.Add(param); param = command.CreateParameter(); param.ParameterName = "@Return"; param.DbType = DbType.String; param.Size = 2; param.Direction = ParameterDirection.Output; command.Parameters.Add(param); Catalog_Access.ExecuteNonQuery(command); string Return = command.Parameters["@Return"].Value.ToString(); return Return; }