示例#1
0
/// <summary>
/// Read concentration values & units
/// </summary>

        void ReadConcData()
        {
            int t0 = TimeOfDay.Milliseconds();

            Conc      = new Dictionary <int, float>();
            ConcUnits = new Dictionary <int, string>();

            BinaryReader br           = OpenBinaryReader("Conc.bin");
            long         streamLength = br.BaseStream.Length;

            while (true)
            {
                if (br.BaseStream.Position >= streamLength - 1)
                {
                    break;
                }
                int   rowNum = br.ReadInt32();
                float conc   = br.ReadSingle();
                Conc[rowNum] = conc;

                string concUnits = br.ReadString();
                ConcUnits[rowNum] = concUnits;
            }
            br.Close();

            t0 = TimeOfDay.Milliseconds() - t0;
            ClientLog.Message("Read cache file time (" + "Conc.bin" + "): " + t0);
            return;
        }
示例#2
0
        /// <summary>
        /// Show with up to 4 custom buttons
        /// </summary>
        /// <param name="message"></param>
        /// <param name="caption"></param>
        /// <param name="button1"></param>
        /// <param name="button2"></param>
        /// <param name="button3"></param>
        /// <param name="button4"></param>
        /// <param name="icon"></param>
        /// <returns>Value of 1 - 4 corresponding to button pressed </returns>

        public static int ShowWithCustomButtons(
            string message,
            string caption,
            string button1,
            string button2,
            string button3,
            string button4,
            MessageBoxIcon icon,
            int width  = -1,
            int height = -1)
        {
            if (!SS.I.Attended)
            {
                ClientLog.Message("Show: " + message);
                return((int)DialogResult.OK);
            }

            Progress.Hide(); // hide any progress message

            MessageBoxMx mb = new MessageBoxMx();

            if (JupyterGuiConverter.ConversionsEnabled)
            {
                MessageBoxMx2 mb2 = new MessageBoxMx2();
                new JupyterGuiConverter().ConvertFormOrUserControl(mb2);
            }

            int rc = mb.ShowInstance(message, caption, button1, button2, button3, button4, icon, width, height);

            return(rc);
        }
示例#3
0
/// <summary>
/// Method to get bitmap
/// </summary>
/// <param name="index"></param>
/// <returns></returns>

        private GetImageBitmapArgs GetImageBitmap(CellInfo ci, DataRowMx dr, int listSourceRowIndex, object fieldValue, ImageMx imageMx, int callId)
        {
            DateTime t0 = DateTime.Now;

            QueryManager     qm   = Grid.QueryManager;
            ResultsFormatter fmtr = qm.ResultsFormatter;

            FormattedFieldInfo ffi = fmtr.FormatField(ci.Rt, ci.TableIndex, ci.Rfld, ci.FieldIndex, dr, listSourceRowIndex, fieldValue, ci.DataRowIndex, false);

            if (ffi.FormattedBitmap == null)
            {
                ffi.FormattedBitmap = new Bitmap(1, 1);
            }
            imageMx.FormattedBitmap = ffi.FormattedBitmap;     // store ref to bitmap
            imageMx.Value           = imageMx.FormattedBitmap; // value is also the bitmap

            imageMx.IsRetrievingValue = false;                 // retrieve is complete

            StoreFormattingInformationInMdt(ffi, fieldValue, dr, ci, imageMx);

            //if (Debug)
            ClientLog.Message("GetImageBitmap complete for callId: " + callId + ", Time(ms) = " + TimeOfDay.Delta(t0));

            GetImageBitmapArgs a = new GetImageBitmapArgs();

            a.ci = ci;
            a.dr = dr;
            a.listSourceRowIndex = listSourceRowIndex;
            a.fieldValue         = fieldValue;
            a.imageMx            = imageMx;
            a.callId             = callId;
            return(a);
        }
示例#4
0
 private void BandedGridView_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
 {
     if (Debug)
     {
         ClientLog.Message("SelectionChanged");
     }
     return;
 }
示例#5
0
 private void BandedGridView_LostFocus(object sender, EventArgs e)
 {
     if (Debug)
     {
         ClientLog.Message("LostFocus");
     }
     return;
 }
示例#6
0
 private void BandedGridView_DataSourceChanged(object sender, EventArgs e)
 {
     if (Debug)
     {
         ClientLog.Message("DataSourceChanged");
     }
     return;
 }
示例#7
0
 private void BandedGridView_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e)
 {
     if (Debug)
     {
         ClientLog.Message("FocusedRowChanged");
     }
     return;
 }
示例#8
0
 private void BandedGridView_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
 {
     if (Debug)
     {
         ClientLog.Message("ValidatingEditor");
     }
     return;
 }
示例#9
0
 private void BandedGridView_ShownEditor(object sender, EventArgs e)
 {
     if (Debug)
     {
         ClientLog.Message("ShownEditor");
     }
     return;
 }
示例#10
0
        /// <summary>
        /// Show a message box and return result
        /// </summary>
        /// <param name="messageText"></param>
        /// <param name="titleCaption"></param>
        /// <param name="buttons"></param>
        /// <param name="icon"></param>
        /// <returns></returns>
        ///
        public static DialogResult Show(
            string messageText,
            string titleCaption,
            MessageBoxButtons buttons,
            MessageBoxIcon icon,
            int width  = -1,
            int height = -1)
        {
            DialogResult dr = DialogResult.OK;

            if (!Lex.IsNullOrEmpty(ScriptLog.FileName))
            {
                ScriptLog.Message("> " + messageText);
            }

            if (!SS.I.Attended)
            {
                ClientLog.Message("Show: " + messageText);
                return(DialogResult.OK);
            }

            else if (SS.I.QueryTestMode)
            {
                QueryTest.LogMessage("Show: " + messageText);
                return(DialogResult.OK);
            }

            //DebugLog.Message(messageText += "\r\n" + new StackTrace(true)); // debug where message is called from"

            Progress.Hide();                       // hide any progress message

            if (Lex.Contains(messageText, "<br>")) // replace "<br>" with newlines
            {
                messageText = messageText.Replace("<br>", "\r\n");
            }

            if (Lex.CountLines(messageText) > 5)
            {
                if (width <= 0)
                {
                    width = 650;
                }
                if (height <= 0)
                {
                    height = 400;
                }
                dr = ShowWithCustomSize(messageText, titleCaption, buttons, icon, width, height);
                return(dr);
            }

            if (messageText.Length > 72 && !messageText.Contains("\r") && !messageText.Contains("\n"))
            {
                messageText = WrapText(messageText, 6000);
            }
            //icon = MessageBoxIcon.Information;
            dr = XtraMessageBox.Show(messageText, titleCaption, buttons, icon);
            return(dr);
        }
示例#11
0
        private void Progress_FormClosed(object sender, FormClosedEventArgs e)
        {
            try
            {
                ProgressTimer.Enabled = false;
            }
            catch (Exception ex)             // occasionally throws a can't create window exception
            { ClientLog.Message("Progress_FormClosed exception: " + DebugLog.FormatExceptionMessage(ex)); }

            Showing = false;
        }
示例#12
0
        public static string FileName = "";         // log file to write to
        /// <summary>
        /// Log a message to the script log
        /// </summary>
        /// <param name="msg"></param>

        public static void Message(string msg)
        {
            if (!Lex.IsNullOrEmpty(FileName))
            {
                LogFile.Message(msg, FileName);
            }

            ClientLog.Message(msg);

            return;
        }
示例#13
0
        /// <summary>
        /// Store edited data for unbound column in DataTable
        /// </summary>
        /// <param name="e"></param>
        /// <param name="ci"></param>

        void SetGridData(CustomColumnDataEventArgs e, CellInfo ci)
        {
            UnboundSets++;
            if (DataTableManager.DebugDetails)
            {
                ClientLog.Message("SetData");
                //SystemUtil.Beep();
            }

            Grid.GetEditor().CellTextEdited(e, ci);
            return;
        }
示例#14
0
        /// <summary>
        /// Log a Message
        /// </summary>
        /// <param name="msg"></param>

        public void Message(
            string msg,
            string logFileName)
        {
            ClientLog.Message(msg);                    // log to client

            if (!SF.ServiceFacade.UseRemoteServices)   // if not using remote services then
            {
                ServicesLog.Message(msg, logFileName); // write the message to the local services log also
            }
            return;
        }
示例#15
0
        /// <summary>
        /// Perform an Application.DoEvents() avoiding recursion and catching and logging any exceptions
        /// </summary>

        public static void DoEvents()
        {
            if (InDoevents)
            {
                return;                         // avoid event recursion (note that this can cause reentry into CustomUnboundColumnData)
            }
            InDoevents = true;
            try { Application.DoEvents(); }             // update display
            catch (Exception ex)
            { ClientLog.Message("DoEvents exception: " + DebugLog.FormatExceptionMessage(ex)); }
            InDoevents = false;
        }
示例#16
0
/// <summary>
/// Callback after image is retrieved refreshes the grid with the new value
/// </summary>
/// <param name="r"></param>

        void ImageBitmapRetrieved(IAsyncResult r)
        {
            GetImageBitmapDelegate d = (r as AsyncResult).AsyncDelegate as GetImageBitmapDelegate;

            GetImageBitmapArgs args = d.EndInvoke(r);             // end invoke and get the handle of the row that has been updated

            RefreshGridForImageValue();
            if (DebugDetails)
            {
                ClientLog.Message("ImageBitmapRetrieved callback called for callId: " + args.callId);
            }
        }
示例#17
0
        /// <summary>
        /// Show Mobius system availability message
        /// </summary>
        /// <param name="messageText"></param>
        /// <param name="messageTitle"></param>
        /// <param name="icon"></param>

        public static void Show(
            string messageText,
            string messageTitle,
            MessageBoxIcon icon,
            Form parentForm)
        {
            if (!Lex.IsNullOrEmpty(ScriptLog.FileName))
            {
                ScriptLog.Message("> " + messageTitle + " - " + messageText);
            }

            if (!SS.I.Attended)
            {
                ClientLog.Message("Show: " + messageTitle + " - " + messageText);
                return;
            }

            bool error = (icon == MessageBoxIcon.Error);

            SystemAvailabilityMsg sam = new SystemAvailabilityMsg();

            sam.Text             = messageTitle;
            sam.SysAvailMsg.Text = messageText;
            MessageBoxMx.SetIconImageIndex(sam.IconImage, icon);

            if (!error && SS.I != null && SS.I.UserIniFile != null)
            {
                string dontShowMsg = SS.I.UserIniFile.Read("SystemAvailabilityMsgDontShowMsg");
                if (Lex.Eq(messageText, dontShowMsg))
                {
                    return;                                                   // if msg not to show just return
                }
                sam.DontShowAgainButton.Visible = true;
            }

            else
            {
                sam.DontShowAgainButton.Visible = false;             // hide for error
            }
            if (parentForm != null && parentForm.Visible)            // put in front of supplied form if any
            {
                sam.ShowDialog(parentForm);
            }

            else
            {
                sam.ShowDialog();
            }

            return;
        }
示例#18
0
        /// <summary>
        /// Constructor
        /// </summary>
        private Progress()
        {
            InitializeComponent();

            Id = ++InstanceCount;

            OriginalFormSize    = Size;
            OriginalCaptionSize = Caption.Size;

            if (Debug)
            {
                ClientLog.Message("Progress - Creating instance: " + Id);
            }
        }
示例#19
0
/// <summary>
/// Start async call to get image if not already in progress
/// </summary>
/// <param name="ci"></param>
/// <param name="dr"></param>
/// <param name="listSourceRowIndex"></param>
/// <param name="fieldValue"></param>
/// <param name="imageMx"></param>
/// <param name="callId"></param>

        private void GetImageBitmapAsync(CellInfo ci, DataRowMx dr, int listSourceRowIndex, object fieldValue, ImageMx imageMx, int callId)
        {
            if (!imageMx.IsRetrievingValue)             // start retrieve if not already started
            {
                //if (Debug)
                ClientLog.Message("Dispatching async callId: " + callId);

                imageMx.IsRetrievingValue = true;
                GetImageBitmapDelegate d = new GetImageBitmapDelegate(GetImageBitmap);
                d.BeginInvoke(ci, dr, listSourceRowIndex, fieldValue, imageMx, callId, new AsyncCallback(ImageBitmapRetrieved), null);
                return;
            }

            else
            {
                return;
            }
        }
示例#20
0
        void HideInstance()
        {
            // Note: Using Hide() or Visible = false seems to fail in some cases (e.g. Show alerts) or
            // when control is switched to another app.

            lock (InstanceLock)
            {
                try
                {
                    if (Debug)
                    {
                        ClientLog.Message("Progress - Hide");
                    }
                    if (!SS.I.Attended)
                    {
                        return;
                    }

                    if (Instance == null)
                    {
                        return;
                    }
                    if (!Showing)
                    {
                        return;
                    }

                    Showing = false;

                    ((Form)Instance).Hide();                     // call base form method to hide the form
                    Instance.Visible = false;                    // hide doesn't always work if user has switched to another app

                    if (Debug)
                    {
                        ClientLog.Message("Progress - Instance.Visible: " + Instance.Visible);
                    }
                }
                catch (Exception ex)
                {
                    ClientLog.Message("Hide exception: " + DebugLog.FormatExceptionMessage(ex));
                }
                return;
            }
        }
示例#21
0
        /// <summary>
        /// ReadStringArray
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>

        String[] ReadStringArray(string fileName)
        {
            int          t0 = TimeOfDay.Milliseconds();
            BinaryReader br = OpenBinaryReader(fileName);

            String[] a = new String[ResultsRowCount];
            for (int i1 = 0; i1 < ResultsRowCount; i1++)
            {
                if (i1 >= ResultsRowCount)
                {
                    break;
                }
                a[i1] = br.ReadString();
            }

            br.Close();
            t0 = TimeOfDay.Milliseconds() - t0;
            ClientLog.Message("Read cache file time (" + fileName + "): " + t0);
            return(a);
        }
示例#22
0
        /// <summary>
        /// Post Progress message for display at next timer tick
        /// </summary>
        /// <param name="caption"></param>
        /// <param name="title"></param>
        /// <param name="allowCancel"></param>
        /// <param name="cancellingMessage"></param>

        public static void Show(
            string caption,
            string title,
            bool allowCancel,
            string cancellingMessage)
        {
            VerifyFormExistence();

            PendingCaption           = caption;
            PendingTitle             = title;
            PendingAllowCancel       = allowCancel;
            PendingCancellingMessage = cancellingMessage;
            PendingShow = true;
            PendingHide = false;
            //if (Instance != null) Instance.ProgressTimer.Enabled = true;

            PerShowCancelRequestedFlag = false;

            if (Debug)
            {
                ClientLog.Message("Progress - Posting Show: " + caption);
            }
            //if (Lex.Contains(caption, "Retrieving data")) caption = caption; // debug

            if (SS.I.LocalServiceMode)             // if local service mode try to show message now since timer ticks may not be processed if in CPU intensive task
            {
                //while (PendingShow)
                {
                    Thread.Sleep(10);
                    UIMisc.DoEvents();

                    string stackTrace = new System.Diagnostics.StackTrace(true).ToString();
                    if (Lex.Contains(stackTrace, "_tick"))                     // if in a timer tick process immediately
                    {
                        Instance.ProgressTimer_Tick(null, null);
                    }
                }
            }

            return;
        }
示例#23
0
        /// <summary>
        /// Handle conversion of Mobius custom data types between the grid and the underlying DataSet
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        public void OnCustomUnboundColumnData(object sender, CustomColumnDataEventArgs e)
        {
            try
            {
                if (InCustomUnboundColumnData)
                {
                    if (DebugDetails)                     // check for reentry which can cause display issues
                    {
                        ClientLog.Message("CustomUnboundColumnData reentry: " + new StackTrace(true));
                    }
                    //return;
                }

                InCustomUnboundColumnData = true;
                ProcessCustomUnboundColumnDataEvent(sender, e);
            }

            catch (Exception ex)
            { ClientLog.Message(DebugLog.FormatExceptionMessage(ex)); }

            InCustomUnboundColumnData = false;
            return;
        }
示例#24
0
/// <summary>
/// ReadIntArray
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>

        int[] ReadIntArray(string fileName)
        {
            // See the following for data on fast binary reading: http://www.codeproject.com/KB/files/fastbinaryfileinput.aspx
            // Also see: Buffer.BlockCopy(src, scrOffset, dst, dstOffset, count);

            int          t0 = TimeOfDay.Milliseconds();
            BinaryReader br = OpenBinaryReader(fileName);

            int[] a = new int[ResultsRowCount];
            for (int i1 = 0; i1 < ResultsRowCount; i1++)
            {
                if (i1 >= ResultsRowCount)
                {
                    break;
                }
                a[i1] = br.ReadInt32();
            }

            br.Close();
            t0 = TimeOfDay.Milliseconds() - t0;
            ClientLog.Message("Read cache file time (" + fileName + "): " + t0);
            return(a);
        }
示例#25
0
        public static void Message(
            string msg,
            string logFileName = null)
        {
            if (ServicesLogFile == null)
            {
                ServicesLogFile = new ServicesLogFile(CommonConfigInfo.ServicesLogFileName);
                //ServicesLogFile.ResetFile();
            }

            try
            {
                ServicesLogFile.Message(msg, logFileName);
            }

            catch (Exception ex)             // log locally in case service message fails
            {
                string msg2 = DebugLog.FormatExceptionMessage(ex)
                              + "\r\nOriginal Message: " + msg;
                ClientLog.Message(msg2);
            }

            return;
        }
示例#26
0
        ///// <summary>
        ///// Turn screen updating on/off
        ///// </summary>
        ///// <param name="updateScreen"></param>

        //public static void ScreenUpdating(bool updateScreen)
        //{
        //	if (BlockScreenVisibilityChanges) return; // debug

        //	if (LogCalls) DebugLog.Message("ExcelOp ScreenUpdating");
        //	try
        //	{
        //		XlApp.ScreenUpdating = updateScreen;

        //		//if (!updateScreen)
        //		//{
        //		//	if (XlApp.Left < 16000)
        //		//		WindowLeft = XlApp.Left;
        //		//	XlApp.Left = 16000;  // move off screen
        //		//}

        //		//else XlApp.Left = WindowLeft;
        //	}
        //	catch (Exception ex) { ex = ex; }
        //}


        /// <summary>
        /// Remove modules from excel file to avoid Excel Security warning startup message
        /// </summary>

        public static void RemoveModules()
        {
            if (LogCalls)
            {
                DebugLog.Message("ExcelOp RemoveModules");
            }

            // Tools > Macro > Security > Security Level must be set to Medium.
            // Also Tools > Macro > Security > Trusted Sources >
            // Trust access to Visual Basic Project must be enabled
            // (See: http://support.microsoft.com/kb/282830/)

            try                                 // remove modules
            {
                if (IsInsightForExcelAvailable) // call method in module if Insight
                {
                    //object ro = XlApp.Run("DeleteVbaModule");
                    return;
                }

                else
                {
                    foreach (VBComponent vbc in XlBook.VBProject.VBComponents)
                    {
                        string s = vbc.Name;
                        if (s.ToLower().StartsWith("module"))                         // just modules
                        {
                            XlBook.VBProject.VBComponents.Remove(vbc);
                        }
                    }

                    return;
                }
            }
            catch (Exception ex) { ClientLog.Message("RemoveModules - " + ex.Message); }
        }
示例#27
0
        /// <summary>
        /// Begin cache table to disk
        /// Caching is used to avoid running out of memory, usually for large exports
        /// </summary>

        public void BeginCaching()
        {
            if (!AllowCaching)
            {
                return;
            }

            if (CacheStartPosition >= 0)
            {
                return;                                      // return if already caching
            }
            if (CacheReader != null)
            {
                return;                                  // return if reading an existing cache file
            }
            if (RowRetrievalState == RowRetrievalState.Complete)
            {
                return;                                                              // return if already have complete data set
            }
            CacheStartPosition = DataTableMx.Rows.Count;
            //if (CacheStartPosition < MinCacheStartPosition)
            //  CacheStartPosition = MinCacheStartPosition;

            CacheFile   = TempFile.GetTempFileName(ClientDirs.TempDir, "mds", true);
            CacheWriter = new StreamWriter(CacheFile);
            RowsRemovedFromDataTable = 0;
            RowsWrittenToCache       = 0;
            CacheStartRowCount       = RowCount;
            CacheStartKeyCount       = KeyCount;

            if (DebugCaching)
            {
                ClientLog.Message("Begincaching, CachingStartPosition: " + DataTableMx.Rows.Count + ", CachingStartRowCount: " + CacheStartRowCount);
            }
            return;
        }
示例#28
0
		/// <summary>
		/// Word operation
		/// </summary>
		/// <param name="command"></param>
		/// <param name="sArg"></param>
		/// <param name="nArg1"></param>
		/// <param name="nArg2"></param>
		/// <param name="nArg3"></param>
		/// <param name="nArg4"></param>
		/// <returns></returns>
		public static string Call(
			string command,
			string sArg,
			int nArg1,
			int nArg2,
			int nArg3,
			int nArg4,
			bool bArg)
		{

			object missingObj = System.Reflection.Missing.Value; // missing object parameter 

			if (SS.I.DebugFlags[5] != null) // dump out command for debug
			{
				ClientLog.Message("Call " + command + " " + sArg);
			}

			try // catch any Word exception
			{

				//******************************************************************************  
				if (Lex.Eq(command, "CreateObject"))  // create the word object
				//******************************************************************************  
				{
					try
					{
						WdApp = new Microsoft.Office.Interop.Word.Application();
					}
					catch (Exception ex)
					{
						return "Word failed to start";
					}

				}

		//******************************************************************************  
				else if (Lex.Eq(command, "Quit"))
				{ // quit application
					//******************************************************************************  

					//Microsoft.Office.Interop.Word.Application.
					WdApp.Quit(ref missingObj, ref missingObj, ref missingObj);

					//	AutoWrap(DISPATCH_METHOD, NULL, WdApp, L"Quit", 0);
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "Cells.SetWidth"))
				{
					//******************************************************************************  
					WdSel.Cells.SetWidth(nArg1, WdRulerStyle.wdAdjustNone);
#if false
	release_obj(WdTemp); // get current font object
	AutoWrap(DISPATCH_PROPERTYGET, &result, WdSel, L"Cells", 0);
	WdTemp = result.pdispVal;

	SETLONG(Arg1,nArg1);  // width in points
	SETLONG(Arg2,wdAdjustNone); // ruler style, required sArg
	AutoWrap(DISPATCH_METHOD, &result, WdTemp, L"Setwidth", 2, Arg2, Arg1);
	VariantClear(&Arg1);
	VariantClear(&Arg2);
#endif
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "DeleteObject"))
				{
					//******************************************************************************  
					WdSel = null;
					WdTable = null;
					WdTables = null;
					WdDoc = null;
					WdDocs = null;
					WdApp = null;
#if false
	// Release references, must do lower to higher level...
	release_obj(WdTemp);
	release_obj(WdSel);
	release_obj(WdTable);
	release_obj(WdTables);
	release_obj(WdDoc);
	release_obj(WdDocs);
	release_obj(WdApp);
#endif
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "Close"))
				{
					//******************************************************************************  
					//      excelobj.ActiveWorkbook.Close False ' no prompt for save
					((_Document)WdDoc).Close(ref missingObj, ref missingObj, ref missingObj);

					//	SETLONG(SaveChanges,wdSaveChanges); // don't prompt
					//	AutoWrap(DISPATCH_METHOD, NULL, WdDoc, L"Close", 1, SaveChanges);
					//	VariantClear(&SaveChanges);
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "Documents.Add"))
				{ // Add a new document
					//******************************************************************************  

					WdDocs = WdApp.Documents;
					WdDoc = WdDocs.Add(ref missingObj, ref missingObj, ref missingObj, ref missingObj);

#if false
	release_obj(WdDocs); // Get active documents
	AutoWrap(DISPATCH_PROPERTYGET, &result, WdApp, L"Documents", 0);   // Get Documents collection
	WdDocs = result.pdispVal;

	release_obj(WdDoc); // Add new document
	AutoWrap(DISPATCH_METHOD, &result, WdDocs, L"Add", 0);
	WdDoc = result.pdispVal;
#endif

					if (WdDoc == null) return ("Error adding document");
					UpdateSelection(); // update selection
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "EndKey"))
				{
					//******************************************************************************  
					Object unit = nArg1;
					WdSel.HomeKey(ref unit, ref missingObj);

					//	SETLONG(Arg,nArg1); 
					//	AutoWrap(DISPATCH_METHOD, &result, WdSel, L"HomeKey", 1, Arg);
					//	VariantClear(&Arg);

					UpdateSelection(); // update selection
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "Font.Name"))
				{
					//******************************************************************************  
					//      WordObj.Selection.Font.Name = sArg
					WdSel.Font.Name = sArg;

#if false
	release_obj(WdTemp); // get current font object
	AutoWrap(DISPATCH_PROPERTYGET, &result, WdSel, L"Font", 0);
	WdTemp = result.pdispVal;

	SETSTR(Arg,sArg);  // set font name
	AutoWrap(DISPATCH_PROPERTYPUT, &result, WdTemp, L"Name", 1, Arg);
	VariantClear(&Arg);
#endif
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "Font.Size"))
				{
					//******************************************************************************  
					//      WordObj.Selection.Font.Size = sArg

					WdSel.Font.Size = nArg1;

#if false
	release_obj(WdTemp); // get current font object
	AutoWrap(DISPATCH_PROPERTYGET, &result, WdSel, L"Font", 0);
	WdTemp = result.pdispVal;

	SETLONG(Arg,nArg1);  // set font size
	AutoWrap(DISPATCH_PROPERTYPUT, &result, WdTemp, L"Size", 1, Arg);
	VariantClear(&Arg);
#endif
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "Font.Bold"))
				//******************************************************************************  
				{
					if (bArg) WdSel.Font.Bold = -1;
					else WdSel.Font.Bold = 0;
				}

	//******************************************************************************  
				else if (Lex.Eq(command, "Font.Italic"))
				//******************************************************************************  
				{
					if (bArg) WdSel.Font.Italic = -1;
					else WdSel.Font.Italic = 0;
				}

		//******************************************************************************  
				else if (Lex.Eq(command, "Font.Subscript"))
				//******************************************************************************  
				{
					WdSel.Font.Subscript = nArg1;

#if false
	release_obj(WdTemp); // get current font object
	AutoWrap(DISPATCH_PROPERTYGET, &result, WdSel, L"Font", 0);
	WdTemp = result.pdispVal;

	SETLONG(Arg,nArg1);  // set font size
	AutoWrap(DISPATCH_PROPERTYPUT, &result, WdTemp, L"Subscript", 1, Arg);
	VariantClear(&Arg);
#endif
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "Font.Superscript"))
				{
					//******************************************************************************  
					WdSel.Font.Superscript = nArg1;

#if false
	release_obj(WdTemp); // get current font object
	AutoWrap(DISPATCH_PROPERTYGET, &result, WdSel, L"Font", 0);
	WdTemp = result.pdispVal;

	SETLONG(Arg,nArg1);  // set font size
	AutoWrap(DISPATCH_PROPERTYPUT, &result, WdTemp, L"Superscript", 1, Arg);
	VariantClear(&Arg);
#endif
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "SetDefaultCellStyle"))
				//******************************************************************************  
				{ // Cell style (e.g. backcolor) automatically carries down do successive
					// rows and must be explicitly reset

					//			int rgbBlack = 0;
					//			if (WdSel.Font.Color != (Microsoft.Office.Interop.Word.WdColor)rgbBlack)
					//				WdSel.Font.Color = (Microsoft.Office.Interop.Word.WdColor)rgbBlack;

					//			int rgbWhite = 255 + 255 * 256 + 255 * 65536;
					//			if (WdSel.Cells.Shading.BackgroundPatternColor != (Microsoft.Office.Interop.Word.WdColor)rgbWhite)
					//				WdSel.Cells.Shading.BackgroundPatternColor = (Microsoft.Office.Interop.Word.WdColor)rgbWhite;

					if (WdSel.Font.Color != Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic)
						WdSel.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic;

					if (WdSel.Cells.Shading.BackgroundPatternColor != Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic)
						WdSel.Cells.Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic;
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "Font.Color"))
				//******************************************************************************  
				{
					Color c = Color.FromArgb(nArg1);
					int rgb = c.R + c.G * 256 + c.B * 65536;
					WdSel.Font.Color = (Microsoft.Office.Interop.Word.WdColor)rgb;
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "BackColor"))
				//******************************************************************************  
				{
					Color c = Color.FromArgb(nArg1);
					int rgb = c.R + c.G * 256 + c.B * 65536;
					WdSel.Cells.Shading.BackgroundPatternColor = (Microsoft.Office.Interop.Word.WdColor)rgb;
				}

		//******************************************************************************  
				else if (Lex.Eq(command, "HomeKey"))
				{
					//******************************************************************************  
					Object unit = nArg1;
					WdSel.HomeKey(ref unit, ref missingObj);
#if false
	SETLONG(Arg,nArg1); 
	AutoWrap(DISPATCH_METHOD, &result, WdSel, L"HomeKey", 1, Arg);
	VariantClear(&Arg);
#endif
					UpdateSelection(); // update selection
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "InlineShapes.AddPicture"))
				{ // insert image from file
					//******************************************************************************  
					InlineShape ils = WdSel.InlineShapes.AddPicture(sArg, ref missingObj, ref missingObj, ref missingObj);
					ils.Width = nArg1;
					ils.Height = nArg2;
#if false
	release_obj(WdTemp); // get current font object
	AutoWrap(DISPATCH_PROPERTYGET, &result, WdSel, L"InlineShapes", 0);
	WdTemp = result.pdispVal;

	SETSTR(Filename,sArg);  // filename
	SETLONG(Width,nArg1); // in points
	SETLONG(Height,nArg2);

	AutoWrap(DISPATCH_METHOD, &result, WdTemp, L"AddPicture", 1, Filename);
	release_obj(WdTemp);
	WdTemp = result.pdispVal; // new shape object

	AutoWrap(DISPATCH_PROPERTYPUT, NULL, WdTemp, L"Width", 1, Width);

	AutoWrap(DISPATCH_PROPERTYPUT, NULL, WdTemp, L"Height", 1, Height);

	VariantClear(&Filename);
	VariantClear(&Width);
	VariantClear(&Height);
#endif
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "InsertBreak"))
				{
					//******************************************************************************  
					object type = nArg1;
					WdSel.InsertBreak(ref type);

					//	SETLONG(Arg,nArg1); 
					//	AutoWrap(DISPATCH_METHOD, &result, WdSel, L"InsertBreak", 1, Arg);
					//	VariantClear(&Arg);

					UpdateSelection(); // update selection
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "InsertSymbol"))
				{
					//******************************************************************************  
					// InsertSymbol(CharacterNumber as Long, Font as String)
					int characterNumber = nArg1;
					object font = sArg;
					WdSel.InsertSymbol(characterNumber, ref font, ref missingObj, ref missingObj);
#if false
	SETLONG(Arg,nArg1); // get char number
	SETSTR(Arg2,sArg); // get font
	AutoWrap(DISPATCH_METHOD, &result, WdSel, L"InsertSymbol", 2, Arg2, Arg);
	VariantClear(&Arg);
	VariantClear(&Arg2);
#endif
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "Cells.Merge"))
				{ // merge cells together
					//******************************************************************************  
					WdSel.Cells.Merge();
#if false
	release_obj(WdTemp); // get current font object
	AutoWrap(DISPATCH_PROPERTYGET, &result, WdSel, L"Cells", 0);
	WdTemp = result.pdispVal;

	AutoWrap(DISPATCH_METHOD, &result, WdTemp, L"Merge", 0);
#endif
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "MoveLeft"))
				{ // units, count
					//******************************************************************************  
					if (nArg2 <= 0) nArg2 = 1;

					object unit = nArg1;
					object count = nArg2;
					WdSel.MoveLeft(ref unit, ref count, ref missingObj);
#if false
	SETLONG(Arg1,nArg1); 
	SETLONG(Arg2,nArg2); 
	AutoWrap(DISPATCH_METHOD, &result, WdSel, L"MoveLeft", 2, Arg2, Arg1);
	VariantClear(&Arg1);
	VariantClear(&Arg2);
#endif
					UpdateSelection(); // update selection
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "MoveRight"))
				{ // units, count, extend
					//******************************************************************************  
					object extend;
					if (nArg2 <= 0) nArg2 = 1;

					object unit = nArg1;
					object count = nArg2;
					if (nArg3 <= 0) extend = missingObj;
					else extend = nArg3;

					WdSel.MoveRight(ref unit, ref count, ref extend);
#if false
	SETLONG(Arg1,nArg1); 
	SETLONG(Arg2,nArg2); 
	SETLONG(Arg3,nArg3); 
	AutoWrap(DISPATCH_METHOD, &result, WdSel, L"MoveRight", 3, Arg3, Arg2, Arg1);
	VariantClear(&Arg1);
	VariantClear(&Arg2);
	VariantClear(&Arg3);
#endif

					UpdateSelection(); // update selection
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "MoveDown"))
				{ // units, count
					//******************************************************************************  
					if (nArg2 <= 0) nArg2 = 1;
					object unit = nArg1;
					object count = nArg2;
					WdSel.MoveDown(ref unit, ref count, ref missingObj);
#if false
	SETLONG(Arg1,nArg1); 
	SETLONG(Arg2,nArg2); 
	AutoWrap(DISPATCH_METHOD, &result, WdSel, L"MoveDown", 2, Arg2, Arg1);
	VariantClear(&Arg1);
	VariantClear(&Arg2);
#endif
					UpdateSelection(); // update selection
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "MoveUp"))
				{ // units, count
					//******************************************************************************  
					if (nArg2 <= 0) nArg2 = 1;
					object unit = nArg1;
					object count = nArg2;
					WdSel.MoveUp(ref unit, ref count, ref missingObj);
#if false
	SETLONG(Arg1,nArg1); 
	SETLONG(Arg2,nArg2); 
	AutoWrap(DISPATCH_METHOD, &result, WdSel, L"MoveUp", 2, Arg2, Arg1);
	VariantClear(&Arg1);
	VariantClear(&Arg2);
#endif

					UpdateSelection(); // update selection
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "PageSetup.Orientation"))
				{
					//******************************************************************************  

					if (nArg1 == 0)
						WdSel.PageSetup.Orientation = WdOrientation.wdOrientPortrait;
					WdSel.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
#if false
	release_obj(WdTemp);
	AutoWrap(DISPATCH_PROPERTYGET, &result, WdSel, L"PageSetup", 0);
	WdTemp = result.pdispVal;

	SETLONG(Arg,nArg1); 
	AutoWrap(DISPATCH_PROPERTYPUT, &result, WdTemp, L"Orientation", 1, Arg);
	VariantClear(&Arg);
#endif
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "PageSetup.Margins"))
				{
					//******************************************************************************  
					WdSel.PageSetup.TopMargin = nArg1;
					WdSel.PageSetup.BottomMargin = nArg2;
					WdSel.PageSetup.LeftMargin = nArg3;
					WdSel.PageSetup.RightMargin = nArg4;
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "PageSetup.PageSize"))
				{
					//******************************************************************************  
					WdSel.PageSetup.PageWidth = nArg1;
					WdSel.PageSetup.PageHeight = nArg2;
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "ParagraphFormat.Alignment"))
				{
					//******************************************************************************  
					WdSel.ParagraphFormat.Alignment = (WdParagraphAlignment)nArg1;
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "Cells.VerticalAlignment"))
				//******************************************************************************  
				{
					WdSel.Cells.VerticalAlignment = (WdCellVerticalAlignment)nArg1;
				}

		//******************************************************************************  
				else if (Lex.Eq(command, "Paste"))
				//******************************************************************************  
				{
					WdSel.Paste();
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "PasteSpecial"))
				{
					//******************************************************************************  
					//	PasteSpecial(IconIndex, Link, Placement, DisplayAsIcon, DataType)

					object iconIndex = 0;
					object link = false;
					object placement = InLine;
					object displayAsIcon = false;
					object dataType = nArg1; // set type of data to paste

					//	ClientLog.Message("Before PasteSpecial"); // TST & PRD 
					WdSel.PasteSpecial(ref iconIndex, ref link, ref placement, ref displayAsIcon,
						ref dataType, ref missingObj, ref missingObj);
					//	ClientLog.Message("After PasteSpecial");
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "InsertStructure"))
				//******************************************************************************  
				// Selection.InlineShapes.AddOLEObject ClassType:="ISISServer", FileName:= _
				//  "C:\Isis\sketch1-small.skc", LinkToFile:=False, DisplayAsIcon:=False
				// This is significantly slower than a paste
				{
					object classType = "ISISServer";
					object fileName = sArg;

					WdSel.InlineShapes.AddOLEObject(
						ref classType,
						ref fileName,
						ref missingObj,
						ref missingObj,
						ref missingObj,
						ref missingObj,
						ref missingObj,
						ref missingObj);
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "Rows.AllowBreakAcrossPages"))
				{ // keep all contents of row on same page
					//******************************************************************************  

					WdSel.Rows.AllowBreakAcrossPages = nArg1;
				}

		//******************************************************************************  
				else if (Lex.Eq(command, "Rows.HeadingFormat"))
				{ // mark rows as headings
					//******************************************************************************  

					WdSel.Rows.HeadingFormat = nArg1;
				}

		//******************************************************************************  
				else if (Lex.Eq(command, "SaveAs"))
				{ // save file in .doc format
					//******************************************************************************  
					try { File.Delete(sArg); } // delete any existing file
					catch (Exception ex) { };
					object fileName = sArg;
					object fileFormat = WdSaveFormat.wdFormatDocument;

					WdDoc.SaveAs(
						ref fileName, // FileName 
						ref fileFormat, // FileFormat 
						ref missingObj, // LockComments 
						ref missingObj, // Password 
						ref missingObj, // AddToRecentFiles 
						ref missingObj, // WritePassword 
						ref missingObj, // ReadOnlyRecommended 
						ref missingObj, // EmbedTrueTypeFonts 
						ref missingObj, // SaveNativePictureFormat
						ref missingObj,	// SaveFormsData 
						ref missingObj,	// SaveAsAOCELetter
						ref missingObj,	// Encoding
						ref missingObj,	// InsertLineBreaks 
						ref missingObj, // AllowSubstitutions 
						ref missingObj, // LineEnding 
						ref missingObj); // AddBiDiMarks
				}

		//******************************************************************************  
				else if (Lex.Eq(command, "ScreenUpdating"))
				{
					//******************************************************************************  
					WdApp.ScreenUpdating = bArg;
				}

		//******************************************************************************  
				else if (Lex.Eq(command, "SelectColumn"))
				{ // select current column of table
					//******************************************************************************  
					WdSel.SelectColumn();
					//	AutoWrap(DISPATCH_METHOD, NULL, WdSel, L"SelectColumn", 0); 
					UpdateSelection();
				}

				//******************************************************************************  
				else if (Lex.Eq(command, "SelectRow"))
				{ // select current row of table
					//******************************************************************************  
					WdSel.SelectRow();

					UpdateSelection();
				}

				//******************************************************************************  
				else if (Lex.Eq(command, "Tables.Add"))
				{ // number of rows & cols supplied
					//******************************************************************************  

					WdTables = WdDoc.Tables;
					Microsoft.Office.Interop.Word.Range range = WdSel.Range;
					int numRows = nArg1;
					int numCols = nArg2;
					WdTable = WdTables.Add(range, numRows, numCols, ref missingObj, ref missingObj);
					WdTable.Borders.InsideLineStyle = WdLineStyle.wdLineStyleSingle;
					WdTable.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle;

					UpdateSelection();
				}

				//******************************************************************************  
				else if (Lex.Eq(command, "TableSelect"))
				{
					//******************************************************************************  

					WdTable.Select();

					UpdateSelection(); // update selection
				}

				//******************************************************************************  
				else if (Lex.Eq(command, "TypeParagraph"))
				{
					//******************************************************************************  
					WdSel.TypeParagraph();

					UpdateSelection();
				}

				//******************************************************************************  
				else if (Lex.Eq(command, "TypeText"))
				{
					//******************************************************************************  
					WdSel.TypeText(sArg);
					//	SETSTR(Arg,sArg); 
					//	AutoWrap(DISPATCH_METHOD, &result, WdSel, L"TypeText", 1, Arg);
					//	VariantClear(&Arg);

					UpdateSelection();
				}

				//******************************************************************************  
				else if (Lex.Eq(command, "Visible"))
				{
					//******************************************************************************  
					WdApp.Visible = bArg;
#if false
	SETBOOL(True,1);
	SETBOOL(False,0);
	if (strcmpi((CCP)sArg,"true)) 
	AutoWrap(DISPATCH_PROPERTYPUT, NULL, WdApp, L"Visible", 1, True);

	else 	AutoWrap(DISPATCH_PROPERTYPUT, NULL, WdApp, L"Visible", 1, False);
#endif
				}

		//******************************************************************************  
				else throw new Exception("WordOp - Invalid operation " + command);
				//******************************************************************************  

				return ""; // everything must be ok

			} // end of try
示例#29
0
        /// <summary>
        /// Write out rows from table if caching has been activated
        /// </summary>

        internal void WriteRowsToCache(bool keepLastKeyValue)
        {
            DataRowMx dr;
            string    firstKey = "", lastKey = "";
            int       rowsRemovedInThisCall = 0, ri, ri2, srpi;

            if (!AllowCaching)
            {
                return;
            }

            if (CacheStartPosition < 0 || CacheWriter == null)
            {
                return;                                                            // just return if caching not active
            }
            if (DataTableMx.Rows.Count < CacheMiminumRowsRequiredForWriting)
            {
                return;
            }

            lock (DataTransferLock)             // lock the DataTable while changing
            {
                if (DataTableFetchPosition < CacheStartPosition)
                {
                    return;                                                              // only cache if fetching beyond start position
                }
                if (DataTableFetchPosition < DataTableMx.Rows.Count - 1)
                {
                    return;                                                                      // can only cache out if at end of available rows
                }
                dr       = DataTableMx.Rows[CacheStartPosition];
                firstKey = dr[KeyValueVoPos] as string;
                ri       = DataTableMx.Rows.Count - 1;
                dr       = DataTableMx.Rows[ri];
                lastKey  = dr[KeyValueVoPos] as string;                // key we want to keep

                if (QueryManager.MoleculeGrid != null)
                {
                    QueryManager.MoleculeGrid.BeginUpdate();
                }

                ri = CacheStartPosition;                       // start deleting here
                while (ri < DataTableMx.Rows.Count)
                {                                              // delete anything with key other than end value
                    dr = DataTableMx.Rows[ri];
                    string key2 = dr[KeyValueVoPos] as string; // end key with possibly partial data that we want to keep
                    if (keepLastKeyValue && key2 == lastKey)
                    {
                        break;
                    }

                    bool doCacheIO = !PurgeDataTableWithoutWritingToCacheFile;
                    if (doCacheIO)
                    {
                        object[]      oa     = dr.ItemArray;
                        StringBuilder sb     = VoArray.SerializeToText(oa, KeyValueVoPos, oa.Length - KeyValueVoPos);
                        string        lenStr = String.Format("{0,8:00000000}", sb.Length);
                        CacheWriter.Write(lenStr);                     // write length
                        CacheWriter.Write(sb);                         // write record
                        RowsWrittenToCache++;
                    }

                    DataTableMx.Rows.Remove(dr);
                    RowsRemovedFromDataTable++;
                    rowsRemovedInThisCall++;
                }

                DataTableFetchPosition -= rowsRemovedInThisCall;                 // adjust fetch position

                for (ri2 = CacheStartPosition; ri2 < DataTableMx.Rows.Count; ri2++)
                {                 // adjust row indexes held the row attributes in rows below those paged out
                    DataRowAttributes dra = GetRowAttributes(ri2);
                    if (dra == null)
                    {
                        continue;
                    }

                    dra.FirstRowForKey -= rowsRemovedInThisCall;
                    if (dra.SubRowPos == null)
                    {
                        continue;
                    }
                    for (srpi = 0; srpi < dra.SubRowPos.Length; srpi++)
                    {
                        dra.SubRowPos[srpi] -= rowsRemovedInThisCall;
                    }
                }
            }             // end of locked section

            if (QueryManager.MoleculeGrid != null)
            {
                QueryManager.MoleculeGrid.EndUpdate();
                QueryManager.MoleculeGrid.Refresh();
                Application.DoEvents();
            }

            if (DebugCaching)
            {
                ClientLog.Message(
                    "CachedRows - DataTable.Rows.Count: " + DataTableMx.Rows.Count +
                    ", FirstKey: " + firstKey + ", LastKey: " + lastKey +
                    ", RowsRemovedFromDataTable (This Call): " + rowsRemovedInThisCall +
                    ", RowsRemovedFromDataTable (Total): " + RowsRemovedFromDataTable +
                    ", RowsWrittenToCache (Total): " + RowsWrittenToCache +
                    ", DataTableFetchPosition: " + DataTableFetchPosition);
            }

            return;
        }
示例#30
0
        /// <summary>
        /// End table caching by writing out remaining records & opening file reader
        /// </summary>

        public void EndCaching()
        {
            if (!AllowCaching)
            {
                return;
            }

            if (CacheStartPosition < 0 || CacheWriter == null)
            {
                return;                                                            // caching active
            }
            if (RowsRemovedFromDataTable == 0)
            {
                if (CacheWriter != null)
                {
                    CacheWriter.Close();
                    CacheWriter = null;
                }
                CacheStartPosition = -1;
                return;
            }

            if (RowRetrievalState == RowRetrievalState.Running || RowRetrievalState == RowRetrievalState.Paused)
            {
                CancelRowRetrieval();            // cancel if not complete
            }
            WriteRowsToCache(false);             // write out remaining rows
            CacheWriter.Close();
            CacheWriter = null;

            CacheReader        = new StreamReader(CacheFile);
            CacheStartPosition = -1;

            //RowCount = CacheStartRowCount; // restore counts (todo: fix this: gives zero for export count with this code)
            //KeyCount = CacheStartKeyCount;

            RowRetrievalState = RowRetrievalState.Paused;
            if (DebugDetails)
            {
                ClientLog.Message("RowRetrievalState.Paused 3");
            }

            if (QueryManager.MoleculeGrid != null)
            {
                QueryManager.MoleculeGrid.EndUpdate();
                QueryManager.MoleculeGrid.Refresh();
                Application.DoEvents();
            }

            if (StatusBarManager != null)
            {                                           // update status bar, may process an event that generates a request for more rows
                StatusBarManager.DisplayRetrievalProgressState(RowRetrievalState);
                StatusBarManager.DisplayFilterCounts(); // update count display
            }

            if (DebugCaching)
            {
                ClientLog.Message("EndCaching: " + DataTableMx.Rows.Count);
            }

            return;
        }