Exemplo n.º 1
0
        public static bool ChangeProduct( System.Data.SqlClient.SqlConnection connection,
                                          System.Data.SqlClient.SqlTransaction tran,
                                          object old_product_id, object new_product_id, out string error)
        {
            bool done = false;
            error = "";
            try
            {
                connection.Open();
                System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
                string query = "UPDATE Purchases.ReceiptContents SET ProductID = @NewProduct\n" +
                                "WHERE ProductID = @OldProduct";
                cmd.Parameters.AddWithValue("@NewProduct", new_product_id);
                cmd.Parameters.AddWithValue("@OldProduct", old_product_id);
                cmd.CommandTimeout = 0;
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.CommandText = query;
                cmd.Connection = connection;
                if (tran != null) cmd.Transaction = tran;
                cmd.ExecuteNonQuery();
                connection.Close();
                done = true;
            }
            catch (System.Exception ex)
            {
                error = ex.Message;
            }
            finally
            {
                if (connection.State == System.Data.ConnectionState.Open) connection.Close();
            }

            return done;
        }
Exemplo n.º 2
0
 public static bool Delete(System.Data.SqlClient.SqlConnection connection, System.Data.DataRow row, out string message)
 {
     bool done = false;
     message = "";
     try
     {
         connection.Open();
         System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
         string sQuery = "DELETE FROM " + Categories.Table + "\n" +
                         " WHERE CategoryID = @CategoryID";
         cmd.Parameters.AddWithValue("@CategoryID", row["CategoryID"]);
         cmd.Connection = connection;
         cmd.CommandTimeout = 0;
         cmd.CommandType = System.Data.CommandType.Text;
         cmd.CommandText = sQuery;
         cmd.ExecuteNonQuery();
         connection.Close();
         done = true;
     }
     catch (System.Exception ex)
     {
         message = ex.Message;
     }
     finally
     {
         if (connection.State == System.Data.ConnectionState.Open) connection.Close();
     }
     return done;
 }
Exemplo n.º 3
0
 public static bool Delete(System.Data.SqlClient.SqlConnection connection,
                           System.Data.SqlClient.SqlTransaction tran,
                           System.Data.DataRow row, out string message)
 {
     bool done = false;
     message = "";
     try
     {
         connection.Open();
         System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
         string sQuery = "DELETE FROM Producer.Products\n" +
                         " WHERE ProductID = @ProductID";
         cmd.Parameters.AddWithValue("@ProductID", row["ProductID"]);
         cmd.Connection = connection;
         if (tran != null) cmd.Transaction = tran;
         cmd.CommandTimeout = 0;
         cmd.CommandType = System.Data.CommandType.Text;
         cmd.CommandText = sQuery;
         cmd.ExecuteNonQuery();
         connection.Close();
         done = true;
     }
     catch (System.Exception ex)
     {
         message = ex.Message;
     }
     finally
     {
         if (connection.State == System.Data.ConnectionState.Open) connection.Close();
     }
     return done;
 }
Exemplo n.º 4
0
 public static bool Exists(System.Data.SqlClient.SqlConnection connection, string category_name, out bool exists, out string message)
 {
     bool ret = false;
     exists = false;
     message = "";
     Guid cat_id = Guid.Empty;
     try
     {
         connection.Open();
         string sQuery = "SELECT CategoryID\n" +
                         "  FROM " + Categories.Table + "\n" +
                         " WHERE CategoryName = @Category";
         System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sQuery);
         cmd.Parameters.AddWithValue("@Category", category_name );
         cmd.Connection = connection;
         object res = cmd.ExecuteScalar();
         if (res != null && !System.Convert.IsDBNull(res)) cat_id = (Guid)res;
         connection.Close();
         exists = (cat_id != Guid.Empty);
         ret = true;
     }
     catch (System.Exception ex)
     {
         message = ex.Message;
     }
     finally
     {
         if (connection.State == System.Data.ConnectionState.Open) connection.Close();
     }
     return ret;
 }
Exemplo n.º 5
0
        /// <summary>
        /// �������� ������ � �� � ���������� �����
        /// </summary>
        /// <param name="connection">��������� � ��</param>
        /// <param name="row">������</param>
        /// <param name="message">�������� ��������� �� ������, ���� ����� ���������� ����</param>
        /// <returns>����� ���������� ������, ���� �� �������� ������; ���� - � ��������� ������</returns>
        public static bool Delete(System.Data.SqlClient.SqlConnection connection, System.Data.DataRow row, /*byte[] image,*/ out string message)
        {
            bool done = false;
            message = "";
            try{
                connection.Open();
                System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
                string sQuery = "IF EXISTS (SELECT DiscountCard\n" +
                                "             FROM Purchases.Receipts\n" +
                                "            WHERE Purchases.Receipts.DiscountCard = @CardID ) \n" +
                                "   UPDATE Purchases.DiscountCards\n" +
                                "      SET Expired = GETDATE()\n" +
                                "    WHERE CardID = @CardID\n" +
                                "ELSE\n" +
                                "   DELETE\n" +
                                "     FROM Purchases.DiscountCards\n" +
                                "    WHERE CardID = @CardID";

                cmd.Parameters.AddWithValue("@CardID", row["CardID"]);
                cmd.Connection = connection;
                cmd.CommandTimeout = 0;
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.CommandText = sQuery;
                cmd.ExecuteNonQuery();
                connection.Close();
                done = true;
            }catch (System.Exception ex){
                message = ex.Message;
            }finally{
                if (connection.State == System.Data.ConnectionState.Open) connection.Close();
            }
            return done;
        }
Exemplo n.º 6
0
        protected override int InsertAndReturnNewID(System.Data.IDbConnection conn, IQMap.ISqlQuery query, System.Data.IDbTransaction transaction = null, System.Data.CommandBehavior commandBehavior = System.Data.CommandBehavior.Default)
        {
            //var newQuery= new SqlQueryDef(, query.Parameters);

            var newQ= new IQMap.SqlQueryBuilder.Impl.SqlQueryDef( query.GetQuery() + "", query.Parameters);
            int result = 0;

            using (var cmd = GetCommand(conn, newQ, transaction))
            {

                ExecuteSqlFinal(new Action(() =>
                {
                    cmd.ExecuteNonQuery();
                }));

                cmd.Parameters.Clear();
                cmd.CommandText = "SELECT @@IDENTITY;";
                result = Convert.ToInt32(cmd.ExecuteScalar());
                cmd.Dispose();
            }
            if (commandBehavior == CommandBehavior.CloseConnection)
            {
                conn.Close();
            }
            OnQueryComplete();
            return result;
        }
Exemplo n.º 7
0
		/// <summary>
		/// [可重入]关闭连接
		/// </summary>
		/// <param name="Connection"></param>
		public static void Close(System.Data.Common.DbConnection Connection)
		{
			if (Connection != null && Connection.State != System.Data.ConnectionState.Closed)
			{
				Connection.Close();
			}
		}
            public Header(System.Data.SQLite.SQLiteConnection connection)
            {
                System.Collections.Hashtable hash = null;

                using (System.Data.SQLite.SQLiteCommand tSQLiteCommand = connection.CreateCommand())
                {

                    tSQLiteCommand.CommandText = clientBuildCommand;
                    using (System.Data.SQLite.SQLiteDataReader reader = tSQLiteCommand.ExecuteReader())
                    {
                        int total = reader.RecordsAffected;
                        hash = new System.Collections.Hashtable(total);
                        while (reader.Read())
                        {
                            hash[reader.GetString(0)] = reader.GetValue(1);
                        }
                        reader.Close();
                    }


                }

                clientBuild = int.Parse((string)hash["clientBuild"]);
                accountName = (string)hash["accountName"];
                realmname = (string)hash["realmName"];
                realmServer = (string)hash["realmServer"];


                connection.Close();
            }
Exemplo n.º 9
0
 // Занесение новой записи в БД
 public static bool Insert(System.Data.SqlClient.SqlConnection connection, System.Data.DataRow row, out string message)
 {
     bool done = false;
     message = "";
     try{
         connection.Open();
         System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
         string sQuery = "INSERT INTO " + Maker.Table + "\n" +
                         "       (MakerID, Name, MakerCategory, Vendor, Address, Created, Updated)\n" +
                         "VALUES (@MakerID, @Name, @MakerCategory, @Vendor, @Address, GETDATE(), GETDATE())";
         cmd.Parameters.AddWithValue("@MakerID", row["MakerID"]);
         cmd.Parameters.AddWithValue("@Name", row["Name"]);
         cmd.Parameters.AddWithValue("@MakerCategory", row["MakerCategory"]);
         cmd.Parameters.AddWithValue("@Vendor", row["Vendor"]);
         cmd.Parameters.AddWithValue("@Address", row["Address"]);
         //cmd.Parameters.AddWithValue("@Created", row["Created"]);
         //cmd.Parameters.AddWithValue("@Updated", row["Updated"]);
         cmd.Connection = connection;
         cmd.CommandTimeout = 0;
         cmd.CommandType = System.Data.CommandType.Text;
         cmd.CommandText = sQuery;
         cmd.ExecuteNonQuery();
         connection.Close();
         done = true;
     }catch (System.Exception ex){
         message = ex.Message;
     }finally{
         if (connection.State == System.Data.ConnectionState.Open) connection.Close();
     }
     return done;
 }
Exemplo n.º 10
0
 public static string ReadFromStream(System.IO.Stream stream, long count)
 {
     byte[] buffer = new byte[count];
     stream.Read(buffer, 0, (int)count);
     stream.Close();
     return System.Text.Encoding.UTF8.GetString(buffer);
 }
Exemplo n.º 11
0
        public static List<Employee> Load(System.IO.StreamReader stream)
        {
            List<Employee> list = new List<Employee>();

            try
            {
                while (stream.Peek() >= 0)
                {
                    string line = stream.ReadLine();

                    string[] values = line.Split(',');
                    Employee employee = new Employee();
                    employee.FirstName = values[0];
                    employee.LastName = values[1];
                    employee.Email = values[2];

                    list.Add(employee);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                stream.Close();
            }

            return list;
        }
Exemplo n.º 12
0
 public static bool CloseForm(System.Windows.Forms.Form form)
 {
     if (form == null || form.IsDisposed) return false;
     try { form.Close(); }
     catch { return false; }
     return true;
 }
Exemplo n.º 13
0
        public static void WriteToStream(System.IO.Stream stream, string data)
        {
            byte[] buffer = System.Text.Encoding.UTF8.GetBytes(data);

            stream.Write(buffer, 0, buffer.Length);
            stream.Close();
        }
Exemplo n.º 14
0
 private void PurgeSingleFile(System.IO.Stream stream, string filename)
 {
     if (stream != null)
         stream.Close();
     if (System.IO.File.Exists(filename))
         System.IO.File.Delete(filename);
 }
Exemplo n.º 15
0
		public static void Main (string[] args)
		{


			MySqlConnection mySqlConnection= new MySqlConnection("" +
			                                                     "Server= localhost;Database=dbprueba;User ID = root; Password= sistemas"");

mySqlConnection.Open();	

Console.WriteLine ("Hello World!");

MySqlCommand mySqlCommand= mySqlConnection.CreateCommand();
mySqlCommand.CommandText= string.Format("insert into categoria(nombre)values ('{0}')", DateTime.Now);
mySqlCommand.ExecuteNonQuery;

mySqlCommand.CommandText= "select * from categoria";

MySqlDataReader mySqlDataReader= mySqlCommand.ExecuteReader();
Console.WriteLine("FieldCount={0}", mySqlDataReader.FieldCount);
for(int index=0; index < mySqlDataReader.FieldCount; index++)
Console.WriteLine("colum{0}={1}", indexer, mySqlDataReader.getName(indexer));

while(mySqlDataReader.Read()){
object id= mySqlDataReader["nombre"];
Console.WriteLine("id={0} nombre={1}", id , nombre);

mySqlDataReader.Close();


mySqlConnection.Close();
}
}
Exemplo n.º 16
0
 /// <summary>
 /// Function for close message
 /// </summary>
 /// <param name="frm"></param>
 public static void CloseMessage(System.Windows.Forms.Form frm)
 {
     if ((MessageBox.Show("Are you sure to exit ? ", "OpenMiracle", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) == DialogResult.Yes)
     {
         frm.Close();
     }
 }
Exemplo n.º 17
0
 public static bool CloseWindow(System.Windows.Window window)
 {
     if (window == null) return false;
     try { window.Close(); }
     catch { return false; }
     return true;
 }
Exemplo n.º 18
0
        public void Receive(System.Net.Sockets.Socket socket, out string mml)
        {
            mml = null;

            string v23MmlDocument;

            try
            {
                // MMLドキュメントサイズを受信
                byte[] lengthBuffer = new byte[4];

                if (!ReceiveData(socket, lengthBuffer, lengthBuffer.Length))
                    new Yos731.MmlReceiver.MmlReceiverException("Failure to receive mml length.", null);

                int length = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(lengthBuffer, 0));

                // MMLドキュメントを受信
                byte[] dataBuffer = new byte[length];

                if (!ReceiveData(socket, dataBuffer, length))
                    new Yos731.MmlReceiver.MmlReceiverException("Failure to receive mml data.", null);

                v23MmlDocument = Encoding.Unicode.GetString(dataBuffer);

                // ACK(0x1)を送信
                byte[] ackData = new byte[1];
                ackData[0] = 0x1;
                SendData(socket, ackData, ackData.Length);
            }
            catch (Yos731.MmlReceiver.MmlReceiverException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                // 発生した例外をスロー
                throw new Yos731.MmlReceiver.MmlReceiverException("Failure to receive MML document.", e);
            }
            finally
            {
                socket.Close();
            }

            // 受信したMML Version 2.3ドキュメントをMML Version 3.0ドキュメントに変換
            try
            {
                XElement v23Mml = XElement.Parse(v23MmlDocument);

                mml = convertV23toV30(v23Mml);
            }
            catch (Yos731.MmlReceiver.MmlReceiverException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new Yos731.MmlReceiver.MmlReceiverException("Failure to convert MML Document from v2.3 to v3.0", e);
            }
        }
Exemplo n.º 19
0
 public void closeService(System.Data.SqlClient.SqlConnection _conn)
 {
     if (_conn != null && _conn.State != System.Data.ConnectionState.Closed)
     {
         _conn.Dispose();
         _conn.Close();
     }
 }
Exemplo n.º 20
0
 public void Close()
 {
     lock (SyncRoot)
     {
         System.Close();
         Data.Close();
     }
 }
Exemplo n.º 21
0
 public void play(System.IO.Stream stream)
 {
     byte[] buf = new byte[stream.Length];
     int SND_MEMORY = 0x4;
     stream.Read(buf, 0, buf.Length);
     stream.Close();
     sndPlaySoundA(buf, SND_MEMORY);
 }
Exemplo n.º 22
0
 public static void ValidateSession(System.Windows.Forms.Form frm, Woodensoft.TitherPro.Domain.Contexts.User u)
 {
     if (u == null)
     {
         frm.Close();
         throw new Exception("You are not logged in!");
     }
 }
 private byte[] GetStreamAsByteArray(System.IO.Stream stream)
 {
     int streamLength = Convert.ToInt32(stream.Length);
     byte[] fileData = new byte[streamLength];
     stream.Read(fileData, 0, streamLength);
     stream.Close();
     return fileData;
 }
Exemplo n.º 24
0
 /// <summary>
 /// 将内存流反序列为对像
 /// </summary>
 /// <param name="memStream">内存流</param>
 /// <returns></returns>
 public static object DeSerializeMemoryStream(System.IO.MemoryStream memStream)
 {
     memStream.Position = 0;
     System.Runtime.Serialization.Formatters.Binary.BinaryFormatter deserializer = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
     object newobj = deserializer.Deserialize(memStream);
     memStream.Close();
     return newobj;
 }
Exemplo n.º 25
0
        /// <summary>
        /// Method to insert a new company to database
        /// </summary>
        /// <param name="connection">SQL connection</param>
        /// <param name="row">A row of type System.Data.DataRow - a single company</param>
        /// <param name="message">Error message, if method returns 'false' itself</param>
        /// <returns>Returns 'true' in success, 'false' - in other cases.</returns>
        public static bool Insert(System.Data.SqlClient.SqlConnection connection, ref System.Data.DataRow row, out string message)
        {
            bool done = false;
            message = "";
            try
            {
                connection.Open();
                System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
                string sQuery = "SELECT NEWID() AS NewCompanyID\n" +
                                "  FROM " + Companies.Table;
                cmd.CommandText = sQuery;
                cmd.Connection = connection;
                object res = cmd.ExecuteScalar();
                if (!System.Convert.IsDBNull(res))
                {
                    Guid new_id = (Guid)res;
                    row["CompanyID"] = new_id;

                    sQuery = "INSERT INTO " + Companies.Table + "\n" +
                             "       (CompanyID, ParentID, CompanyName, [Address], WebSite, Phones, Created, Updated)\n" +
                             "VALUES (@CompanyID, @ParentID, @CompanyName, @Address, @WebSite, @Phones, GETDATE(), GETDATE())";
                    cmd.Parameters.AddWithValue("@CompanyID", row["CompanyID"]);
                    cmd.Parameters.AddWithValue("@ParentID", row["ParentID"]);
                    cmd.Parameters.AddWithValue("@CompanyName", row["CompanyName"]);
                    cmd.Parameters.AddWithValue("@Address", row["Address"]);
                    cmd.Parameters.AddWithValue("@WebSite", row["WebSite"]);
                    cmd.Parameters.AddWithValue("@Phones", row["Phones"]);
                    cmd.Connection = connection;
                    cmd.CommandTimeout = 0;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = sQuery;
                    cmd.ExecuteNonQuery();
                    done = true;
                }
                connection.Close();
            }
            catch (System.Exception ex)
            {
                message = ex.Message;
            }
            finally
            {
                if (connection.State == System.Data.ConnectionState.Open) connection.Close();
            }
            return done;
        }
Exemplo n.º 26
0
 //获取Hash描述表
 public bool GetHash(System.IO.FileStream objFile, ref byte[] HashData)
 {
     //从文件中取得Hash描述
     System.Security.Cryptography.HashAlgorithm MD5 = System.Security.Cryptography.HashAlgorithm.Create("MD5");
     HashData = MD5.ComputeHash(objFile);
     objFile.Close();
     return true;
 }
Exemplo n.º 27
0
        public DataRow retornaFila()
        {
            Formas.fCatalogo f = new SOPORTEC.Formas.fCatalogo(dt,"Nombre del Catalogo",2, );
                f.ShowDialog();
                rw = f.fila;
                f.Close();
                f.Dispose();

            return rw;
        }
Exemplo n.º 28
0
 static void SaveStreamToFile(System.IO.Stream stream, string filePath)
 {
     Console.WriteLine("Saving to file {0}", filePath);
     FileStream outstream = File.Open(filePath, FileMode.Create, FileAccess.Write);
     CopyStream(stream, outstream);
     outstream.Close();
     stream.Close();
     Console.WriteLine();
     Console.WriteLine("File {0} saved", filePath);
 }
Exemplo n.º 29
0
        public void Read(System.IO.Stream stream)
        {
            br = new BinaryReader(stream);

            byte[] headerBytes = FindHeader();
            ParseHeader(headerBytes);

            br.Close();
            stream.Close();
        }
Exemplo n.º 30
0
 //获取Hash描述表
 public bool GetHash(System.IO.FileStream objFile, ref string strHashData)
 {
     //从文件中取得Hash描述
     byte[] HashData;
     System.Security.Cryptography.HashAlgorithm MD5 = System.Security.Cryptography.HashAlgorithm.Create("MD5");
     HashData = MD5.ComputeHash(objFile);
     objFile.Close();
     strHashData = Convert.ToBase64String(HashData);
     return true;
 }
Exemplo n.º 31
0
 public void CloseDBConnection(System.Data.SqlClient.SqlConnection DBConn)
 {
     try
     {
         if (DBConn != null)
             DBConn.Close();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }