コード例 #1
0
ファイル: SyncFromServerModel.cs プロジェクト: whuacn/CJia
        private async Task <bool> SyncDataToLocal(string SqlDelete, string SqlInsert, List <Data.DataObject> DataList, Data.iDeviceTableChange itc)
        {
            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(iDB.DbFile))
            {
                conn.BeginTransaction();
                try
                {
                    EventArgs Arg = UpdateLocalData(conn, SqlDelete, SqlInsert, DataList, itc.TableName, itc.PrimaryKey);
                    conn.Delete(itc); conn.Insert(itc);
                    //更新服务器上该设备的同步日志,确保下次不再同步
                    bool isSaveSuccess = await SaveDeviceSyncLog(iCommon.DeviceID, itc.TableName, itc.LastChangeDate);

                    if (isSaveSuccess)
                    {
                        conn.Commit();
                        if (itc.TableName == "DoctorCheckLog")
                        {
                            iCommon.OnCheckLogSyncComplet(Arg);
                        }
                    }
                    else
                    {
                        conn.Rollback();
                        return(false);
                    }
                }
                catch
                {
                    conn.Rollback();
                    return(false);
                }
            }
            return(true);
        }
コード例 #2
0
        /**
         * Deletes a golf course from the ListView and from the database
         */
        private async void DeleteGolfCourse(object sender, EventArgs e)
        {
            var image = sender as Image;
            var tgr   = image.GestureRecognizers[0] as TapGestureRecognizer;
            //for each line, the golf course name is stored in the cross image CommandParameter attribute to be able to identify an image to its golf course
            var name          = tgr.CommandParameter.ToString();
            var confirmDelete = await this.DisplayAlert("Suppression d'un golf", "Voulez vous vraiment supprimer le golf : " + name + " ?", "Oui", "Non");

            if (confirmDelete)
            {
                //remove golf course cell from ListView
                var toDelete = image.BindingContext as GolfCourse;
                var vm       = BindingContext as GolfCourseListViewModel;
                vm.RemoveGolfCourse.Execute(toDelete);

                SQLite.SQLiteConnection connection = DependencyService.Get <ISQLiteDb>().GetConnection();
                try
                {
                    //remove golf course from database
                    connection.BeginTransaction();
                    connection.Delete <GolfCourse>(name);
                    connection.Commit();
                }
                catch (Exception bddException)
                {
                    await this.DisplayAlert("Erreur avec la base de donnée", bddException.StackTrace, "Ok");

                    connection.Rollback();
                }
            }
        }
コード例 #3
0
ファイル: DeviceRegisterModel.cs プロジェクト: whuacn/CJia
 /// <summary>
 /// 保存本地设备所属科室信息
 /// </summary>
 public void SaveLocalDeviceOffice(string DeviceID, List <string> OfficeIDs, List <string> OfficeNames)
 {
     using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(iDB.DbFile))
     {
         conn.BeginTransaction();
         try
         {
             string SqlText           = @"Delete From [iDeviceOffice] Where [DeviceID]=?";
             SQLite.SQLiteCommand cmd = conn.CreateCommand(SqlText, DeviceID);
             cmd.ExecuteNonQuery();
             SqlText         = @"Insert Into [iDeviceOffice] ([DOID],[DeviceID], [OfficeID],[OfficeName],[CreateDate]) Values (@1,@2,@3,@4,@5)";
             cmd.CommandText = SqlText;
             for (int i = 0; i < OfficeIDs.Count; i++)
             {
                 cmd.ClearBindings();
                 cmd.Bind(Guid.NewGuid().ToString());
                 cmd.Bind(DeviceID);
                 cmd.Bind(OfficeIDs[i]); cmd.Bind(OfficeNames[i]);
                 cmd.Bind(iCommon.DateNow);
                 cmd.ExecuteNonQuery();
             }
             conn.Commit();
         }
         catch
         {
             conn.Rollback();
         }
     }
 }
コード例 #4
0
ファイル: SyncFromServerModel.cs プロジェクト: whuacn/CJia
        /// <summary>
        /// 从服务器同步有变化的数据到本地
        /// </summary>
        /// <param name="ChangeTableList"></param>
        /// <returns></returns>
        private async Task <bool> SyncDataFromServer(List <Data.iTableChange> ChangeTableList, SQLite.SQLiteConnection conn, string IsInitData)
        {
            foreach (Data.iTableChange itc in ChangeTableList)
            {
                object Result = await RemoteExcute(new object[] { iCommon.DeviceID, itc.TableName, itc.PrimaryKey, IsInitData });

                if (Result == null)
                {
                    continue;
                }
                List <Data.DataObject> DataList = Deserialize <Data.DataObject>(Result as byte[]);
                if (DataList == null || DataList.Count == 0)
                {
                    continue;
                }

                string          SqlDelete = String.Format(@"Delete From {0} Where {1}=?", itc.TableName, itc.PrimaryKey);
                Data.DataObject bo        = DataList[0];
                string[]        Fields    = bo.FieldArray;
                string          SqlInsert = "Insert Into " + itc.TableName + " (";
                string          txtParams = " (";
                for (int i = 0; i < Fields.Length - 1; i++)
                {
                    SqlInsert += Fields[i] + ",";
                    txtParams += "?,";
                }
                SqlInsert = SqlInsert.TrimEnd(',');
                txtParams = txtParams.TrimEnd(',');
                SqlInsert = SqlInsert + ") Values " + txtParams + ")";
                conn.BeginTransaction();
                try
                {
                    SQLite.SQLiteCommand cmdDelete = conn.CreateCommand(SqlDelete);
                    SQLite.SQLiteCommand cmdInsert = conn.CreateCommand(SqlInsert);
                    foreach (Data.DataObject data in DataList)
                    {
                        cmdDelete.ClearBindings();
                        cmdInsert.ClearBindings();
                        cmdDelete.Bind(data.GetExtValue(itc.PrimaryKey));
                        cmdDelete.ExecuteNonQuery();
                        if (data.GetExtValue("ChangeType") != "DELETE")
                        {
                            for (int d = 0; d < data.Data.Length - 1; d++)
                            {
                                cmdInsert.Bind(data.Data[d]);
                            }
                            cmdInsert.ExecuteNonQuery();
                        }
                    }
                    conn.Delete(itc);
                    conn.Insert(itc);
                    bool isSaveSuccess = await SavePadSyncLog(iCommon.DeviceID, itc.TableName, itc.LastChangeDate);

                    if (isSaveSuccess)
                    {
                        conn.Commit();
                    }
                    else
                    {
                        conn.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    conn.Rollback();
                }
            }
            return(true);
        }
コード例 #5
0
 public void RollbackTransaction()
 {
     _connection.Rollback();
 }