Esempio n. 1
0
        public List <ImportStaging> getData()
        {
            var buffer = new List <ImportStaging>();

            try
            {
                using (var conn = new SqlConnection(Properties.Settings.Default.ConnStr))
                    using (var comm = conn.CreateCommand())
                    {
                        comm.CommandType = CommandType.Text;
                        comm.CommandText = Properties.Resources.GetCmd;
                        conn.Open();
                        Console.WriteLine("Connection Open...");
                        using (var rdr = comm.ExecuteReader())
                        {
                            Console.WriteLine("Execute Query...");
                            while (rdr.Read())
                            {
                                var t = new ImportStaging();
                                t.AxId      = rdr.GetString(rdr.GetOrdinal("AxId"));
                                t.Action    = rdr.GetByte(rdr.GetOrdinal("Action"));
                                t.Module    = rdr.GetByte(rdr.GetOrdinal("Module"));
                                t.Status    = rdr.GetByte(rdr.GetOrdinal("Status"));
                                t.Partition = rdr.GetString(rdr.GetOrdinal("Partition"));
                                t.CommonKey = rdr.GetString(rdr.GetOrdinal("CommonKey"));
                                t.Data      = Encoding.Unicode.GetBytes(rdr.GetString(rdr.GetOrdinal("Data")));
                                t.Log       = rdr.GetString(rdr.GetOrdinal("Log"));
                                buffer.Add(t);
                            }
                            rdr.Close();
                        }

                        conn.Close();
                        comm.Dispose();
                        conn.Dispose();
                    }
                Console.WriteLine("Connection Close...");
            }
            catch (InvalidCastException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(buffer);
        }
Esempio n. 2
0
        public bool setStatusbyCommonKey(ImportStaging updated)
        {
            var res = false;

            try
            {
                using (var conn = new SqlConnection(Properties.Settings.Default.ConnStr))
                    using (var comm = conn.CreateCommand())
                    {
                        comm.CommandText = Properties.Resources.SetCmd;
                        comm.Parameters.AddWithValue("@axid", updated.AxId);
                        comm.Parameters.AddWithValue("@status", updated.Status);
                        comm.Parameters.Add("@log", SqlDbType.NVarChar).Value = updated.Log;
                        comm.Parameters.AddWithValue("@key", updated.CommonKey);
                        comm.Parameters.AddWithValue("@module", updated.Module);
                        conn.Open();
                        if (comm.ExecuteNonQuery() > 0)
                        {
                            res = true;
                            Console.WriteLine("Status Changed...");
                        }
                        conn.Close();
                        comm.Dispose();
                        conn.Dispose();
                    }
            }
            catch (InvalidCastException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(res);
        }