void initCommandInsert(DbDataAdapter pAdp, ITableDescriptor pTabDesc)
        {
            if (string.IsNullOrEmpty(pTabDesc.getNameFull()))
            {
                throw new MyExceptionError("Db Table Full name is null or empty");
            }

            List <SqliteParameter> listPrm = new List <SqliteParameter>();

            StringBuilder buffer = new StringBuilder();

            //

            //
            buffer.Append("INSERT INTO ");
            //buffer.Append("\"");
            buffer.Append(pTabDesc.getNameFull());
            //buffer.Append("\"");
            //buffer.Append(pTableFullName);
            buffer.Append(" (");

            foreach (ColumnDescriptor col in pTabDesc.getColumns())
            {
                //buffer.Append("\"");
                buffer.Append(col.name);
                //buffer.Append("\"");
                buffer.Append(",");
            }
            buffer.Remove(buffer.Length - 1, 1);
            buffer.Append(") VALUES (");
            int prmIndx = 0;

            foreach (ColumnDescriptor col in pTabDesc.getColumns())
            {
                SqliteParameter prm = new SqliteParameter();
                ++prmIndx;
                prm.ParameterName = ToolSqlText.getNewParamName(prmIndx);
                prm.SourceVersion = DataRowVersion.Current;
                prm.SourceColumn  = col.name;
                //prm.Size = col.size;
                listPrm.Add(prm);

                buffer.Append(prm.ParameterName + ",");
            }
            buffer.Remove(buffer.Length - 1, 1);
            buffer.Append(")");
            //

            pAdp.InsertCommand = environment.getNewSqlCommand(buffer.ToString(), listPrm.ToArray());
        }
        void initCommandDelete(DbDataAdapter pAdp, ITableDescriptor pTabDesc)
        {
            if (string.IsNullOrEmpty(pTabDesc.getNameFull()))
            {
                throw new MyExceptionError("Db Table Full name is null or empty");
            }

            bool hasRecVers = pTabDesc.getColumn(TableDUMMY.RECVERS) != null;

            List <SqliteParameter> listPrm = new List <SqliteParameter>();

            StringBuilder buffer = new StringBuilder();

            //

            //
            buffer.Append("DELETE FROM ");
            //buffer.Append("\"");
            buffer.Append(pTabDesc.getNameFull());
            //buffer.Append("\"");
            //buffer.Append(pTableFullName);
            buffer.Append(" WHERE ");

            string[] arr_    = hasRecVers ? new string[] { TableDUMMY.LOGICALREF, TableDUMMY.RECVERS } : new string[] { TableDUMMY.LOGICALREF };
            int      prmIndx = 0;

            buffer.Append("(");
            for (int i = 0; i < arr_.Length; ++i)
            {
                if (i > 0)
                {
                    buffer.Append(" AND ");
                }

                SqliteParameter prm = new SqliteParameter();
                ++prmIndx;
                prm.ParameterName = ToolSqlText.getNewParamName(prmIndx);
                prm.SourceVersion = DataRowVersion.Original;
                prm.SourceColumn  = arr_[i];
                //prm.Size = col.size;
                listPrm.Add(prm);

                buffer.Append(string.Format("{0} = {1}", prm.SourceColumn, prm.ParameterName));
            }

            buffer.Append(")");
            //

            pAdp.DeleteCommand = environment.getNewSqlCommand(buffer.ToString(), listPrm.ToArray());
        }
Esempio n. 3
0
        public virtual void loadFilterStruct()
        {
            try
            {
                getGrid().beginDataLoad();

                if (!HasFilter)
                {
                    getFilterTreePanel().Visible = false;
                    getFilterGridPanel().Visible = false;
                }
                else
                {
                    getFilterTreePanel().Visible = false;
                    List <MobDataGrid> list = new List <MobDataGrid>();
                    {
                        if (FilterCols.Length > 0)
                        {
                            list.Add(getFilterGrid1());
                        }
                        if (FilterCols.Length > 1)
                        {
                            list.Add(getFilterGrid2());
                        }
                        else
                        {
                            getFilterGrid2().Visible = false;
                        }
                    }

                    filterWrap = new ImplFilterWrapGrid(list.ToArray());
                    //filterWrap = new ImplFilterWrapTree(getFilterTree());
                    filterWrap.FilterChanged += filterWrap_FilterChanged;
                    //getFilter().NodeClick += MobDataReferenceGridFormBase_NodeClick;

                    string stateNameFilterTree = globalStoreName() + "/filtertree";

                    object[][] tree_ = environment.getStateData(stateNameFilterTree) as object[][];

                    if (tree_ == null)
                    {
                        string           name_ = getDsName();
                        ITableDescriptor td_   = environment.getDbDescriptor().getTable(name_);
                        if (td_ == null)
                        {
                            throw new MyExceptionError("Cant find table [" + name_ + "] descriptor");
                        }

                        string tabFullName_ = td_.getNameFull();

                        string    sql_ = string.Format("SELECT DISTINCT {0} FROM {1}", ToolString.joinList(FilterCols), tabFullName_);
                        DataTable tab_ = SqlExecute.execute(environment, sql_, null);
                        tree_ = ToolTable.getGroups(tab_, FilterCols);
                    }

                    filterWrap.fill(tree_);
                    // getFilter().fillTree(tree_);


                    environment.setStateData(stateNameFilterTree, tree_);
                }
            }
            catch (Exception exc)
            {
                ToolMobile.setException(exc);
            }
            finally
            {
                getGrid().endDataLoad();
            }
        }