Пример #1
0
        void ChangeEditViewMode(CompositeDataBoundControl view, Dictionary<string, object> dicArgs)
        {
            string mode = dicArgs["mode"] as string;
            if (!string.IsNullOrEmpty(mode))
            {
                object o = this.GetObjByID(this.DataSourceID);
                if (o != null && o is WebDataSource)
                {
                    WebDataSource wds = ((WebDataSource)o);
                    if (mode == "insert")
                    {
                        #region insert
                        if (view is DetailsView)
                        {
                            DetailsView detView = view as DetailsView;
                            if (detView.CurrentMode != DetailsViewMode.Insert)
                            {
                                detView.ChangeMode(DetailsViewMode.Insert);
                            }
                        }
                        else if (view is FormView)
                        {
                            FormView fmView = view as FormView;
                            if (fmView.CurrentMode != FormViewMode.Insert)
                            {
                                fmView.ChangeMode(FormViewMode.Insert);
                            }
                        }
                        #endregion
                    }
                    else if (mode == "edit")
                    {
                        #region edit
                        List<object> lstKeys = new List<object>();
                        foreach (KeyValuePair<string, object> pair in dicArgs)
                        {
                            if (pair.Key != "mode")
                            {
                                lstKeys.Add(pair.Value);
                            }
                        }
                        int index = -1;
                        if (string.IsNullOrEmpty(wds.MasterDataSource))
                        {
                            if (string.IsNullOrEmpty(wds.View.Sort))
                            {
                                wds.View.ApplyDefaultSort = true;
                            }
                            index = wds.View.Find(lstKeys.ToArray());
                        }
                        else
                        {
                            DataTable detTab = wds.View.Table;
                            DataColumn[] keyColumns = detTab.PrimaryKey;
                            DataRow editRow = detTab.Rows.Find(lstKeys.ToArray());
                            for (int i = 0; i < detTab.Rows.Count; i++)
                            {
                                bool isEditRow = true;
                                foreach (DataColumn column in keyColumns)
                                {
                                    if (!editRow[column].Equals(detTab.Rows[i][column]))
                                    {
                                        isEditRow = false;
                                        break;
                                    }
                                }
                                if (isEditRow)
                                {
                                    index = i;
                                    break;
                                }
                            }
                        }

                        if (view is DetailsView)
                        {
                            DetailsView detView = view as DetailsView;
                            if (index != -1 && detView.CurrentMode != DetailsViewMode.Edit)
                            {
                                detView.PageIndex = index;
                                detView.DataBind();
                                detView.ChangeMode(DetailsViewMode.Edit);
                            }
                        }
                        else if (view is FormView)
                        {
                            FormView fmView = view as FormView;
                            if (index != -1 && fmView.CurrentMode != FormViewMode.Edit)
                            {
                                fmView.PageIndex = index;
                                fmView.DataBind();
                                fmView.ChangeMode(FormViewMode.Edit);
                            }
                        }
                        #endregion
                    }
                    else if (mode == "readonly")
                    {
                        #region readonly
                        if (view is DetailsView)
                        {
                            DetailsView detView = view as DetailsView;
                            if (detView.CurrentMode != DetailsViewMode.ReadOnly)
                            {
                                detView.ChangeMode(DetailsViewMode.ReadOnly);
                            }
                        }
                        else if (view is FormView)
                        {
                            FormView fmView = view as FormView;
                            if (fmView.CurrentMode != FormViewMode.ReadOnly)
                            {
                                fmView.ChangeMode(FormViewMode.ReadOnly);
                            }
                        }
                        #endregion
                    }
                }
                UpdatePanel upan = this.GetModalUpdatePanel(1);
                if (upan != null)
                {
                    string oper = "";
                    if(mode == "insert" || mode=="edit")
                    {
                        oper = "show";
                    }
                    else if(mode=="readonly")
                    {
                        oper = "hide";
                    }
                    string script = string.Format("var behavior=$find('{0}behavior');if(behavior){{behavior.{1}();}}", this.EditPanelID, oper);
                    ScriptManager.RegisterStartupScript(upan, this.GetType(), Guid.NewGuid().ToString(), script, true);
                }
            }
        }
Пример #2
0
 public static void Bind(CompositeDataBoundControl view, string sql)
 {
     view.DataSource = GetTable(sql);
     view.DataBind();
 }
Пример #3
0
        public void Submit(CompositeDataBoundControl view)
        {
            object o = this.GetObjByID(this.DataSourceID);
            if (o != null && o is WebDataSource)
            {
                WebDataSource wds = o as WebDataSource;
                string loadType = "";
                //int position = -1;
                if (view is DetailsView)
                {
                    WebDetailsView detView = view as WebDetailsView;
                    if (detView.CurrentMode == DetailsViewMode.Insert)
                    {
                        detView.InsertItem(false);
                        loadType = "insert";
                        //position = wds.InnerDataSet.Tables[wds.DataMember].Rows.Count - 1;
                    }
                    else if (detView.CurrentMode == DetailsViewMode.Edit)
                    {
                        detView.UpdateItem(false);
                        loadType = "edit";
                    }
                    WebValidate validate = (WebValidate)detView.ExtendedFindChildControl(this.DataSourceID, FindControlType.DataSourceID, typeof(WebValidate));
                    if (validate != null && detView.ValidateFailed)
                    {
                        return;
                    }
                }
                else if (view is FormView)
                {
                    WebFormView fmView = view as WebFormView;
                    if (fmView.CurrentMode == FormViewMode.Insert)
                    {
                        fmView.InsertItem(false);
                        loadType = "insert";
                        //position = wds.InnerDataSet.Tables[wds.DataMember].Rows.Count - 1;
                    }
                    else if (fmView.CurrentMode == FormViewMode.Edit)
                    {
                        fmView.UpdateItem(false);
                        loadType = "edit";
                    }
                    WebValidate validate = (WebValidate)fmView.ExtendedFindChildControl(this.DataSourceID, FindControlType.DataSourceID, typeof(WebValidate));
                    if (validate != null && fmView.ValidateFailed)
                    {
                        return;
                    }
                }

                StringBuilder builder = new StringBuilder();
                if (wds.AutoApply)
                {
                    builder.AppendFormat("var grid=Ext.getCmp('{0}');", this.ID);
                    builder.Append("grid.store.load();");
                }
                else
                {
                    DataTable tab = wds.InnerDataSet.Tables[wds.DataMember].GetChanges();
                    if (tab != null && tab.Rows.Count == 1)
                    {
                        builder.AppendFormat("var grid=Ext.getCmp('{0}');", this.ID);
                        DataRow changedRow = tab.Rows[0];
                        if (loadType == "insert")
                        {
                            builder.Append("var changedRecord={");
                            foreach (DataColumn column in tab.Columns)
                            {
                                if (changedRow[column] != DBNull.Value)
                                {
                                    Type type = column.DataType;
                                    if (GloFix.IsNumeric(type))
                                    {
                                        builder.AppendFormat("{0}:{1},", column.ColumnName, changedRow[column.ColumnName]);
                                    }
                                    else if (type == typeof(bool))
                                    {
                                        builder.AppendFormat("{0}:{1},", column.ColumnName, changedRow[column.ColumnName].ToString().ToLower());
                                    }
                                    else
                                    {
                                        builder.AppendFormat("{0}:'{1}',", column.ColumnName, changedRow[column.ColumnName]);
                                    }
                                }
                            }
                            if (builder.ToString().EndsWith(","))
                            {
                                builder.Remove(builder.Length - 1, 1);
                            }
                            builder.Append("};");
                            builder.AppendFormat("Infolight.GridHelper.insertStore(grid.store,changedRecord);", this.ID);
                        }
                        else if (loadType == "edit")
                        {
                            builder.Append("var recordKeys={");
                            foreach (ExtGridColumn extColumn in this.Columns)
                            {
                                if (extColumn.IsKeyField)
                                {
                                    Type type = tab.Columns[extColumn.DataField].DataType;
                                    if (GloFix.IsNumeric(type))
                                    {
                                        builder.AppendFormat("{0}:{1},", extColumn.DataField, changedRow[extColumn.DataField]);
                                    }
                                    else if (type == typeof(bool))
                                    {
                                        builder.AppendFormat("{0}:{1},", extColumn.DataField, changedRow[extColumn.DataField].ToString().ToLower());
                                    }
                                    else
                                    {
                                        builder.AppendFormat("{0}:'{1}',", extColumn.DataField, changedRow[extColumn.DataField]);
                                    }
                                }
                            }
                            if (builder.ToString().EndsWith(","))
                            {
                                builder.Remove(builder.Length - 1, 1);
                            }
                            builder.Append("};");

                            builder.Append("var changedRecord={");
                            foreach (DataColumn column in tab.Columns)
                            {
                                if (!changedRow[column, DataRowVersion.Current].Equals(changedRow[column, DataRowVersion.Original]))
                                {
                                    Type type = column.DataType;
                                    if (GloFix.IsNumeric(type))
                                    {
                                        builder.AppendFormat("{0}:{1},", column.ColumnName, changedRow[column.ColumnName]);
                                    }
                                    else if (type == typeof(bool))
                                    {
                                        builder.AppendFormat("{0}:{1},", column.ColumnName, changedRow[column.ColumnName].ToString().ToLower());
                                    }
                                    else
                                    {
                                        builder.AppendFormat("{0}:'{1}',", column.ColumnName, changedRow[column.ColumnName]);
                                    }
                                }
                            }
                            if (builder.ToString().EndsWith(","))
                            {
                                builder.Remove(builder.Length - 1, 1);
                            }
                            builder.Append("};");
                            builder.Append("Infolight.GridHelper.updateStore(grid.store,recordKeys,changedRecord);");
                        }
                        wds.InnerDataSet.Tables[wds.DataMember].AcceptChanges();
                    }
                }

                UpdatePanel upan = this.GetModalUpdatePanel(1);
                if (upan != null)
                {
                    builder.AppendFormat("var behavior=$find('{0}behavior');", this.EditPanelID);
                    builder.Append("if(behavior){behavior.hide();}");
                    if (loadType == "insert")
                    {
                        builder.AppendFormat("grid.locateLastRecord();");
                    }
                }
                if (builder.Length > 0)
                {
                    ScriptManager.RegisterStartupScript(upan, this.GetType(), Guid.NewGuid().ToString(), builder.ToString(), true);
                }
            }
        }
Пример #4
0
 public void ChangeMode(WebGridView.OpenEditMode mode, CompositeDataBoundControl dbControl)
 {
     if (mode == WebGridView.OpenEditMode.View)
     {
         if (dbControl is FormView)
         {
             ((FormView)dbControl).ChangeMode(FormViewMode.ReadOnly);
         }
         else if (dbControl is DetailsView)
         {
             ((DetailsView)dbControl).ChangeMode(DetailsViewMode.ReadOnly);
         }
     }
     else if (mode == WebGridView.OpenEditMode.Update)
     {
         if (dbControl is FormView)
         {
             ((FormView)dbControl).ChangeMode(FormViewMode.Edit);
         }
         else if (dbControl is DetailsView)
         {
             ((DetailsView)dbControl).ChangeMode(DetailsViewMode.Edit);
         }
     }
     else if (mode == WebGridView.OpenEditMode.Insert)
     {
         if (dbControl is FormView)
         {
             ((FormView)dbControl).ChangeMode(FormViewMode.Insert);
         }
         else if (dbControl is DetailsView)
         {
             ((DetailsView)dbControl).ChangeMode(DetailsViewMode.Insert);
         }
     }
 }