Exemple #1
0
        public dlgQProperty(Task aTsk)
        {
            _tsk = aTsk;
            _q = null;

            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            _txtCode.Leave += new EventHandler(_txtCode_Leave);
        }
Exemple #2
0
        public dlgParam(Query aQuery)
        {
            _query = aQuery;

              //
              // Required for Windows Form Designer support
              //
              InitializeComponent();

              _uc = new ucParamDef(true);
              _uc.SetData(_query.Params);
              _uc.Location = new Point(5, 5);
              _uc.Size = new Size(this.ClientSize.Width - 10, _cmdOk.Top - 10);
              _uc.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
              this.Controls.Add(_uc);

              this.Text = "Параметр(ы) запроса - " + _query.Name;
        }
Exemple #3
0
 /// <summary>
 /// Запрет на отображение (исполнение) запроса.
 /// Может быть переопределено в производном классе.
 /// </summary>
 /// <param name="aQ">запрос</param>
 /// <returns>true - отображение запрещено; false - отображение разрешено</returns>
 protected virtual bool _IsProhibition(Query aQ)
 {
     return false;
 }
Exemple #4
0
        public TreeNode FindNodeByQuery(TreeNodeCollection aNColl,  Query aQ)
        {
            TreeNode ret = null;
            foreach (TreeNode tn in aNColl)
            {
                ret = FindNodeByQuery(tn.Nodes,  aQ);
                if (ret != null)
                    return ret;

                if (aQ.Equals(tn.Tag))
                    return  tn;
            }
            return ret;
        }
Exemple #5
0
        public void Load(Performer aPrf)
        {
            if (SelectedNode != null)
                _prevSelectedQuery = SelectedNode.Tag as Query;

            Nodes.Clear();

            mCurrSession = aPrf.pSes;

            if (aPrf == null || aPrf.pQueries.Count == 0)
                return;

            Stack ownStack = new Stack(16);
            string [] ss = null;
            string [] prevSS = new string[0];
            TreeNode node = null;
            //ArrayList qns = new ArrayList(_ses.Queries.Count);
            //foreach (Query q in _ses.Queries)
            //	qns.Add(q.Name);
            //	qns.Sort();
            CompareQueryName cqn = new CompareQueryName();
            aPrf.pQueries.Sort(cqn);
            foreach (Query q in aPrf.pQueries)
            {
                if (q.Hidden && (!pViewHidden))
                    continue;

                /// если установлен запрет на отображение, через виртуальную
                /// функцию _IsProhibition
                if (_IsProhibition(q))
                    continue;

                ss = q.Name.Split(PathSeparator.ToCharArray());
                int ii = 0;
                for (; ii < prevSS.Length && ii < ss.Length && prevSS[ii].Equals(ss[ii]); ii++)
                {
                    continue;
                }

                for(int jj = prevSS.Length-ii; jj>0 && ownStack.Count>0; jj--)
                    ownStack.Pop();

                for (; ii < ss.Length; ii++)
                {
                    node = new TreeNode(ss[ii]);
                    node.Tag = q;
                    if (ownStack.Count > 0)
                    {
                        ((TreeNode)ownStack.Peek()).Nodes.Add(node);
                        if (q.Hidden)
                            node.ForeColor = SystemColors.GrayText;
                    }
                    else
                    {
                        Nodes.Add(node);
                    }

                    ownStack.Push(node);
                }
                prevSS = ss;
            }

            if (_prevSelectedQuery != null)
                SelectedNode = FindNodeByQuery(Nodes, _prevSelectedQuery);

            if (pViewHidden)
                ViewCodeText(Nodes);
        }
Exemple #6
0
        public bool IsCorrectQueryCode(int aCode, Query aQ)
        {
            bool ret = true;

              foreach (Query q in Queries)
            if (q.Code == aCode && aQ != q)
            {
              ret = false;
              break;
            }

              return ret;
        }
Exemple #7
0
 public OpeningFile(string aFileName, eOpeningFileContent aOFContent, Query aQuery)
 {
     pFileName		= aFileName;
     pOFContent	= aOFContent;
     pQuery			= aQuery;
 }
Exemple #8
0
        private void DoCommandImportQuery(object sender, System.EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
              dlg.Filter = "Запрос v3 (*" + Performer.CURRENT_QUERY_EXT + ")|*" + Performer.CURRENT_QUERY_EXT
            + "|Запрос v2 (*.q2)|*.q2";
              if (dlg.ShowDialog() == DialogResult.OK)
              {
            Query q = null;
            try
            {
              /// РАСПОЗНАЕМ версию сессии по расширению:
              string ext = Path.GetExtension(dlg.FileName).ToLower();
              if (ext.Equals(Performer.CURRENT_QUERY_EXT))
              {
            q = Query.Load(dlg.FileName);
              }
              else if (ext.Equals(".q2"))
              { // Преобразуем из версии 2 в текущую версию
            q = new Query(CommandAS.QueryLib2.Query.Load(dlg.FileName));
              }
            }
            catch { }

            if (q != null)
            {
              _task.AddQuery(q);
              _tvQueries.Load(_task);
            }
            else
              MessageBox.Show("Не известный формат файла");
              }
        }
Exemple #9
0
 /// <summary>
 /// Выполняет запрос aQuery для соединения aCn. 
 /// Для запроса типа eSQLQueryType.Select результат помещается в таблицу mTab.
 /// pDBConnection=aCn
 /// pCurrentQuery=aQuery. 
 /// Запрос выполняется внутри транзакции соединения pDBConnection.
 /// </summary>
 /// <param name="aCn">Соединение.</param>
 /// <param name="aQuery">Запрос.</param>
 /// <returns>
 ///	true - запрос выполнен успешно;
 ///	false - запрос не выполнен, ошибка. Ошибка в pError.
 /// </returns>
 public bool Execute(OleDbConnection aCn, Query aQuery)
 {
     mDB.pDBConnection = aCn;
       mCQ = aQuery;
       return Execute();
 }
Exemple #10
0
        protected void mExecute(DataSet aDS, Query aQr)
        {
            OleDbCommand cmd = mDB.NewOleDbCommand(aQr.Text);

              #region  добавлено DSY 20.02.2008
              cmd.CommandTimeout = 120;   //  2 минут должно хватить
              #endregion

              bool isSelect = (GetSQLQueryType(aQr.Text) == eSQLQueryType.Select);
              if (!isSelect)
            cmd.CommandText = cmd.CommandText.Replace(mSes.ParamBegDelim + EXECUTE_NO_QUERY_MARK + mSes.ParamEndDelim, string.Empty);

              ArrayList paramCol = mGetQueryParamCol(aQr, null);

              #region handling EXEC_SUBQUERY_nn param1, param2, ..., paramN

              int pos = 0;
              int len = EXEC_SUBQUERY_nn.Length;
              while ((pos = cmd.CommandText.IndexOf(EXEC_SUBQUERY_nn, pos)) != -1)
              {
            int cp = pos + len;
            // define query by code
            int cp2 = cmd.CommandText.IndexOf("(", cp);
            int qCode = CASTools.ConvertToInt32Or0(cmd.CommandText.Substring(cp, cp2 - cp).Trim());
            if (qCode == 0)
            {
              pos = cp;
              continue;
            }
            Query qq = FoundQueryByCode(qCode);
            if (qq != null)
            {
              // define qyery param
              cp = cp2 + 1;
              cp2 = cmd.CommandText.IndexOf(")", cp);
              string[] ss = cmd.CommandText.Substring(cp, cp2 - cp).Trim().Split(",".ToCharArray());
              for (int ii = 0; ii < ss.Length; ii++)
              {
            string sprm = ss[ii].Trim();
            if (sprm.Length == 0)
              continue;

            bool isVal = true;
            foreach (Param prm in paramCol)
            {
              if (sprm.Equals(mSes.ParamBegDelim + prm.Name + mSes.ParamEndDelim))
              {
                Param qp = (Param)qq.Params[ii];
                qp.CurrentValue = string.Empty;
                if (qp.Type == prm.Type)
                  qp.CurrentValue = prm.CurrentValue;
                else
                {
                  switch (qp.Type)
                  {
                    case eQueryParamType.Integer:
                    case eQueryParamType.IntSelectList:
                    case eQueryParamType.IntSelectTree:
                      qp.ValInt = prm.ValInt;
                      break;
                    case eQueryParamType.PlaceCode:
                    case eQueryParamType.PCSelectList:
                    case eQueryParamType.PCSelectTree:
                      qp.CurrentValue = prm.ValPC.PlaceDelimCode;
                      break;
                  }
                }
                isVal = false;
              }
            }
            if (isVal)
              ((Param)qq.Params[ii]).CurrentValue = sprm;
              }
              //
              mExecute(aDS, qq);
            }
            // remove substring from CommandText
            cmd.CommandText = cmd.CommandText.Remove(pos, cp2 - pos + 1);
              }

              #endregion

              mGenerateCommandWithParam(cmd, paramCol);

              if (isSelect)
              {
            DataSet ds = new DataSet();
            OleDbDataAdapter da = new OleDbDataAdapter();
            da.SelectCommand = cmd;
            da.Fill(ds);

            #region Save image to temporary file or Unzip zipping data
            for (int jj = 0; jj < ds.Tables.Count; jj++)
            {
              DataColumn cid = null;
              DataColumn cif = null;
              DataColumn czd = null;
              DataColumn cud = null;
              DataColumn cbd = null;
              DataColumn cbf = null;
              foreach (DataColumn dc in ds.Tables[jj].Columns)
              {
            if (dc.ColumnName.Equals(COL_IMG_DATA))
              cid = dc;
            else if (dc.ColumnName.Equals(COL_IMG_FILE))
              cif = dc;
            else if (dc.ColumnName.Equals(COL_ZIP_DATA))
              czd = dc;
            else if (dc.ColumnName.Equals(COL_UNZ_DATA))
              cud = dc;
            else if (dc.ColumnName.Equals(COL_BIN_DATA))
              cbd = dc;
            else if (dc.ColumnName.Equals(COL_BIN_FILE))
              cbf = dc;
              }
              if (cid != null && cif != null)
              {
            foreach (DataRow dr in ds.Tables[jj].Rows)
            {
              byte[] bi = dr[cid] as byte[];
              if (bi != null && bi.Length > 0)
              {
                System.IO.MemoryStream ms = new System.IO.MemoryStream(bi);
                try
                {
                  Image img = new Bitmap(ms);
                  string fn = mTempFiles.pGetTempFileName;
                  img.Save(fn, System.Drawing.Imaging.ImageFormat.Jpeg);
                  File.SetAttributes(fn, FileAttributes.Temporary);
                  //изменил DiMoN 5.09.06
                  dr[cif] = fn.Replace(@"\", @"\\");
                }
                catch { }
              }
            }
              }
              if (czd != null && cud != null)
              {
            CasBinary bin = new CasBinary();
            foreach (DataRow dr in ds.Tables[jj].Rows)
            {
              byte[] bi = dr[czd] as byte[];
              if (bi != null && bi.Length > 0)
              {
                try
                {
                  MemoryStream ms = bin.TranslateFrom(new MemoryStream(bi));
                  //dr[cud] = System.Text.Encoding.Default.GetString(ms.ToArray()).Replace("\n", Environment.NewLine);
                  dr[cud] = System.Text.Encoding.Default.GetString(ms.ToArray());
                }
                catch {}
              }
            }
              }
              if (cbd != null && cbf != null)
              {
            foreach (DataRow dr in ds.Tables[jj].Rows)
            {
              byte[] bi = dr[cbd] as byte[];
              if (bi != null && bi.Length > 0)
              {
                try
                {
                  string fn = dr[cbf].ToString();
                  if (fn != null && fn.Length > 0)
                    fn = mTempFiles.GetTempFileName(fn);
                  else
                    fn = mTempFiles.pGetTempFileName;
                  FileStream file = new FileStream(fn, FileMode.Create, FileAccess.Write);
                  file.Write(bi, 0, bi.Length);
                  file.Close();
                  File.SetAttributes(fn, FileAttributes.Temporary);
                  dr[cbf] = fn; //.Replace(@"\", @"\\");
                }
                catch { }
              }
            }
              }
            }
            #endregion

            while (ds.Tables.Count > 0)
            {
              DataTable dt = ds.Tables[0];
              ds.Tables.Remove(dt);
              if (aDS.Tables.Count == 0)
            dt.TableName = RESULT_TAB_NAME;
              else
            dt.TableName = RESULT_TAB_NAME + (aDS.Tables.Count + 1).ToString();
              aDS.Tables.Add(dt);
              pResultMessage += "\r\n таб. " + dt.TableName + "\r\n\t";
              foreach (DataColumn dc in dt.Columns)
            pResultMessage += dc.ColumnName + ", ";

            }
              }
              else if (cmd.CommandText.Trim(" \n\r\t".ToCharArray()).Length > 0)
              {
            pResultMessage +=
              "\r\n Выполнен запрос \r\n" + cmd.CommandText +
              "\r\n обработано " + mDB.ExecuteNonQuery(cmd) + " (зап.)";
              }
        }
Exemple #11
0
        protected ArrayList mGetQueryParamCol(Query aQr, ArrayList aParamOptions)
        {
            ArrayList locParamCol = new ArrayList(16);
              Param pp;
              if (aQr != null)
            foreach (Param prm in aQr.Params)
            {
              pp = new Param();
              pp.CurrentValue = prm.CurrentValue;
              pp.Name = prm.Name;
              pp.Type = prm.Type;
              pp.Inset = prm.Inset;
              //pp.SelectValue = prm.SelectValue;
              //pp.Title = prm.Title;
              locParamCol.Add(pp);
            }

              if (pCommonParamCollection != null)
            foreach (Param prm in pCommonParamCollection)
            {
              pp = new Param();
              pp.CurrentValue = prm.CurrentValue;
              pp.Name = prm.Name;
              pp.Type = prm.Type;
              pp.Inset = prm.Inset;
              locParamCol.Add(pp);
            }

              if (aParamOptions != null)
            foreach (Param prm in aParamOptions)
            {
              pp = new Param();
              pp.CurrentValue = prm.CurrentValue;
              pp.Name = prm.Name;
              pp.Type = prm.Type;
              pp.Inset = prm.Inset;
              locParamCol.Add(pp);
            }

              return locParamCol;
        }
Exemple #12
0
 /// <summary>
 /// Установить текущий запрос из коллекции сессии по коду [aCode].
 /// </summary>
 /// <param name="aCode">Код запроса</param>
 /// <returns>
 ///	true - запрос установлен;
 ///	false - не установлен (не найден запрос).
 /// </returns>
 public bool SetCurrentQueryByCode(int aCode)
 {
     Query qq = FoundQueryByCode(aCode);
       if (qq != null)
       {
     mCQ = qq;
     return true;
       }
       return false;
 }
Exemple #13
0
        /// <summary>
        /// Установить текущий запрос из коллекции сессии по имени [aName].
        /// </summary>
        /// <param name="aName">Имя запроса.</param>
        /// <returns>
        ///	true - запрос установлен;
        ///	false - не установлен (не найден запрос).
        /// </returns>
        public bool SetCurrentQueryByName(string aName)
        {
            if (mSes != null)
            foreach (Query qq in mSes.Queries)
              if (qq.Name.Equals(aName))
              {
            mCQ = qq;
            return true;
              }

              //mCQ = null;
              return false;
        }
Exemple #14
0
 public void QueryParam(OleDbCommand aCmd, Query aQr, ArrayList aParamOptions)
 {
     mGenerateCommandWithParam(aCmd, mGetQueryParamCol(aQr, aParamOptions));
 }
Exemple #15
0
 public void QueryParam(OleDbCommand aCmd, Query aQr)
 {
     QueryParam(aCmd, aQr, null);
 }
Exemple #16
0
 /// <summary>
 /// Выполняет запрос aQuery и для типа eSQLQueryType.Select 
 /// помещает результат  в таблицу mTab. pCurrentQuery=aQuery.
 /// Запрос выполняется внутри транзакции соединения pDBConnection.
 /// </summary>
 /// <param name="aQuery">Запрос.</param>
 /// <returns>
 ///	true - запрос выполнен успешно;
 ///	false - запрос не выполнен, ошибка. Ошибка в pError.
 /// </returns>
 public bool Execute(Query aQuery)
 {
     mCQ = aQuery;
       return Execute();
 }
Exemple #17
0
 protected override bool _IsProhibition(Query aQ)
 {
     return _wdb.IsProhibition(aQ.Code);
 }
Exemple #18
0
        private void ExEditorRun(Query aQuery, eOpeningFileContent aOFContent)
        {
            string fileName = CASTools.PathWithEndSeparator(_txtTempPath.Text)
            + aQuery.Name.Replace(_tvQueries.PathSeparator, "_"); //.Replace(".","_");
              switch (aOFContent)
              {
            case eOpeningFileContent.SQL:
              fileName += ".sql";
              break;
            case eOpeningFileContent.XSLT:
              fileName += ".xslt";
              break;
              }

              StreamWriter fl = new StreamWriter(fileName, false, Encoding.Default);
              switch (aOFContent)
              {
            case eOpeningFileContent.SQL:
              fl.Write(aQuery.Text);
              break;
            case eOpeningFileContent.XSLT:
              fl.Write(aQuery.XSLT);
              break;
              }
              fl.Close();

              ProcessStartInfo psi = new ProcessStartInfo();
              try
              {
            psi.FileName = _txtTextEditor.Text; //@"C:\ASW\NotePadPP\notepad++.exe";
            psi.Arguments = "\"" + fileName + "\"";
              }
              catch { }

              if (psi.FileName.Length > 0)
              {
            try
            {
              if (_currProc == null)
              {
            _currProc = Process.Start(psi);
            _currProc.EnableRaisingEvents = true;
            _currProc.Exited += new EventHandler(DoCurrProcExited);
              }
              else
            Process.Start(psi);

              _ofArr.Add(new OpeningFile(fileName, aOFContent, aQuery));
            }
            catch (Exception ex)
            {
              Error.ShowError(ex.Message);
            }
              }
        }
Exemple #19
0
        public ucTreeQuery()
        {
            //_ses = null;
            _prevSelectedQuery = null;
            pViewHidden = false;

            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            _tt = new ToolTip();
            // Set up the delays for the ToolTip.
            _tt.AutoPopDelay = 100;
            //_tt.InitialDelay = 1000;
            //_tt.ReshowDelay = 500;
            _tt.AutomaticDelay = 0;
            // Force the ToolTip text to be displayed whether or not the form is active.
            _tt.ShowAlways = true;

            this.MouseMove += new MouseEventHandler(ucTreeQuery_MouseMove);
        }
Exemple #20
0
 public void DeleteQuery(Query aQr)
 {
     mSes.Queries.Remove(aQr);
 }
Exemple #21
0
        private void DoCommandNewQuery(object sender, System.EventArgs e)
        {
            string newNodeName = string.Empty;
              if (_tvQueries.SelectedNode != null)
            newNodeName = GetQueryNameFoldersWS(_tvQueries.SelectedNode.FullPath);
              newNodeName += "Новый запрос ";

              Query q = new Query();

              q.Name = newNodeName + (_task.pCountQuery + 1).ToString();
              q.Text = "SELECT * FROM xxx";

              _task.AddQuery(q);
              _tvQueries.Load(_task);
        }
Exemple #22
0
 public ucParamTV(Performer aPerf)
 {
     mPerf = aPerf;
       mLocParams = new ArrayList(2);
       mSQLExps = new string[] { };
       mIsShowEmptyItem = false;
       pIsImageDefined = false;
       pCurrentQuery = null;
 }
Exemple #23
0
 public void AddQuery(Query aQr)
 {
     mSes.Queries.Add(aQr);
 }
Exemple #24
0
        public void SetValueTo(Query aQ)
        {
            aQ.Code = CASTools.ConvertToInt32Or0(_txtCode.Text);

            if (_txtName0.Text.Length == 0)
                aQ.Name = _txtName.Text;
            else
                aQ.Name = _txtName0.Text + @"\" + _txtName.Text;
            aQ.Author = _txtAuthor.Text;
            aQ.ImageName = _txtImage.Text;
            aQ.Note = _txtNote.Text;
            aQ.Hidden = _chkHidden.Checked;
        }
Exemple #25
0
 public bool IsCorrectQueryCode(int aCode, Query aQ)
 {
     return mSes.IsCorrectQueryCode(aCode, aQ);
 }
Exemple #26
0
        /// <summary>
        /// Загрузка запроса из фйла.
        /// </summary>
        /// <param name="aFileName">Имя файла.</param>
        /// <returns>Загруженный запрос.</returns>
        public static Query Load(string aFileName)
        {
            Query q = new Query();

              FileStream f = new FileStream(aFileName, FileMode.Open);
              XmlSerializer xs = new XmlSerializer(typeof(Query));
              q = (Query)xs.Deserialize(f);

              f.Close();

              return q;
        }