예제 #1
0
        private void bt_Upload_Click(object sender, EventArgs e)
        {
            OpenFileDialogForm ofd = new OpenFileDialogForm();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                foreach (var file in ofd.FileNames)
                {
                    if (!lv_Doc.Items.ContainsKey(Path.GetFileName(file)))
                    {
                        var tb = flp_DataField.Controls.Find("名称", true).FirstOrDefault();
                        if (tb != null && tb is TextBox)
                        {
                            TextBox box = tb as TextBox;
                            tb.Text = Path.GetFileName(file);
                        }
                        lv_Doc.Items.Add(new ListViewItem(Path.GetFileName(file))
                        {
                            Name = file
                        });
                    }
                }
                SaveDocList();
            }
        }
예제 #2
0
        private void bt_Upload_Click(object sender, EventArgs e)
        {
            OpenFileDialogForm ofd = new OpenFileDialogForm();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                foreach (var file in ofd.FileNames)
                {
                    if (!lv_Doc.Items.ContainsKey(Path.GetFileName(file)))
                    {
                        lv_Doc.Items.Add(new ListViewItem(Path.GetFileName(file))
                        {
                            Name = file
                        });
                    }
                    //else
                    //{
                    //    MessageBox.Show("文档已添加!");
                    //}
                }
                SaveDocList();
            }
        }
예제 #3
0
        private void bt_Upload_Click_1(object sender, EventArgs e)
        {
            OpenFileDialogForm ofd = new OpenFileDialogForm();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                foreach (var file in ofd.FileNames)
                {
                    lv_Doc.Items.Add(new ListViewItem(Path.GetFileName(file))
                    {
                        Name = file
                    });
                }
                int record = 0;
                if (int.TryParse(RecordID, out record))
                {
                    SaveDocList(record);
                }
                else
                {
                    SaveDocList();
                }
            }
        }
예제 #4
0
        /// <summary>
        /// 重新布局界面
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="table"></param>
        /// <param name="enable"></param>
        public bool CreateFromFieldTable(IFieldTable table, WorkingStateEnum workingState, bool uploadFile)
        {
            RecordID = table.GetFieldValue("ID");
            if (GoalTables.Contains(TableName) && workingState == WorkingStateEnum.View)
            {
                DataDetailFrom ddf = new DataDetailFrom(this.TableModeName)
                {
                    Text = bt_CreateDetail.Text, Name = this.TableName, DataID = RecordID
                };
                ddf.ShowDialog();
                this.DialogResult = DialogResult.OK;
                return(false);
            }
            TableName         = table.TableName;
            pictureBox1.Image = null;
            if (table == null)
            {
                return(false);
            }
            CurrentTable = table;
            lv_Doc.Items.Clear();
            if (uploadFile)
            {
                OpenFileDialogForm ofd = new OpenFileDialogForm();
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    foreach (var file in ofd.FileNames)
                    {
                        lv_Doc.Items.Add(new ListViewItem(Path.GetFileName(file))
                        {
                            Name = file
                        });
                    }
                }
                else
                {
                    this.DialogResult = DialogResult.Cancel;
                    return(false);
                }
            }
            var proList = workingState.GetType().GetField(workingState.ToString()).GetCustomAttributes(typeof(Exportable), false).FirstOrDefault();

            this.Text = proList != null?(proList as Exportable).Name.ToString():"";

            var fields = table.GetTableFields();

            tableLayoutPanel1.SuspendLayout();
            flp_DataField.SuspendLayout();
            if (fields.Where(f => !f.IsExtend).Select(f => f.Name).Any(f => flp_DataField.Controls.Find(f, true).Length == 0))
            {
                flp_DataField.Controls.Clear();
            }

            foreach (TableField field in fields)
            {
                if (field.IsExtend)
                {
                    if (field.Name == "ID" && field.Value != "")
                    {
                        var files = DBHelper.GetDBHelper().GetTableRecordDocList(table.TableName, field.Value);
                        if (files.Length > 0)
                        {
                            lv_Doc.Items.AddRange(files.Select(f => new ListViewItem(Path.GetFileName(f))
                            {
                                Name = f
                            }).ToArray());
                        }
                    }
                    continue;
                }
                AddTextField(flp_DataField, field);
            }
            flp_DataField.ResumeLayout(false);
            flp_DataField.PerformLayout();
            tableLayoutPanel1.ResumeLayout(false);
            tableLayoutPanel1.PerformLayout();
            return(true);
        }
예제 #5
0
        private void lv_Doc_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                ContextMenuStrip cms = new ContextMenuStrip();
                cms.ShowImageMargin  = false;
                cms.ShowCheckMargin  = false;
                cms.ShowItemToolTips = false;
                cms.Font             = this.Font;

                if (lv_Doc.GetItemAt(e.X, e.Y) != null)
                {
                    ToolStripButton itemDel = new ToolStripButton();
                    itemDel.Text   = "文档删除";
                    itemDel.Click += (obj, ee) =>
                    {
                        if (MessageBox.Show("您确认要删除选择的文件吗?", "确认", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            ListViewItem item = lv_Doc.GetItemAt(e.X, e.Y);
                            if (item != null)
                            {
                                lv_Doc.Items.Remove(item);
                                int record = 0;
                                if (int.TryParse(RecordID, out record))
                                {
                                    SaveDocList(record);
                                }
                                else
                                {
                                    SaveDocList();
                                }
                            }
                        }
                    };
                    cms.Items.Add(itemDel);

                    ToolStripButton itemOpen = new ToolStripButton();
                    itemOpen.Text   = "文档打开";
                    itemOpen.Click += (obj, ee) =>
                    {
                        string filePath = Path.GetTempPath() + lv_Doc.SelectedItems[0].Text;
                        if (!File.Exists(filePath))
                        {
                            filePath = DBHelper.GetDBHelper().GetDocFromTableRecord(
                                this.TableName,
                                RecordID,
                                lv_Doc.SelectedItems[0].Text);
                        }
                        if (filePath != "")
                        {
                            new DocumentViewwerForm(filePath).ShowDialog();                 //打开此文件。
                        }
                    };
                    cms.Items.Add(itemOpen);
                }
                else
                {
                    ToolStripButton itemUpload = new ToolStripButton();
                    itemUpload.Text   = "文档上传";
                    itemUpload.Click += (obj, ee) =>
                    {
                        OpenFileDialogForm ofd = new OpenFileDialogForm();
                        if (ofd.ShowDialog() == DialogResult.OK)
                        {
                            foreach (var file in ofd.FileNames)
                            {
                                lv_Doc.Items.Add(new ListViewItem(Path.GetFileName(file))
                                {
                                    Name = file
                                });
                            }
                            int record = 0;
                            if (int.TryParse(RecordID, out record))
                            {
                                SaveDocList(record);
                            }
                            else
                            {
                                SaveDocList();
                            }
                        }
                    };
                    cms.Items.Add(itemUpload);
                }
                cms.Show(lv_Doc, e.Location);
            }
        }
예제 #6
0
        private void AddTextField(FlowLayoutPanel flp, TableField field, bool bSearch = false)
        {
            var lable   = flp.Controls.Find("lb_" + field.Name, true).FirstOrDefault();
            var textBox = flp.Controls.Find(field.Name, true).FirstOrDefault();

            if (textBox == null)
            {
                TableLayoutPanel tlp = GetTableLayout();
                Label            lb  = new Label()
                {
                    Text        = field.Name,
                    Name        = "lb_" + field.Name,
                    AutoSize    = true,
                    MaximumSize = new Size(120, 0),
                    Anchor      = AnchorStyles.Right,
                    Margin      = new Padding(0, 3, 0, 3)
                };
                Control valueBox;
                if (field.Type == "smalldatetime" || field.Type == "date")
                {
                    valueBox = new DateTimePicker()
                    {
                        Name         = field.Name,
                        Anchor       = AnchorStyles.Left,
                        Margin       = new Padding(0, 3, 0, 3),
                        Format       = DateTimePickerFormat.Custom,
                        CustomFormat = "yyyy-MM-dd",
                        Width        = 84
                    };
                }
                else if (field.Type == "image")
                {
                    PictureBox pb = new PictureBox();
                    pb.Click += (sender, e) =>
                    {
                        OpenFileDialogForm ofd = new OpenFileDialogForm();
                        if (ofd.ShowDialog() == DialogResult.OK)
                        {
                            pb.Image = Image.FromFile(ofd.FileNames.FirstOrDefault());
                        }
                        ;
                    };
                    valueBox = pb;
                }
                else
                {
                    valueBox = new TextBox()
                    {
                        Name   = field.Name,
                        Anchor = AnchorStyles.Left,
                        Margin = new Padding(0, 3, 0, 3),
                    };
                    CreateTextBox(flp_DataField, field, valueBox);
                }
                if (field.Value != "" && !bSearch)
                {
                    valueBox.Text = field.Value;
                    lb.ForeColor  = Color.Black;
                }
                else
                {
                    if (field.NoNull)
                    {
                        lb.ForeColor = Color.Red;
                    }
                }


                tlp.Controls.Add(lb, 0, 0);
                tlp.Controls.Add(valueBox, 1, 0);
                flp.Controls.Add(tlp);
            }
            else if (!bSearch)
            {
                textBox.Text = field.Value;
                if (field.NoNull)
                {
                    lable.ForeColor = Color.Red;
                }
                else
                {
                    lable.ForeColor = Color.Black;
                }
            }
        }
예제 #7
0
        /// <summary>
        /// 重新布局界面
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="table"></param>
        /// <param name="enable"></param>
        public bool CreateFromFieldTable(IFieldTable table, WorkingStateEnum workingState, bool uploadFile)
        {
            TableName         = table.TableName;
            pictureBox1.Image = null;
            if (table == null)
            {
                return(false);
            }
            CurrentTable = table;
            lv_Doc.Items.Clear();
            if (uploadFile)
            {
                OpenFileDialogForm ofd = new OpenFileDialogForm();
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    foreach (var file in ofd.FileNames)
                    {
                        lv_Doc.Items.Add(new ListViewItem(Path.GetFileName(file))
                        {
                            Name = file
                        });
                    }
                }
                else
                {
                    this.DialogResult = DialogResult.Cancel;
                    return(false);
                }
            }
            var proList = workingState.GetType().GetField(workingState.ToString()).GetCustomAttributes(typeof(Exportable), false).FirstOrDefault();

            this.Text = proList != null?(proList as Exportable).Name.ToString():"";

            var fields = table.GetTableFields();

            tableLayoutPanel1.SuspendLayout();
            DataTable     dt     = new DataTable();
            List <string> values = new List <string>();

            dt.Columns.AddRange(fields.Where(f => !f.IsExtend || f.Name != "ID").Select(f => new DataColumn(f.Name)).ToArray());
            dt.Rows.Add(fields.Where(f => !f.IsExtend || f.Name != "ID").Select(f => f.Value).ToArray());
            string id = fields.Where(f => f.Name == "ID").Select(f => f.Value).FirstOrDefault();

            this.reportViewer1.LocalReport.DataSources.Clear();
            this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", dt));

            this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet2", GetImages(id)));
            this.reportViewer1.RefreshReport();
            foreach (TableField field in fields)
            {
                if (field.IsExtend)
                {
                    if (field.Name == "ID" && field.Value != "")
                    {
                        RecordID = field.Value;
                        var files = DBHelper.GetDBHelper().GetTableRecordDocList(table.TableName, field.Value);
                        if (files.Length > 0)
                        {
                            lv_Doc.Items.AddRange(files.Select(f => new ListViewItem(Path.GetFileName(f))
                            {
                                Name = f
                            }).ToArray());
                        }
                        break;
                    }
                }
            }
            tableLayoutPanel1.ResumeLayout(false);
            tableLayoutPanel1.PerformLayout();
            return(true);
        }