示例#1
0
        public async Task CheckAttachment <T>(int AttachmentTypeId, string ObjectID, AttachmentsViewModelWithEntityDto <T> input, AttachmentUploadType type)
        {
            var attachmentType = await _lookup_attachmentTypeRepository.GetAsync(AttachmentTypeId);

            if (attachmentType == null)
            {
                throw new UserFriendlyException(L("InvalidAttachmentTypeIdCode"), L("InvalidAttachmentTypeIdCode_Detail"));
            }

            if ((input.Attachments != null && input.Attachments.Count > 0) || (input.AttachmentsToDelete != null && input.AttachmentsToDelete.Count > 0))
            {
                var version       = 1;
                var numOfAttached = input.Attachments.Count;

                if (type == AttachmentUploadType.edit)
                {
                    var oldAttachments = await _attachmentFileRepository.GetAll().Where(e => e.ObjectId == ObjectID && e.AttachmentTypeId == AttachmentTypeId).OrderByDescending(e => e.Version).ToListAsync();

                    var anyAttachment = oldAttachments.FirstOrDefault();

                    if (anyAttachment != null)
                    {
                        var lastGroup = oldAttachments.Where(e => e.Version == anyAttachment.Version).ToList();

                        var tokensToDelete = new Dictionary <string, string>();
                        foreach (var item in input.AttachmentsToDelete)
                        {
                            if (!tokensToDelete.ContainsKey(item.FileToken))
                            {
                                tokensToDelete.Add(item.FileToken, item.FileToken);
                            }
                        }
                        version = anyAttachment.Version;

                        var notDeletedAttaches = lastGroup.Where(e => !tokensToDelete.ContainsKey(e.FileToken)).ToList();
                        var DeletedAttaches    = lastGroup.Where(e => tokensToDelete.ContainsKey(e.FileToken)).ToList();
                        if (notDeletedAttaches.Count != lastGroup.Count)
                        {
                            version = anyAttachment.Version + 1;

                            foreach (var att in notDeletedAttaches)
                            {
                                att.Version = version;
                            }
                        }
                        foreach (var item in DeletedAttaches)
                        {
                            await _attachmentFileRepository.DeleteAsync(item);
                        }
                        numOfAttached += notDeletedAttaches.Count;
                    }
                }

                if (numOfAttached > attachmentType.MaxAttachments)
                {
                    throw new UserFriendlyException(L("MaxAttachmentsCode"), L("MaxAttachmentsCode_Detail"));
                }
                var listAttachments = new List <UploadFilesInputDto>();
                foreach (var att in input.Attachments)
                {
                    var FileByte = _tempFileCacheManager.GetFile(att.FileToken);
                    if (FileByte == null)
                    {
                        throw new UserFriendlyException("There is no such image file with the token: " + att.FileToken);
                    }
                    CheckFileType(att.FileName, attachmentType);
                    if (attachmentType.MaxSize != 0 && FileByte.Length > attachmentType.MaxSize * 1000)
                    {
                        throw new UserFriendlyException(L("FileSizeNotAllowdCode"), L("FileSizeNotAllowdCode_Detail"));
                    }
                    var UploadFilesInputDto = ObjectMapper.Map <UploadFilesInputDto>(att);
                    UploadFilesInputDto.FileByte = FileByte;
                    UploadFilesInputDto.Version  = version;
                    listAttachments.Add(UploadFilesInputDto);
                }
                await AddAttachment(
                    attachmentType, ObjectID,
                    listAttachments
                    );
            }
            else
            {
                if (attachmentType.IsRequired)
                {
                    throw new UserFriendlyException(L("AttachmentNotFoundCode"), L("AttachmentNotFoundCode_Detail"));
                }
            }
        }
示例#2
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();
        }