Archive for Luglio 17th, 2008

Item lista

CodeKeep C# Feed Luglio 17th, 2008

Description: Classe para manipulação da tabela tb_item_lista

Link: http://www.codekeep.net/snippets/093f6e70-0132-4d5e-92aa-7996a2dba6d9.aspx

namespace MobileInspection.VistoriaWEB.DAO
{
	/// <summary>
	/// Classe para manipulação da tabela tb_item_lista
	/// </summary>
	public class Item_listaDAO
	{
        #region GetItem_lista (DataTable)
        /// <summary>
        /// Seleciona todos os registros da tabela tb_ItemLista
        /// </summary>
        /// <returns>
        /// Retorna um DataTable com os registros.
        /// </returns>
        public DataTable GetItem_lista(int inttlist_cod)
        { 
            DataTable dt = new DataTable();
            string NomeProcedure = "SP_S_TB_ITEM_LISTA";
            SQLHelper objSQLHelper = new SQLHelper("Audatex");
            try
            {
                SqlCommand cmdParam = new SqlCommand();
                SqlParameter[] arrayPar = new SqlParameter[1];
                cmdParam.Parameters.Add("@tlist_cod", SqlDbType.Int, 4).Value = inttlist_cod;
                cmdParam.Parameters.CopyTo(arrayPar, 0);

                IDataReader dr = objSQLHelper.sqlReaderRetorno(NomeProcedure, arrayPar);

                dt.Load(dr);
            }
            catch (Exception ex)
            {
                throw new Exception("ERRO na camada DAO: " + ex.Message);
            }
            finally
            {
                objSQLHelper = null;
            }

            return dt;
        }

ddlSeguradoraDataBind()

CodeKeep C# Feed Luglio 17th, 2008

Description: Método Popular Combo

Link: http://www.codekeep.net/snippets/e0465599-6f1d-4c7e-84ad-221be4b8151d.aspx

 private void ddlSeguradoraDataBind()
        {

            try
            {
                ddlSeguradora.Items.Clear();
                SeguradoraBO objSeguradoraBO = new SeguradoraBO();
                ddlSeguradora.DataSource = objSeguradoraBO.GetSeguradoras();
                ddlSeguradora.DataBind();
            }
            catch (Exception ex)
            {
                ucGlobal.PopUpClient(this.Page, "Ocorreu um erro ao carregar o combo Seguradora!");
            }
        }




namespace MobileInspection.VistoriaWEB.BO
{
    public class SeguradoraBO
    {
        public DataTable GetSeguradoras()
        {
            DataTable dtSeguradoras = new DataTable();
            SeguradoraDAO objSegurancaDAO = new SeguradoraDAO();

            try
            {
                dtSeguradoras = objSegurancaDAO.GetSeguradoras();
            }
            catch (Exception ex)
            {
                throw new Exception("ERRO na camada BO: " + ex.Message);
            }
            return dtSeguradoras;
        }
    }
}

Teste

CodeKeep C# Feed Luglio 17th, 2008

Description: teste

Link: http://www.codekeep.net/snippets/7e335167-1fc1-48be-873e-e5d1974c4a39.aspx

protected void Page_Load(object sender, EventArgs e)
    {
       
    }

File Size as String (i.e. 100 Kb, 101 MB etc..)

CodeKeep C# Feed Luglio 17th, 2008

Description: This function will return the file size in string from the File Upload control.

Link: http://www.codekeep.net/snippets/1511df17-34e7-47d3-a886-dc7ea8c4cd0e.aspx

 #region GetFileSizeInBytes()// Funciton to get the File Size in Bytes
    private string GetFileSizeInBytes() // Function to return the file size in Bytes
    {
        string FlSize = "0 Bytes";


        if (fuDownload.HasFile)
        {
            string flActualByte = fuDownload.FileBytes.Length.ToString();
            if (flActualByte.Length == 3)
            {
                FlSize = flActualByte + "bytes";
            }
            else if (flActualByte.Length == 4)
            {
                flActualByte = flActualByte.Substring(0, 2);
                flActualByte = flActualByte.Insert(1, ".");

                FlSize = flActualByte + " kB";
            }
            else if (flActualByte.Length == 5)
            {
                flActualByte = flActualByte.Substring(0, 3);
                flActualByte = flActualByte.Insert(2, ".");

                FlSize = flActualByte + " kB";
            }
            else if (flActualByte.Length == 6)
            {
                flActualByte = flActualByte.Substring(0, 4);
                flActualByte = flActualByte.Insert(3, ".");

                FlSize = flActualByte + " kB";
            }
            else if (flActualByte.Length == 7)
            {
                flActualByte = flActualByte.Substring(0, 2);
                flActualByte = flActualByte.Insert(1, ".");

                FlSize = flActualByte + " MB";
            }
            else if (flActualByte.Length == 8)
            {
                flActualByte = flActualByte.Substring(0, 3);
                flActualByte = flActualByte.Insert(2, ".");

                FlSize = flActualByte + " MB";
            }
            else if (flActualByte.Length == 9)
            {
                flActualByte = flActualByte.Substring(0, 4);
                flActualByte = flActualByte.Insert(3, ".");

                FlSize = flActualByte + " MB";
            }
            else if (flActualByte.Length == 10)
            {
                flActualByte = flActualByte.Substring(0, 2);
                flActualByte = flActualByte.Insert(1, ".");

                FlSize = flActualByte + " GB";
            }

        }

        return FlSize;
    }
    #endregion

Nullable Int

CodeKeep C# Feed Luglio 17th, 2008

Description: Nullable Int

Link: http://www.codekeep.net/snippets/a6bf9117-418a-497b-8406-c748b02508b7.aspx

int? i=2;

            int? result = i * 2 ?? 5;
            MessageBox.Show(result.ToString());