Beispiel #1
0
        protected override async void OnDragDrop(DragEventArgs e)
        {
            base.OnDragDrop(e);
            if (e.Data.GetData(DataFormats.FileDrop) is string[] files && files.Any())
            {
                EnableControls?.Invoke(false);
                try
                {
                    using (var stream = new FileStream(files[0], FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        using (var sr = new StreamReader(stream, Encoding.UTF8, true))
                        {
                            Text = await sr.ReadToEndAsync();
                        }
                    }
                }
                catch
                {
                    Text = "Error reading file";
                }

                RefreshUndoRedoButton();
                EnableControls?.Invoke(true);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 创建行控件
        /// </summary>
        /// <param name="field">字段信息</param>
        /// <returns>行控件</returns>
        protected Control CreateItem(We7Control control)
        {
            HtmlTableRow       row   = new HtmlTableRow();
            HtmlTableCell      c     = new HtmlTableCell("TH");
            HtmlGenericControl lable = new HtmlGenericControl("strong");

            lable.InnerHtml = control.Label + ":";
            c.Controls.Add(lable);
            row.Cells.Add(c);

            c = new HtmlTableCell();
            We7Control ctr = control.Clone() as We7Control;

            if (!EnableControls.Contains(ctr.Type))
            {
                ctr.Type = "Text";
            }
            FieldControl fc = UIHelper.GetControl(ctr);

            fc.IsEdit = IsEdit;
            c.Controls.Add(fc);
            row.Cells.Add(c);

            row.Style.Add("display", control.Visible ? "" : "none");

            return(row);
        }
Beispiel #3
0
        private void BwXmlFormat_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                ShowMessage?.Invoke(e.Error.Message);
            }
            else
            {
                Text = e.Result?.ToString();
                RefreshUndoRedoButton();
            }

            ClearAllSelections(XmlFormatButton.GetCurrentParent());
            EnableControls?.Invoke(true);
        }
Beispiel #4
0
        private async void LoadButtonEvent(object sender, EventArgs e)
        {
            if (openFileDialog1?.ShowDialog() == DialogResult.OK)
            {
                var  fileInfo = new FileInfo(openFileDialog1.FileName);
                bool loadFile = true;
                if (fileInfo.Length > 1e7)
                {
                    var reply = ShowMessage?.Invoke(
                        "File is bigger than 10MB and this tool can have problem to show it. Are you sure?",
                        "Request",
                        MessageBoxButtons.OKCancel,
                        MessageBoxIcon.Exclamation);

                    loadFile = reply == null || reply == DialogResult.OK;
                }

                if (loadFile)
                {
                    try
                    {
                        EnableControls?.Invoke(false);
                        using (var stream = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                        {
                            using (var sr = new StreamReader(stream, Encoding.UTF8, true))
                            {
                                Text = await sr.ReadToEndAsync();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ShowMessage?.Invoke(ex.Message);
                    }
                    finally
                    {
                        RefreshUndoRedoButton();
                        EnableControls?.Invoke(true);
                    }
                }
            }
        }
        /// <summary>
        /// it will load when control first time loading
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ucConnectToPort_Load(object sender, EventArgs e)
        {
            try
            {
                ConnectionStatusDelegate = new StatusMsg(StatusUpdate);
                ConnectButtonDelegate    = new EnableControls(DisplayOfConnectButton);
                DisconnectButtonDelegate = new EnableControls(DisplayOfDisconnectButton);
                currentUCDelegate        = new EnableControls(DisplayOfCurrentUC);
                BindPortControlDelegate  = new BindPortControl(BindComPorts);
                MsgBoxDelegate           = new MsgBoxDisplay(ShowMsgBox);
                BindBaudRate();


                DefaultConnectedStatus();
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex);
            }
        }
Beispiel #6
0
 private async void SaveButtonEvent(object sender, EventArgs e)
 {
     if (saveFileDialog1?.ShowDialog() == DialogResult.OK)
     {
         try
         {
             EnableControls?.Invoke(false);
             var buffer = Encoding.Default.GetBytes(Text);
             using (var fs = new FileStream(saveFileDialog1.FileName, FileMode.Create, FileAccess.Write, FileShare.None, buffer.Length, true))
             {
                 await fs.WriteAsync(buffer, 0, buffer.Length);
             }
         }
         catch (Exception ex)
         {
             ShowMessage?.Invoke(ex.Message);
         }
         finally
         {
             EnableControls?.Invoke(true);
         }
     }
 }
Beispiel #7
0
 private void XmlFormatButton_Event(object sender, EventArgs e)
 {
     EnableControls?.Invoke(false);
     bwXmlFormat.RunWorkerAsync(Text);
 }
Beispiel #8
0
        public void InitLayout(PanelContext ctx)
        {
            PanelContext = ctx;
            if (!IsInitialized)
            {
                if (IsViewer)
                {
                    if (!String.IsNullOrEmpty(PanelContext.Panel.EditInfo.ViewerCss))
                    {
                        HtmlLink link = new HtmlLink();
                        link.Href = PanelContext.Panel.EditInfo.ViewerCss;
                        link.Attributes["type"] = "text/css";
                        link.Attributes["rel"]  = "stylesheet";
                        Page.Header.Controls.Add(link);
                    }
                }
                else
                {
                    if (!String.IsNullOrEmpty(PanelContext.Panel.EditInfo.EditCss))
                    {
                        HtmlLink link = new HtmlLink();
                        link.Href = PanelContext.Panel.EditInfo.EditCss;;
                        link.Attributes["type"] = "text/css";
                        link.Attributes["rel"]  = "stylesheet";
                        Page.Header.Controls.Add(link);
                    }
                }
                IsInitialized = true;
            }

            foreach (We7Control ctr in Panel.EditInfo.Controls)
            {
                if (IsViewer && String.Compare("ID", ctr.Name) == 0)
                {
                    continue;
                }
                We7Control control = new We7Control();
                foreach (PropertyInfo prop in ctr.GetType().GetProperties())
                {
                    prop.SetValue(control, prop.GetValue(ctr, null), null);
                }
                if (IsViewer && !EnableControls.Contains(control.Type))
                {
                    control.Type = "Text";
                }
                PlaceHolder c = UIHelper.GetControl <PlaceHolder>("_" + control.ID, this);
                if (c != null)
                {
                    c.Controls.Clear();
                    c.Controls.Add(UIHelper.GetControl(control));
                }
                else
                {
                    FieldControl fc = UIHelper.GetControl <FieldControl>(control.ID, this);
                    if (UIHelper.GetControl <FieldControl>(control.ID, this) != null)
                    {
                        Controls.Remove(fc);
                    }
                    Controls.Add(UIHelper.GetControl(control));
                }
            }
        }