当前位置: 首页>>代码示例>>C#>>正文


C# FbTransaction.Commit方法代码示例

本文整理汇总了C#中FirebirdSql.Data.FirebirdClient.FbTransaction.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# FbTransaction.Commit方法的具体用法?C# FbTransaction.Commit怎么用?C# FbTransaction.Commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FirebirdSql.Data.FirebirdClient.FbTransaction的用法示例。


在下文中一共展示了FbTransaction.Commit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Client

        public Client(TcpClient Client_)
        {
            byte[] bf = { 1 };
            Client_.GetStream().Write(bf, 0, bf.Length);
            uint BytesCount;

            while (true)
            {
                try
                {
                    BytesCount = (uint)Client_.GetStream().Read(Buff, 0, Buff.Length);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    break;
                }
                if (Msg.IMEI == 0 && Buff.Length > 0)
                {
                    try
                    {
                        Msg.IMEI = Msg.GetIMEI(BytesCount, Buff);
                        if (!Dictionary_.ContainsKey(Msg.IMEI))
                        {
                            Dictionary_.Add(Msg.IMEI, true);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        break;
                    }
                    Console.WriteLine("Client: " + Msg.IMEI + " connected!");
                    //foreach (KeyValuePair<Int64, bool> kvp in Dictionary)
                    //{
                    //    Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
                    //}
                    continue;
                }
                else if (Msg.IMEI > 0)
                {
                    Msg.InitComponents(Buff);
                    uint offset = Msg.GetOffset();
                    try
                    {
                        Console.WriteLine("[{0}] " + " [" + DateTime.Now + "]", Msg.IMEI);
                        DataBaseConnect();
                        fbt = fb.BeginTransaction();
                        List<Message> InvalidMsg = new List<Message>();
                        for (int i = 0; i < Msg.MessageCount; i++)
                        {
                            Msg.DTime = Msg.ByteToDateTime(offset + 2, Buff);
                            Msg.Longitude = Msg.ByteToInt(offset + 11, Buff);
                            Msg.Latitude = Msg.ByteToInt(offset + 15, Buff);
                            Msg.Speed = Msg.ByteToShort(offset + 24, Buff);
                            offset -= 33;
                            if (Msg.Speed == 0)
                            {
                                InvalidMsg.Add(Msg);
                                if (InvalidMsg.Count == Msg.MessageCount)
                                {
                                    Dictionary_[Msg.IMEI] = false;
                                    break;
                                }
                            }
                            else if (Msg.Speed != 0)
                            {
                                if (InvalidMsg.Count > 0)
                                {
                                    Int32 AVGLongitude = 0;
                                    Int32 AVGLatitude = 0;
                                    DateTime TempDateTime;
                                    TempDateTime = InvalidMsg.Last().DTime;
                                    //foreach (var item in InvalidMsg)
                                    //{
                                    //    AVGLongitude += item.Longitude;
                                    //    AVGLatitude += item.Latitude;
                                    //}
                                    //AVGLongitude = AVGLongitude / InvalidMsg.Count;
                                    //AVGLatitude = AVGLatitude / InvalidMsg.Count;
                                    AVGLongitude = InvalidMsg.Last().Longitude;
                                    AVGLatitude = InvalidMsg.Last().Latitude;
                                    DataBaseSendData(Msg.IMEI, TempDateTime, (Int32)AVGLatitude, (Int32)AVGLongitude, InvalidMsg.Last().Speed);
                                    InvalidMsg.Clear();
                                }
                                DataBaseSendData(Msg.IMEI, Msg.DTime, Msg.Latitude, Msg.Longitude, Msg.Speed);
                                Dictionary_[Msg.IMEI] = true;
                            }
                        }
                        fbt.Commit();
                        InvalidMsg.Clear();
                        fb.Close();
                        break;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
//.........这里部分代码省略.........
开发者ID:Igorurievich,项目名称:GPS_System,代码行数:101,代码来源:Client.cs

示例2: DataBaseSendData

 private void DataBaseSendData(long IMEI, DateTime dt, int latitude, int longitude, int speed, FbConnection fb)
 {
     if ((latitude != 0) && (longitude != 0))
     {
         fbt = fb.BeginTransaction();
         using (
             var insertSQL = new FbCommand("insert into sms" +"(sms.IMEI, sms.DATE_, sms.TIME_, sms.LATITUDE, sms.LONGITUDE, sms.SPEED) values('"+ IMEI 
             + "','" + dt.ToShortDateString() 
             + "','" + dt.ToLongTimeString() 
             + "','" + latitude 
             + "','" + longitude 
             + "','" + speed 
             + "');", fb)) // using Firebird DB, FBCommand haven't method "AddWithValue".
         {
             if (fb.State == ConnectionState.Closed)
             {
                 fb.Open();
             }
             insertSQL.Transaction = fbt;
             try
             {
                 insertSQL.ExecuteNonQueryAsync();
                 fbt.Commit();
             }
             catch (Exception ex)
             {
                 fbt.Rollback();
                 Log.Add(ex.Message + "\r\n" + ex.Source + "\r\n" + ex.TargetSite);
             }
         }
     }
 }
开发者ID:Igorurievich,项目名称:GPS-Tracking-System,代码行数:32,代码来源:Client.cs


注:本文中的FirebirdSql.Data.FirebirdClient.FbTransaction.Commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。