コード例 #1
0
        /// <summary>
        /// Persists any pending updates to the database
        /// </summary>
        /// <returns></returns>
        public static bool SaveTitleUpdates()
        {
            System.Data.Linq.ChangeSet changeset = Dao.DBContext.Instance.GetChangeSet();

            // Find actual SQL run to process the update - debugging purposes
            string s = Dao.DBContext.Instance.GetType().GetMethod("GetChangeText", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(Dao.DBContext.Instance, null) as string;

            // updates all the pending image changes
            foreach (object title in changeset.Updates)
            {
                Dao.Title daoTitle = title as Dao.Title;

                if (daoTitle != null)
                {
                    UpdatesImagesForTitle(daoTitle);
                    Dao.TitleDao.UpdateCollectionsForTitle(daoTitle);

                    daoTitle.ResetPercentComplete();
                }
            }

            // todo : solomon : add error handing and logging here
            Dao.DBContext.Instance.SubmitChanges();
            return(true);
        }
コード例 #2
0
        private void Btn_Save_Click(object sender, EventArgs e)
        {
            try
            {
                ep_gridview.Clear();
                try
                {
                    db.SubmitChanges();
                }
                catch (Exception AnyError)
                {
                    System.Data.Linq.ChangeSet cs = db.GetChangeSet();

                    cs.Inserts.Clear();
                    db.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, cs.Updates);
                    cs.Deletes.Clear();



                    ep_gridview.SetError(Btn_Save, AnyError.Message);
                }


                MessageBox.Show("保存成功");
            }
            catch (Exception AnyError)
            {
                ep_gridview.SetError(gv_Game_BasicRatio, AnyError.Message + Environment.NewLine + AnyError.StackTrace);
                MessageBox.Show("保存失败");
            }
        }
コード例 #3
0
 private void btnApagar_Click(object sender, RoutedEventArgs e)
 {
     //Eliminamos um trabalhador que tenha o CPF digitado pelo usuário:
     using (var ctx = new empresaContext("Data Source=isostore:/Banco.sdf"))
     {
         try
         {
             IEnumerable <Trabalhadores> query = (from c in ctx.Trabalhadores
                                                  where c.Cpf == cpf.Text
                                                  select c).ToList();
             ctx.Trabalhadores.DeleteAllOnSubmit(query);
             System.Data.Linq.ChangeSet cs = ctx.GetChangeSet();
             int qtde = cs.Deletes.Count;
             if (qtde > 0)
             {
                 txtRes.Text = "O CPF foi encontrado: o trabalhador foi eliminado com sucesso.";
             }
             else
             {
                 txtRes.Text = "O trabalhador não foi eliminado.";
             }
             ctx.SubmitChanges();
         }
         catch (Exception errcd)
         {
             txtRes.Text = "Erro: verifique que este CPF exista no banco de dados.";
         }
     }
 } //fim da lógica do botão Apagar
コード例 #4
0
        } //fim da lógica do botão Apagar

        private void btnAlterar_Click(object sender, RoutedEventArgs e)
        {
            //Alteramos os dados de um trabalhador que tenha o CPF digitado pelo usuário:
            using (var ctx = new empresaContext("Data Source=isostore:/Banco.sdf"))
            {
                try
                {
                    var umtrabalhador =
                        (from c in ctx.Trabalhadores
                         where c.Cpf == cpf.Text
                         select c).First();

                    umtrabalhador.Nome    = nome.Text;
                    umtrabalhador.Salario = Convert.ToDouble(salario.Text);
                    umtrabalhador.Sexo    = sexo.Text;

                    System.Data.Linq.ChangeSet cs = ctx.GetChangeSet();
                    int qtde = cs.Updates.Count;
                    if (qtde > 0)
                    {
                        txtRes.Text = "O CPF foi encontrado: o trabalhador foi alterado com sucesso.";
                    }
                    else
                    {
                        txtRes.Text = "O trabalhador não foi alterado.";
                    }

                    ctx.SubmitChanges();
                }
                catch (Exception errcd)
                {
                    txtRes.Text = "Erro: verifique os dados digitados e que este CPF exista no banco de dados.";
                }
            }
        }
コード例 #5
0
        public bool Update <T>(List <T> entities)
        {
            bool returnValue = false;

            foreach (T entity in entities)
            {
                if ((entity as TOOL_ISSUES).IsNotNullOrEmpty())
                {
                    TOOL_ISSUES obj          = null;
                    TOOL_ISSUES activeEntity = (entity as TOOL_ISSUES);

                    obj = (from row in DB.TOOL_ISSUES
                           where row.TOOL_CD == activeEntity.TOOL_CD && row.ISSUE_NO == activeEntity.ISSUE_NO
                           select row).SingleOrDefault <TOOL_ISSUES>();
                    if (obj.IsNotNullOrEmpty())
                    {
                        try
                        {
                            obj.TOOL_CD     = activeEntity.TOOL_CD;
                            obj.ISSUE_NO    = activeEntity.ISSUE_NO;
                            obj.ISSUE_DATE  = activeEntity.ISSUE_DATE;
                            obj.ALTERATIONS = activeEntity.ALTERATIONS;
                            obj.INTL        = activeEntity.INTL;
                            DB.SubmitChanges();

                            System.Data.Linq.ChangeSet cs = DB.GetChangeSet();
                            returnValue = cs.Updates.Count > 0 ? true : false;
                            returnValue = true;
                        }
                        catch (System.Data.Linq.ChangeConflictException)
                        {
                            foreach (System.Data.Linq.ObjectChangeConflict conflict in DB.ChangeConflicts)
                            {
                                conflict.Resolve(System.Data.Linq.RefreshMode.KeepChanges);
                            }
                        }
                        catch (Exception ex)
                        {
                            ex.LogException();
                            DB.TOOL_ISSUES.Context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, obj);
                        }
                    }
                    else
                    {
                        returnValue = Delete <TOOL_ISSUES>(new List <TOOL_ISSUES> {
                            activeEntity
                        });
                        returnValue = Insert <TOOL_ISSUES>(new List <TOOL_ISSUES> {
                            activeEntity
                        });
                    }
                }
            }
            returnValue = true;
            return(returnValue);
        }
コード例 #6
0
        public static void SaveGenreMetaDataChanges()
        {
            System.Data.Linq.ChangeSet changeset = Dao.DBContext.Instance.GetChangeSet();

            // Find actual SQL run to process the update - debugging purposes
            string s = Dao.DBContext.Instance.GetType().GetMethod("GetChangeText", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(Dao.DBContext.Instance, null) as string;

            // updates all the pending image changes
            foreach (object gmd in changeset.Updates)
            {
                Dao.GenreMetaData daoGMD = gmd as Dao.GenreMetaData;

                if (daoGMD != null)
                {
                    UpdatesImagesForGenreMetaData(daoGMD);
                }
            }
            Dao.DBContext.Instance.SubmitChanges();
        }
コード例 #7
0
 private void BtnSave_Click(object sender, EventArgs e)
 {
     try
     {
         //db.ExecuteCommand("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED");
         //db.ObjectTrackingEnabled = false;
         db.SubmitChanges();
         BS_GV_DATA.DataSource = db.WX_BounsConfig.Where(t => t.aspnet_UserID == GlobalParam.UserKey).OrderBy(t => t.RowNumber);;
         MessageBox.Show("保存成功");
     }
     catch (Exception AnyError)
     {
         MessageBox.Show(AnyError.Message);
         System.Data.Linq.ChangeSet cs = db.GetChangeSet();
         cs.Inserts.Clear();
         cs.Deletes.Clear();
         db.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, cs.Updates);
         BS_GV_DATA.DataSource = db.WX_BounsConfig.Where(t => t.aspnet_UserID == GlobalParam.UserKey);
     }
 }
コード例 #8
0
        public bool Insert <T>(List <T> entities)
        {
            bool returnValue = false;

            foreach (T entity in entities)
            {
                if ((entity as TOOL_ISSUES).IsNotNullOrEmpty())
                {
                    TOOL_ISSUES obj = entity as TOOL_ISSUES;
                    try
                    {
                        if (!obj.TOOL_CD.IsNotNullOrEmpty())
                        {
                            obj.TOOL_CD = GenerateNextNumber("TOOL_ISSUES", "TOOL_CD");
                        }

                        DB.TOOL_ISSUES.InsertOnSubmit(obj);
                        DB.SubmitChanges();

                        System.Data.Linq.ChangeSet cs = DB.GetChangeSet();
                        returnValue = cs.Inserts.Count > 0 ? true : false;
                    }
                    catch (System.Data.Linq.ChangeConflictException)
                    {
                        foreach (System.Data.Linq.ObjectChangeConflict conflict in DB.ChangeConflicts)
                        {
                            conflict.Resolve(System.Data.Linq.RefreshMode.KeepChanges);
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.LogException();
                        DB.TOOL_ISSUES.DeleteOnSubmit(obj);
                    }
                }
            }

            returnValue = true;
            return(returnValue);
        }
コード例 #9
0
        protected virtual void PopulateLastAudit()
        {
            if (!AuditingEnabled)
                return;

            _lastAudit = null;
            _lastChangeSet = this.GetChangeSet();
        }