Beispiel #1
0
        /// <summary>
        /// 绑定表单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void BindFrm(object sender, FF.GenerWorkNodeCompletedEventArgs e)
        {
            #region 初始化数据.
            this.canvasMain.Children.Clear();
            this.FrmDS = new DataSet();
            try
            {
                if (e.Result.Length < 200)
                {
                    throw new Exception(e.Result);
                }
                this.FrmDS.FromXml(e.Result);
                loadingWindow.DialogResult = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Err", MessageBoxButton.OK);
                loadingWindow.DialogResult = true;
                return;
            }
            #endregion 初始化数据.

            this.InitToolbar();

            string table = "";
            try
            {
                this.dtMapAttrs = this.FrmDS.Tables["Sys_MapAttr"];
                foreach (DataTable dt in this.FrmDS.Tables)
                {
                    Glo.TempVal = dt.TableName;
                    table       = dt.TableName;
                    switch (dt.TableName)
                    {
                    case "Sys_MapAttr":
                        foreach (DataRow dr in dt.Rows)
                        {
                            if (dr["UIVisible"] == "0")
                            {
                                continue;
                            }

                            if (dr["FK_MapData"] != Glo.FK_MapData)
                            {
                                continue;
                            }

                            string myPk          = dr["MyPK"];
                            string FK_MapData    = dr["FK_MapData"];
                            string keyOfEn       = dr["KeyOfEn"];
                            string name          = dr["Name"];
                            string defVal        = dr["DefVal"];
                            string UIContralType = dr["UIContralType"];
                            string MyDataType    = dr["MyDataType"];
                            string lgType        = dr["LGType"];
                            bool   isEnable      = false;
                            if (dr["UIIsEnable"].ToString() == "1")
                            {
                                isEnable = true;
                            }

                            double X = double.Parse(dr["X"]);
                            double Y = double.Parse(dr["Y"]);
                            if (X == 0)
                            {
                                X = 100;
                            }
                            if (Y == 0)
                            {
                                Y = 100;
                            }

                            string UIBindKey = dr["UIBindKey"];
                            switch (UIContralType)
                            {
                            case CtrlType.TextBox:
                                TBType tp = TBType.String;
                                switch (MyDataType)
                                {
                                case DataType.AppInt:
                                    tp = TBType.Int;
                                    break;

                                case DataType.AppFloat:
                                case DataType.AppDouble:
                                    tp = TBType.Float;
                                    break;

                                case DataType.AppMoney:
                                    tp = TBType.Money;
                                    break;

                                case DataType.AppString:
                                    tp = TBType.String;
                                    break;

                                case DataType.AppDateTime:
                                    tp = TBType.DateTime;
                                    break;

                                case DataType.AppDate:
                                    tp = TBType.Date;
                                    break;

                                default:
                                    break;
                                }

                                BPTextBox tb = new BPTextBox(tp);
                                tb.NameOfReal = keyOfEn;
                                tb.Name       = keyOfEn;
                                tb.SetValue(Canvas.LeftProperty, X);
                                tb.SetValue(Canvas.TopProperty, Y);

                                tb.Text  = this.GetValByKey(keyOfEn);        //给控件赋值.
                                tb.Width = double.Parse(dr["UIWidth"]);

                                if (tb.Height > 24)
                                {
                                    tb.TextWrapping = TextWrapping.Wrap;
                                }

                                tb.Height = double.Parse(dr["UIHeight"]);

                                if (isEnable)
                                {
                                    tb.IsEnabled = true;
                                }
                                else
                                {
                                    tb.IsEnabled = false;
                                }
                                this.canvasMain.Children.Add(tb);
                                break;

                            case CtrlType.DDL:
                                BPDDL ddl = new BPDDL();
                                ddl.Name      = keyOfEn;
                                ddl.HisLGType = lgType;
                                ddl.Width     = double.Parse(dr["UIWidth"]);
                                ddl.UIBindKey = UIBindKey;
                                ddl.HisLGType = lgType;
                                if (lgType == LGType.Enum)
                                {
                                    DataTable dtEnum = this.FrmDS.Tables["Sys_Enum"];
                                    foreach (DataRow drEnum in dtEnum.Rows)
                                    {
                                        if (drEnum["EnumKey"].ToString() != UIBindKey)
                                        {
                                            continue;
                                        }

                                        ListBoxItem li = new ListBoxItem();
                                        li.Tag     = drEnum["IntKey"].ToString();
                                        li.Content = drEnum["Lab"].ToString();
                                        ddl.Items.Add(li);
                                    }
                                    if (ddl.Items.Count == 0)
                                    {
                                        throw new Exception("@没有从Sys_Enum中找到编号为(" + UIBindKey + ")的枚举值。");
                                    }
                                }
                                else
                                {
                                    ddl.BindEns(UIBindKey);
                                }

                                ddl.SetValue(Canvas.LeftProperty, X);
                                ddl.SetValue(Canvas.TopProperty, Y);

                                //给控件赋值.
                                ddl.SetSelectVal(this.GetValByKey(keyOfEn));

                                this.canvasMain.Children.Add(ddl);
                                break;

                            case CtrlType.CheckBox:
                                BPCheckBox cb = new BPCheckBox();
                                cb.Name    = keyOfEn;
                                cb.Content = name;

                                Label cbLab = new Label();
                                cbLab.Name    = "CBLab" + cb.Name;
                                cbLab.Content = name;
                                cbLab.Tag     = keyOfEn;
                                cb.Content    = cbLab;

                                cb.SetValue(Canvas.LeftProperty, X);
                                cb.SetValue(Canvas.TopProperty, Y);

                                if (this.GetValByKey(keyOfEn) == "1")
                                {
                                    cb.IsChecked = true;
                                }
                                else
                                {
                                    cb.IsChecked = false;
                                }
                                this.canvasMain.Children.Add(cb);
                                break;

                            case CtrlType.RB:
                                break;

                            default:
                                break;
                            }
                        }
                        continue;

                    case "Sys_FrmRB":
                        DataTable dtRB = this.FrmDS.Tables["Sys_FrmRB"];
                        foreach (DataRow dr in dtRB.Rows)
                        {
                            if (dr["FK_MapData"] != Glo.FK_MapData)
                            {
                                continue;
                            }

                            BPRadioBtn btn = new BPRadioBtn();
                            btn.Name      = dr["MyPK"];
                            btn.GroupName = dr["KeyOfEn"];
                            btn.Content   = dr["Lab"];
                            btn.UIBindKey = dr["EnumKey"];
                            btn.Tag       = dr["IntKey"];
                            btn.SetValue(Canvas.LeftProperty, double.Parse(dr["X"].ToString()));
                            btn.SetValue(Canvas.TopProperty, double.Parse(dr["Y"].ToString()));
                            this.canvasMain.Children.Add(btn);
                        }
                        continue;

                    case "Sys_MapDtl":
                        foreach (DataRow dr in dt.Rows)
                        {
                            BPDtl dtl = new BPDtl(dr["No"], this.FrmDS);
                            dtl.SetValue(Canvas.LeftProperty, double.Parse(dr["X"]));
                            dtl.SetValue(Canvas.TopProperty, double.Parse(dr["Y"]));
                            dtl.Width  = double.Parse(dr["W"]);
                            dtl.Height = double.Parse(dr["H"]);
                            this.canvasMain.Children.Add(dtl);
                        }
                        continue;

                    case "Sys_FrmEle":
                        foreach (DataRow dr in dt.Rows)
                        {
                            if (dr["FK_MapData"] != Glo.FK_MapData)
                            {
                                continue;
                            }

                            BPEle img = new BPEle();
                            img.Name    = dr["MyPK"].ToString();
                            img.EleType = dr["EleType"].ToString();
                            img.EleName = dr["EleName"].ToString();
                            img.EleID   = dr["EleID"].ToString();

                            img.Cursor = Cursors.Hand;
                            img.SetValue(Canvas.LeftProperty, double.Parse(dr["X"].ToString()));
                            img.SetValue(Canvas.TopProperty, double.Parse(dr["Y"].ToString()));

                            img.Width  = double.Parse(dr["W"].ToString());
                            img.Height = double.Parse(dr["H"].ToString());
                            this.canvasMain.Children.Add(img);
                        }
                        continue;

                    case "Sys_MapData":
                        if (dt.Rows.Count == 0)
                        {
                            continue;
                        }
                        foreach (DataRow dr in dt.Rows)
                        {
                            if (dr["No"] != Glo.FK_MapData)
                            {
                                continue;
                            }

                            Glo.HisMapData      = new MapData();
                            Glo.HisMapData.FrmH = double.Parse(dt.Rows[0]["FrmH"]);
                            Glo.HisMapData.FrmW = double.Parse(dt.Rows[0]["FrmW"]);
                            Glo.HisMapData.No   = (string)dt.Rows[0]["No"];
                            Glo.HisMapData.Name = (string)dt.Rows[0]["Name"];
                            // Glo.IsDtlFrm = false;
                            this.canvasMain.Width    = Glo.HisMapData.FrmW;
                            this.canvasMain.Height   = Glo.HisMapData.FrmH;
                            this.scrollViewer1.Width = Glo.HisMapData.FrmW;
                        }
                        break;

                    case "Sys_FrmBtn":
                        foreach (DataRow dr in dt.Rows)
                        {
                            if (dr["FK_MapData"] != Glo.FK_MapData)
                            {
                                continue;
                            }

                            BPBtn btn = new BPBtn();
                            btn.Name         = dr["MyPK"];
                            btn.Content      = dr["Text"].Replace("&nbsp;", " ");
                            btn.HisBtnType   = (BtnType)int.Parse(dr["BtnType"]);
                            btn.HisEventType = (EventType)int.Parse(dr["EventType"]);

                            if (dr["EventContext"] != null)
                            {
                                btn.EventContext = dr["EventContext"].Replace("~", "'");
                            }

                            if (dr["MsgErr"] != null)
                            {
                                btn.MsgErr = dr["MsgErr"].Replace("~", "'");
                            }

                            if (dr["MsgOK"] != null)
                            {
                                btn.MsgOK = dr["MsgOK"].Replace("~", "'");
                            }

                            btn.SetValue(Canvas.LeftProperty, double.Parse(dr["X"]));
                            btn.SetValue(Canvas.TopProperty, double.Parse(dr["Y"]));
                            this.canvasMain.Children.Add(btn);
                        }
                        continue;

                    case "Sys_FrmLine":
                        foreach (DataRow dr in dt.Rows)
                        {
                            if (dr["FK_MapData"] != Glo.FK_MapData)
                            {
                                continue;
                            }

                            string color = dr["BorderColor"];
                            if (string.IsNullOrEmpty(color))
                            {
                                color = "Black";
                            }

                            BPLine myline = new BPLine(dr["MyPK"], color, double.Parse(dr["BorderWidth"]),
                                                       double.Parse(dr["X1"]), double.Parse(dr["Y1"]), double.Parse(dr["X2"]),
                                                       double.Parse(dr["Y2"]));

                            myline.SetValue(Canvas.LeftProperty, double.Parse(dr["X"]));
                            myline.SetValue(Canvas.TopProperty, double.Parse(dr["Y"]));
                            this.canvasMain.Children.Add(myline);
                        }
                        continue;

                    case "Sys_FrmLab":
                        foreach (DataRow dr in dt.Rows)
                        {
                            if (dr["FK_MapData"] != Glo.FK_MapData)
                            {
                                continue;
                            }

                            BPLabel lab = new BPLabel();
                            lab.Name = dr["MyPK"];
                            string text = dr["Text"].Replace("&nbsp;", " ");
                            text         = text.Replace("@", "\n");
                            lab.Content  = text;
                            lab.FontSize = double.Parse(dr["FontSize"]);
                            lab.Cursor   = Cursors.Hand;
                            lab.SetValue(Canvas.LeftProperty, double.Parse(dr["X"]));
                            lab.SetValue(Canvas.TopProperty, double.Parse(dr["Y"]));

                            if (dr["IsBold"] == "1")
                            {
                                lab.FontWeight = FontWeights.Bold;
                            }
                            else
                            {
                                lab.FontWeight = FontWeights.Normal;
                            }

                            string color = dr["FontColor"];
                            lab.Foreground = new SolidColorBrush(Glo.ToColor(color));
                            this.canvasMain.Children.Add(lab);
                        }
                        continue;

                    case "Sys_FrmLink":
                        foreach (DataRow dr in dt.Rows)
                        {
                            if (dr["FK_MapData"] != Glo.FK_MapData)
                            {
                                continue;
                            }

                            BPLink link = new BPLink();
                            link.Name    = dr["MyPK"];
                            link.Content = dr["Text"];
                            link.URL     = dr["URL"];

                            link.WinTarget = dr["Target"];

                            link.FontSize = double.Parse(dr["FontSize"]);
                            link.Cursor   = Cursors.Hand;
                            link.SetValue(Canvas.LeftProperty, double.Parse(dr["X"]));
                            link.SetValue(Canvas.TopProperty, double.Parse(dr["Y"]));

                            string color = dr["FontColor"];
                            if (string.IsNullOrEmpty(color))
                            {
                                color = "Black";
                            }

                            link.Foreground = new SolidColorBrush(Glo.ToColor(color));
                            this.canvasMain.Children.Add(link);
                        }
                        continue;

                    case "Sys_FrmImg":
                        foreach (DataRow dr in dt.Rows)
                        {
                            if (dr["FK_MapData"] != Glo.FK_MapData)
                            {
                                continue;
                            }

                            BPImg img = new BPImg();
                            img.Name   = dr["MyPK"];
                            img.Cursor = Cursors.Hand;
                            img.SetValue(Canvas.LeftProperty, double.Parse(dr["X"].ToString()));
                            img.SetValue(Canvas.TopProperty, double.Parse(dr["Y"].ToString()));

                            img.Width  = double.Parse(dr["W"].ToString());
                            img.Height = double.Parse(dr["H"].ToString());
                            this.canvasMain.Children.Add(img);
                        }
                        continue;

                    case "Sys_FrmImgAth":
                        foreach (DataRow dr in dt.Rows)
                        {
                            if (dr["FK_MapData"] != Glo.FK_MapData)
                            {
                                continue;
                            }

                            BPImgAth ath = new BPImgAth();
                            ath.Name   = dr["MyPK"];
                            ath.Cursor = Cursors.Hand;
                            ath.SetValue(Canvas.LeftProperty, double.Parse(dr["X"].ToString()));
                            ath.SetValue(Canvas.TopProperty, double.Parse(dr["Y"].ToString()));

                            ath.Height = double.Parse(dr["H"].ToString());
                            ath.Width  = double.Parse(dr["W"].ToString());
                            this.canvasMain.Children.Add(ath);
                        }
                        continue;

                    case "Sys_MapM2M":
                        foreach (DataRow dr in dt.Rows)
                        {
                            if (dr["FK_MapData"] != Glo.FK_MapData)
                            {
                                continue;
                            }

                            BPM2M m2m = new BPM2M(dr["NoOfObj"]);
                            m2m.SetValue(Canvas.LeftProperty, double.Parse(dr["X"]));
                            m2m.SetValue(Canvas.TopProperty, double.Parse(dr["Y"]));

                            m2m.Width  = double.Parse(dr["W"]);
                            m2m.Height = double.Parse(dr["H"]);
                            this.canvasMain.Children.Add(m2m);
                        }
                        continue;

                    case "Sys_FrmAttachment":
                        foreach (DataRow dr in dt.Rows)
                        {
                            if (dr["FK_MapData"] != Glo.FK_MapData)
                            {
                                continue;
                            }

                            string uploadTypeInt = dr["UploadType"].ToString();
                            if (uploadTypeInt == null)
                            {
                                uploadTypeInt = "0";
                            }

                            AttachmentUploadType uploadType = (AttachmentUploadType)int.Parse(uploadTypeInt);
                            if (uploadType == AttachmentUploadType.Single)
                            {
                                BPAttachment ath = new BPAttachment(dr["NoOfObj"],
                                                                    dr["Name"], dr["Exts"],
                                                                    double.Parse(dr["W"]), dr["SaveTo"].ToString());

                                ath.SetValue(Canvas.LeftProperty, double.Parse(dr["X"]));
                                ath.SetValue(Canvas.TopProperty, double.Parse(dr["Y"]));

                                ath.Label  = dr["Name"] as string;
                                ath.Exts   = dr["Exts"] as string;
                                ath.SaveTo = dr["SaveTo"] as string;

                                ath.X = double.Parse(dr["X"]);
                                ath.Y = double.Parse(dr["Y"]);

                                if (dr["IsUpload"] == "1")
                                {
                                    ath.IsUpload = true;
                                }
                                else
                                {
                                    ath.IsUpload = false;
                                }

                                if (dr["IsDelete"] == "1")
                                {
                                    ath.IsDelete = true;
                                }
                                else
                                {
                                    ath.IsDelete = false;
                                }

                                if (dr["IsDownload"] == "1")
                                {
                                    ath.IsDownload = true;
                                }
                                else
                                {
                                    ath.IsDownload = false;
                                }

                                this.canvasMain.Children.Add(ath);
                                continue;
                            }

                            if (uploadType == AttachmentUploadType.Multi)
                            {
                                BPAttachmentM athM = new BPAttachmentM();
                                athM.SetValue(Canvas.LeftProperty, double.Parse(dr["X"]));
                                athM.SetValue(Canvas.TopProperty, double.Parse(dr["Y"]));
                                athM.Name   = dr["NoOfObj"];
                                athM.Width  = double.Parse(dr["W"]);
                                athM.Height = double.Parse(dr["H"]);
                                athM.X      = double.Parse(dr["X"]);
                                athM.Y      = double.Parse(dr["Y"]);
                                athM.SaveTo = dr["SaveTo"];
                                athM.Text   = dr["Name"];
                                athM.Label  = dr["Name"];
                                this.canvasMain.Children.Add(athM);
                                continue;
                            }
                        }
                        continue;

                    default:
                        break;
                    }
                }
                loadingWindow.DialogResult = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("err:" + table, ex.Message + " " + ex.StackTrace,
                                MessageBoxButton.OK);
            }
            this.SetGridLines();
        }
Beispiel #2
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            e.Handled = true;
            // 获取 textBox 对象的相对于 Canvas 的 x坐标 和 y坐标
            double x = (double)this.GetValue(Canvas.LeftProperty);
            double y = (double)this.GetValue(Canvas.TopProperty);

            // KeyEventArgs.Key - 与事件相关的键盘的按键 [System.Windows.Input.Key枚举]
            switch (e.Key)
            {
            // 按 Up 键后 textBox 对象向 上 移动 1 个像素
            // Up 键所对应的 e.PlatformKeyCode == 38
            // 当获得的 e.Key == Key.Unknown 时,可以使用 e.PlatformKeyCode 来确定用户所按的键
            case Key.Up:
                this.SetValue(Canvas.TopProperty, y - 1);
                break;

            // 按 Down 键后 textBox 对象向 下 移动 1 个像素
            // Down 键所对应的 e.PlatformKeyCode == 40
            case Key.Down:
                this.SetValue(Canvas.TopProperty, y + 1);
                break;

            // 按 Left 键后 textBox 对象向 左 移动 1 个像素
            // Left 键所对应的 e.PlatformKeyCode == 37
            case Key.Left:
                this.SetValue(Canvas.LeftProperty, x - 1);
                break;

            // 按 Right 键后 textBox 对象向 右 移动 1 个像素
            // Right 键所对应的 e.PlatformKeyCode == 39
            case Key.Right:
                this.SetValue(Canvas.LeftProperty, x + 1);
                break;

            case Key.Delete:
                if (this.Name.Contains("_blank_") == false)
                {
                    if (MessageBox.Show("您确定要删除吗?",
                                        "删除提示", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                    {
                        return;
                    }
                }
                Canvas c = this.Parent as Canvas;
                c.Children.Remove(this);
                break;

            case Key.C:
                break;

            case Key.V:
                if (Keyboard.Modifiers == ModifierKeys.Control)
                {
                    BPAttachment tb = new BPAttachment();
                    tb.Cursor = Cursors.Hand;
                    tb.SetValue(Canvas.LeftProperty, (double)this.GetValue(Canvas.LeftProperty) + 15);
                    tb.SetValue(Canvas.TopProperty, (double)this.GetValue(Canvas.TopProperty) + 15);
                    Canvas s1c = this.Parent as Canvas;
                    try
                    {
                        s1c.Children.Add(tb);
                    }
                    catch
                    {
                        s1c.Children.Remove(tb);
                    }
                }
                break;

            default:
                break;
            }
            base.OnKeyDown(e);
        }