Exemplo n.º 1
0
 private void EditButton_Click(object sender, EventArgs e)
 {
     readerConnectionML    = new ReaderConnectionML();
     readerConnectionML.id = int.Parse(ConectioncomboBox.SelectedValue.ToString());
     EnabledControls(true);
     SaveButton.Enabled = true;
 }
Exemplo n.º 2
0
        private void LoadData()
        {
            try
            {
                BussinesLayer.ModelReaderBLL modelReaderBLL = new BussinesLayer.ModelReaderBLL();
                readerConnectionBLL = new ReaderConnectionBLL();
                readerConnectionML  = new ReaderConnectionML();

                dtModelReader = modelReaderBLL.All();
                ModelComboBox.DisplayMember = ModelReaderML.DataBase.brand;
                ModelComboBox.ValueMember   = ModelReaderML.DataBase.id;
                ModelComboBox.DataSource    = dtModelReader;

                dtConnection = readerConnectionBLL.All();
                ConectioncomboBox.DisplayMember = ReaderConnectionML.DataBase.name;
                ConectioncomboBox.ValueMember   = ReaderConnectionML.DataBase.id;

                ConectioncomboBox.DataSource = dtConnection;

                LoadControls();
                EnabledControls(false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("LoadData: {0}", ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 3
0
        public int Update(ReaderConnectionML readerConnectionML, string ConnectionString)
        {
            try
            {
                if (readerConnectionML != null)
                {
                    if (readerConnectionML.isDefault)
                    {
                        StringBuilder QueryUpdate = new StringBuilder();
                        QueryUpdate.AppendFormat("UPDATE {0} SET ", TableName);
                        QueryUpdate.AppendFormat("{0} = Convert(Bit, 'false')", ReaderConnectionML.DataBase.isDefault);

                        SqlConnection ConexionUpdate = new SqlConnection
                        {
                            ConnectionString = ConnectionString
                        };

                        using (SqlCommand cmd2Update = new SqlCommand(QueryUpdate.ToString(), ConexionUpdate))
                        {
                            ConexionUpdate.Open();
                            cmd2Update.ExecuteScalar();
                            if (ConexionUpdate.State == System.Data.ConnectionState.Open)
                            {
                                ConexionUpdate.Close();
                            }
                        }
                    }


                    StringBuilder Query = new StringBuilder();
                    Query.AppendFormat("UPDATE {0} SET ", TableName);
                    Query.AppendFormat("{0} = '{1}', ", ReaderConnectionML.DataBase.name, readerConnectionML.name);
                    Query.AppendFormat("{0} = '{1}', ", ReaderConnectionML.DataBase.ip, readerConnectionML.ip);
                    Query.AppendFormat("{0} = '{1}', ", ReaderConnectionML.DataBase.port, readerConnectionML.port);
                    Query.AppendFormat("{0} =  convert(bit, '{1}'), ", ReaderConnectionML.DataBase.isDefault, readerConnectionML.isDefault);
                    Query.AppendFormat("{0} = {1}, ", ReaderConnectionML.DataBase.idReader, readerConnectionML.idReader);
                    Query.AppendFormat("idUserUpdate = {0}, ", idUser);
                    Query.AppendLine("dateUpdate = GETDATE() ");
                    Query.AppendFormat("WHERE id = {0}", readerConnectionML.id);

                    SqlConnection Conexion = new SqlConnection()
                    {
                        ConnectionString = ConnectionString
                    };

                    Conexion.Open();
                    SqlCommand cmd2 = new SqlCommand(Query.ToString(), Conexion);
                    cmd2.ExecuteNonQuery();
                    Conexion.Close();

                    return(readerConnectionML.id);
                }

                return(0);
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("{0}.Update : {1}", core, ex));
            }
        }
Exemplo n.º 4
0
 private void AddButton_Click(object sender, EventArgs e)
 {
     CancelButton.Visible = true;
     AddButton.Enabled    = false;
     ClearControls();
     ConectioncomboBox.Enabled = false;
     EnabledControls(true);
     readerConnectionML    = new ReaderConnectionML();
     readerConnectionML.id = 0;
     SaveButton.Enabled    = true;
 }
Exemplo n.º 5
0
 public int save(ReaderConnectionML readerConnectionML)
 {
     try
     {
         if (readerConnectionML.id > 0)
         {
             return(readerConnectionDAL.Update(readerConnectionML, ConnectionStrings));
         }
         else
         {
             return(readerConnectionDAL.Insert(readerConnectionML, ConnectionStrings));
         }
     }
     catch (Exception ex)
     {
         throw new Exception(String.Format("{0}.Save: {1}", core, ex));
     }
 }
Exemplo n.º 6
0
        private void LoadConnection(int id)
        {
            try
            {
                ReaderConnectionBLL readerConnectionBLL = new ReaderConnectionBLL();
                ReaderConnectionML  readerConnectionML  = readerConnectionBLL.GetConnectionById(id);

                NameConectiontextBox.Text  = readerConnectionML.name;
                IPtextBox.Text             = readerConnectionML.ip;
                PortTextBox.Text           = readerConnectionML.port;
                DefaultCheckBox.Checked    = readerConnectionML.isDefault;
                ModelComboBox.SelectedItem = readerConnectionML.idReader;
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("LoadConnection: {0}", ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 7
0
        public bool connect()
        {
            try
            {
                ReaderConnectionBLL readerConnectionBLL = new ReaderConnectionBLL();
                ReaderConnectionML  readerConnectionML  = readerConnectionBLL.GetActiveConnection();

                if (readerConnectionML != null)
                {
                    return(connect(readerConnectionML.ip, int.Parse(readerConnectionML.port)));
                }
                else
                {
                    throw new Exception("No se encontró una conexión valida");
                }
            }catch (Exception ex)
            {
                throw new Exception(string.Format("ZKTecoDeviceBLL.connect: {0}", ex.Message));
            }
        }
Exemplo n.º 8
0
        public ReaderConnectionML GetEntity(DataRow row)
        {
            try
            {
                if (row != null)
                {
                    ReaderConnectionML readerConnectionML = new ReaderConnectionML()
                    {
                        ip        = (row[ReaderConnectionML.DataBase.ip] != DBNull.Value) ? row[ReaderConnectionML.DataBase.ip].ToString() : string.Empty,
                        port      = (row[ReaderConnectionML.DataBase.port] != DBNull.Value) ? row[ReaderConnectionML.DataBase.port].ToString() : string.Empty,
                        name      = (row[ReaderConnectionML.DataBase.name] != DBNull.Value) ? row[ReaderConnectionML.DataBase.name].ToString() : string.Empty,
                        isDefault = (row[ReaderConnectionML.DataBase.isDefault] != DBNull.Value) ? Convert.ToBoolean(row[ReaderConnectionML.DataBase.isDefault].ToString()) : false,
                    };

                    return(readerConnectionML);
                }

                return(null);
            }catch (Exception ex)
            {
                throw new Exception(String.Format("{0}.ReaderConnectionML : {1}", core, ex));
            }
        }
Exemplo n.º 9
0
        public int Insert(ReaderConnectionML readerConnectionML, string ConnectionString)
        {
            try
            {
                if (readerConnectionML != null)
                {
                    if (readerConnectionML.isDefault)
                    {
                        StringBuilder QueryUpdate = new StringBuilder();
                        QueryUpdate.AppendFormat("UPDATE {0} SET ", TableName);
                        QueryUpdate.AppendFormat("{0} = Convert(Bit, 'false')", ReaderConnectionML.DataBase.isDefault);

                        SqlConnection ConexionUpdate = new SqlConnection
                        {
                            ConnectionString = ConnectionString
                        };

                        using (SqlCommand cmd2 = new SqlCommand(QueryUpdate.ToString(), ConexionUpdate))
                        {
                            ConexionUpdate.Open();
                            cmd2.ExecuteScalar();
                            if (ConexionUpdate.State == System.Data.ConnectionState.Open)
                            {
                                ConexionUpdate.Close();
                            }
                        }
                    }

                    StringBuilder Query = new StringBuilder();
                    Query.AppendFormat("INSERT INTO {0}", TableName);
                    Query.AppendFormat("({0}, {1}, {2}, {3}, {4}, _registry, idUserInsert, dateInsert)", ReaderConnectionML.DataBase.name, ReaderConnectionML.DataBase.ip, ReaderConnectionML.DataBase.port, ReaderConnectionML.DataBase.isDefault, ReaderConnectionML.DataBase.idReader);
                    Query.AppendLine(" VALUES( ");
                    Query.AppendFormat(" '{0}', ", readerConnectionML.name);
                    Query.AppendFormat(" '{0}', ", readerConnectionML.ip);
                    Query.AppendFormat(" '{0}', ", readerConnectionML.port);
                    Query.AppendFormat(" convert(bit, '{0}'), ", readerConnectionML.isDefault);
                    Query.AppendFormat(" {0}, ", readerConnectionML.idReader);
                    Query.AppendLine(" 1, ");
                    Query.AppendFormat(" {0}, ", idUser);
                    Query.AppendLine(" GETDATE()) ");
                    Query.AppendLine(" SELECT CAST(scope_identity() AS int)");
                    SqlConnection Conexion = new SqlConnection
                    {
                        ConnectionString = ConnectionString
                    };

                    using (SqlCommand cmd2 = new SqlCommand(Query.ToString(), Conexion))
                    {
                        Conexion.Open();
                        int newID = (Int32)cmd2.ExecuteScalar();

                        if (Conexion.State == System.Data.ConnectionState.Open)
                        {
                            Conexion.Close();
                        }
                        return(newID);
                    }
                }

                return(0);
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("{0}.Insert : {1}", core, ex));
            }
        }