Ejemplo n.º 1
0
 protected void OnApplyError(ApplyErrorEventArgs value)
 {
     ApplyErrorEventHandler handler = (ApplyErrorEventHandler)base.Events[EventOnApplyError];
     if (handler != null)
     {
         handler(this, value);
     }
 }
Ejemplo n.º 2
0
        // Modified by yangdong 2006-02-15.
        // 为解决提交不成功,InfoNavigator的状态不对的情况。
        public virtual bool ApplyUpdates(bool NeedToValidate)
        {
            bool blapplysuccess = true;
            if (fRealDataSet.HasChanges())
            {
                try
                {
                    OnBeforeApplyUpdates(new EventArgs());
                    // Add By Chenjian
                    // Validate modified data
                    if (this.Site != null /*&& NeedToValidate*/)
                    {
                        foreach (IComponent comp in this.Site.Container.Components)
                        {
                            if (comp is DefaultValidate)
                            {
                                DefaultValidate validator = comp as DefaultValidate;
                                InfoBindingSource bindingSource = validator.BindingSource;
                                if (bindingSource != null)
                                {
                                    if (bindingSource.GetDataSource() != null && bindingSource.GetDataSource() is InfoDataSet
                                        && (InfoDataSet)bindingSource.GetDataSource() == this)
                                    {
                                        bool isDetail = false;
                                        foreach (DataRelation relation in this.RealDataSet.Relations)
                                        {
                                            if (bindingSource.DataMember == relation.RelationName)
                                            {
                                                isDetail = true;
                                                break;
                                            }
                                        }
                                        if (NeedToValidate || isDetail)
                                        {
                                            for (int i = 0; i < validator.BindingSource.List.Count; ++i)
                                            {
                                                DataRowView rowView = validator.BindingSource.List[i] as DataRowView;

                                                if (rowView.Row.RowState == DataRowState.Modified || rowView.Row.RowState == DataRowState.Added)
                                                {
                                                    bool isInsert = rowView.Row.RowState == DataRowState.Added;
                                                    bool CheckDeplicateSucessful = validator.CheckDuplicate(rowView, isInsert);
                                                    if (!CheckDeplicateSucessful)
                                                    {
                                                        return false;
                                                    }
                                                    if (validator.ValidActive == true)
                                                    {
                                                        bool CheckNullAndRangeSuccessful = validator.CheckNullAndRange(rowView);
                                                        bool ValidateSuccessful = validator.ValidateRow(i, rowView);
                                                        validator.ResetWarnging();
                                                        if (!CheckNullAndRangeSuccessful || !ValidateSuccessful)
                                                        {
                                                            return false;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (DeleteIncomplete)
                    {
                        foreach (DataTable table in fRealDataSet.Tables)
                        {
                            ArrayList keys = GetKeyFields(table.TableName);
                            ArrayList rows = new ArrayList();
                            foreach (DataRow row in table.Rows)
                            {
                                if (row.RowState != DataRowState.Added)
                                {
                                    continue;
                                }

                                bool keyIsNull = false;
                                foreach (object obj in keys)
                                {
                                    if (row[(string)obj] == null || row[(string)obj] == DBNull.Value)
                                    {
                                        keyIsNull = true;
                                        break;
                                    }
                                }

                                if (keyIsNull)
                                {
                                    rows.Add(row);
                                }
                            }

                            foreach (DataRow row in rows)
                            {
                                table.Rows.Remove(row);
                            }
                        }
                    }

                    // End Add
                    DataSet custDS = new DataSet();
                    //if (_supportCurrentMasterRow)
                    //{
                    //    custDS.Merge(fRealDataSet);
                    //}
                    //else
                    //{
                        if (fRealDataSet.GetChanges() != null)
                        {
                            custDS.Merge(fRealDataSet.GetChanges());//tables...
                        }
                    //}

                    string s = RemoteName;
                    int iPos = s.IndexOf('.');
                    string s1 = s.Substring(0, iPos);
                    string s2 = s.Substring(iPos + 1, s.Length - iPos - 1);

                    DataSet aDS = new DataSet();
                    if (this.CommandText != null && this.CommandText.Length != 0)
                        aDS = CliUtils.UpdateDataSet(s1, s2, custDS, this.CommandText);
                    else
                        aDS = CliUtils.UpdateDataSet(s1, s2, custDS, "");

                    if (aDS == null || aDS.Tables == null)
                    { return false; }

                    // End Add

                    //if (fServerModify)
                    //{
                    //    if (aDS.Tables[0].Rows.Count != 1 || aDS.Tables[0].Rows[0].RowState != DataRowState.Added)
                    //    { goto Label1; }

                    //    DataRow needModifyRow = fRealDataSet.Tables[0].Rows[0];
                    //    foreach (DataRow r in fRealDataSet.Tables[0].Rows)
                    //    {
                    //        if (r.RowState == DataRowState.Added)
                    //        { needModifyRow = r; }
                    //    }

                    //    foreach (DataColumn c in needModifyRow.Table.Columns)
                    //    {
                    //        needModifyRow[c.ColumnName] = aDS.Tables[0].Rows[0][c.ColumnName];
                    //    }
                    //}
                    InfoBindingSource ibsview = null;
                    InfoBindingSource ibsmaster = null;
                    if (this.Container != null)
                    {
                        foreach (IComponent comp in this.Container.Components)
                        {
                            if (comp is InfoBindingSource)
                            {
                                InfoBindingSource ibs = comp as InfoBindingSource;
                                foreach (InfoRelation relation in ibs.Relations)
                                {
                                    if (relation.RelationDataSet == this)// find view
                                    {
                                        ibsview = ibs;
                                        break;
                                    }
                                }
                                if (ibs.DataSource == this)
                                {
                                    ibsmaster = ibs;
                                }
                            }
                        }
                    }

                    if (fServerModify)
                    {
                        int m = 0;
                        foreach (DataRow row in aDS.Tables[0].Rows)
                        {
                            if (row.RowState == DataRowState.Added)
                            {
                                break;
                            }
                            m++;
                        }
                        if (m < aDS.Tables[0].Rows.Count)
                        {
                            DataRow needModifyRow = fRealDataSet.Tables[0].Rows[m];
                            foreach (DataRow r in fRealDataSet.Tables[0].Rows)
                            {
                                if (r.RowState == DataRowState.Added)
                                { needModifyRow = r; }
                            }
                            /*挂起绑定,减少更改值需要的时间*/
                            int postion = 0;
                            if (ibsmaster != null && ibsmaster.ServerModifyCache)
                            {
                                postion = ibsmaster.Position;
                                ibsmaster.CancelPositionChanged = true;
                                ibsmaster.SuspendBinding();
                            }
                            /******************************/

                            foreach (DataColumn c in needModifyRow.Table.Columns)
                            {
                                if (!c.ReadOnly)
                                {
                                    needModifyRow[c.ColumnName] = aDS.Tables[0].Rows[m][c.ColumnName];
                                }
                            }

                            if (ibsmaster != null && ibsmaster.ServerModifyCache)
                            {
                                ibsmaster.ResumeBinding();
                                ibsmaster.Position = postion;
                                ibsmaster.CancelPositionChanged = false;
                            }

                            if (ibsview != null)
                            {
                                DataSet realDs = ((InfoDataSet)ibsview.GetDataSource()).RealDataSet;
                                DataSet ds = realDs.GetChanges(DataRowState.Added);
                                if (ds != null)
                                {
                                    DataColumn[] cs = realDs.Tables[0].PrimaryKey;
                                    DataRow row = ds.Tables[0].Rows[0];

                                    if (cs.Length != 0)
                                    {
                                        List<object> os = new List<object>();
                                        foreach (DataColumn c in cs)
                                        {
                                            os.Add(row[c.ColumnName]);
                                        }

                                        DataRow replaceRow = realDs.Tables[0].Rows.Find(os.ToArray());
                                        foreach (DataColumn c in needModifyRow.Table.Columns)
                                        {
                                            if (replaceRow.Table.Columns.Contains(c.ColumnName) && !c.ReadOnly)
                                            {
                                                replaceRow[c.ColumnName] = needModifyRow[c.ColumnName];
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (ibsview != null)
                    {
                        (ibsview.DataSource as InfoDataSet).RealDataSet.AcceptChanges();
                        ibsview.Reset_fInEdit();
                    }

                    fRealDataSet.AcceptChanges();
                    OnAfterApplyUpdates(new EventArgs());
                }
                catch (Exception e)
                {
                    if (fRealDataSet.GetChanges(DataRowState.Deleted) !=null
                        && fRealDataSet.GetChanges(DataRowState.Deleted).Tables[0].Rows.Count > 0 && this.Container != null)
                    {
                        bool autoapply = false;
                        InfoBindingSource ibsview = null;
                        if (this.Container != null)
                        {
                            foreach (IComponent comp in this.Container.Components)
                            {
                                if (comp is InfoBindingSource)
                                {
                                    InfoBindingSource ibs = comp as InfoBindingSource;
                                    if (ibs.DataSource == this) //find bindingsource of master
                                    {
                                        if (ibs.AutoApply)
                                        {
                                            autoapply = true;
                                            continue;
                                        }
                                        else
                                        {
                                            autoapply = false;
                                            break;
                                        }
                                    }
                                    foreach (InfoRelation relation in ibs.Relations)
                                    {
                                        if (relation.RelationDataSet == this)// find view
                                        {
                                            ibsview = ibs;
                                            break;
                                        }
                                    }
                                }
                            }
                            if (autoapply)
                            {
                                fRealDataSet.RejectChanges();
                                if (ibsview != null)
                                {
                                    (ibsview.DataSource as InfoDataSet).RealDataSet.RejectChanges();
                                    //clear edit flag...
                                    ibsview.Reset_fInEdit();
                                }
                            }
                        }
                    }
                    ApplyErrorEventArgs args = new ApplyErrorEventArgs(e);
                    OnApplyError(args);
                    blapplysuccess = false;
                    if (!args.Cancel)
                    {
                        throw e;
                    }
                }
                finally
                {
                    if (this.Container != null)
                    {
                        foreach (IComponent comp in this.Container.Components)
                        {
                            if (comp is InfoBindingSource)
                            {
                                InfoBindingSource bs = (InfoBindingSource)comp;
                                DataSet ds = new DataSet();
                                int m = bs.Relations.Count;
                                for (int n = 0; n < m; n++)
                                {
                                    InfoRelation infoRel = bs.Relations[n];
                                    ds = this.fRealDataSet;
                                    if (infoRel.RelationDataSet.GetRealDataSet() == ds)
                                    {
                                        if (!infoRel.Active)
                                        {
                                            infoRel.Active = this.RelationsActive;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return blapplysuccess;
        }
Ejemplo n.º 3
0
 protected void OnApplyError(ApplyErrorEventArgs value)
 {
     Srvtools.InfoDataSet.ApplyErrorEventHandler handler = (Srvtools.InfoDataSet.ApplyErrorEventHandler)base.Events[EventOnApplyError];
     if (handler != null)
     {
         handler(this, value);
     }
 }