Esempio n. 1
0
        private void txtCustomerId_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Return)
            {
                int CustId = Convert.ToInt32(txtCustomerId.Text);
                try
                {
                    oCliente_Ent = oCliente.GetOne(CustId);

                    chkNameStyle.Checked = oCliente_Ent.NameStyle;
                    txtTitle.Text = oCliente_Ent.Title;
                    txtFirstName.Text = oCliente_Ent.FirstName;
                    txtMiddleName.Text = oCliente_Ent.MiddleName;
                    txtLastName.Text = oCliente_Ent.LastName;
                    txtSuffix.Text = oCliente_Ent.Suffix;
                    txtCompany.Text = oCliente_Ent.CompanyName;
                    txtSalesPerson.Text = oCliente_Ent.SalesPerson;
                    txtEmailAddress.Text = oCliente_Ent.EmailAddress;
                    txtPhone.Text = oCliente_Ent.Phone;
                    txtPassHash.Text = oCliente_Ent.PasswordHash;
                    txtPassSalt.Text = oCliente_Ent.PasswordSalt;
                    txtFecha.Text = oCliente_Ent.ModifiedDate.ToString("dd-MM-yyyy");
                }
                catch (Exception Ex)
                {
                    MessageBox.Show(Ex.Message);
                }
            }
        }
        public E_Customer GetOne(int CustomerId)
        {
            E_Customer vRes = new E_Customer();

            SqlCommand cmd = new SqlCommand();

            try
            {
                cmd = CrearComando("Customer_Get");
                cmd.Parameters.AddWithValue("@CustomerId", CustomerId);

                AbrirConexion();
                SqlDataReader consulta = Ejecuta_Consulta(cmd);

                if (consulta.Read())
                {
                    if (consulta.HasRows)
                    {
                        vRes.CustomerId = (int)consulta["CustomerId"];
                        vRes.NameStyle = (Boolean)consulta["NameStyle"];
                        vRes.Title = Convert.ToString(consulta["Title"]);
                        vRes.FirstName = (string)consulta["FirstName"];
                        vRes.MiddleName = Convert.ToString(consulta["MiddleName"]);
                        vRes.LastName = (string)consulta["LastName"];
                        vRes.Suffix = Convert.ToString(consulta["Suffix"]);
                        vRes.CompanyName = Convert.ToString(consulta["CompanyName"]);
                        vRes.SalesPerson = Convert.ToString(consulta["SalesPerson"]);
                        vRes.EmailAddress = Convert.ToString(consulta["EmailAddress"]);
                        vRes.Phone = Convert.ToString(consulta["Phone"]);
                        vRes.PasswordHash = (string)consulta["PasswordHash"];
                        vRes.PasswordSalt = (string)consulta["PasswordSalt"];
                        vRes.ModifiedDate = (DateTime)consulta["ModifiedDate"];
                    }
                }
                consulta.Close();
                consulta.Dispose();

            }
            catch (Exception Ex)
            {
                throw new Exception(Ex.Message, Ex);
            }
            finally
            {
                cmd.Dispose();
                CerrarConexion();
            }
            return vRes;
        }
 public int Save(E_Customer oCustomer)
 {
     return D_Cus.Save(oCustomer);
 }
        public int Save(E_Customer oCustomer)
        {
            SqlCommand cmd = new SqlCommand();
            int vReg = -1;
            try
            {
                cmd = CrearComando("Customer_Set");
                cmd.Parameters.AddWithValue("@CustomerId", oCustomer.CustomerId);
                cmd.Parameters["@CustomerId"].Direction = ParameterDirection.InputOutput;

                cmd.Parameters.AddWithValue("@NameStyle", oCustomer.NameStyle);
                cmd.Parameters.AddWithValue("@Title", oCustomer.Title);
                cmd.Parameters.AddWithValue("@FirstName", oCustomer.FirstName);
                cmd.Parameters.AddWithValue("@MiddleName", oCustomer.MiddleName);
                cmd.Parameters.AddWithValue("@LastName", oCustomer.LastName);
                cmd.Parameters.AddWithValue("@Suffix", oCustomer.Suffix);
                cmd.Parameters.AddWithValue("@CompanyName", oCustomer.CompanyName);
                cmd.Parameters.AddWithValue("@SalesPerson", oCustomer.SalesPerson);
                cmd.Parameters.AddWithValue("@EmailAddress", oCustomer.EmailAddress);
                cmd.Parameters.AddWithValue("@Phone", oCustomer.Phone);
                cmd.Parameters.AddWithValue("@PasswordHash", oCustomer.PasswordHash);
                cmd.Parameters.AddWithValue("@PasswordSalt", oCustomer.PasswordSalt);

                AbrirConexion();
                vReg = Ejecuta_Accion(ref cmd);
                vReg = Convert.ToInt32(cmd.Parameters["@CustomerId"].Value);
            }
            catch (Exception Ex)
            {
                throw new Exception(Ex.Message, Ex);
            }
            finally
            {
                cmd.Dispose();
                CerrarConexion();
            }
            return vReg;
        }