FrmRemarkManage.cs 8.4 KB
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Comm;
using Dal;
using Microsoft.Office.Interop.Word;
using ZedGraph;
using Rectangle=System.Drawing.Rectangle;

namespace App
{
    public partial class FrmRemarkManage : App.FrmBase
    {
        private Remark _Remark;
        private List<Remark> _RemarkList;
        private List<Remark> _OldRemarkList;

        private RectangleF _Rectangle ;
        private PointF _StartPoint;

        private Color _fillColor;
        private string _text;
        Fuction fuction = new Fuction();
        private DataTable table1;
        private int nameIndex;

        public FrmRemarkManage(List<Remark> remarkList,RectangleF rectangle ,PointF startPoint)
        {
            _Rectangle = rectangle ;
            _StartPoint = startPoint;
            _OldRemarkList=new List<Remark>();
            _OldRemarkList.AddRange(remarkList);
            _RemarkList=remarkList;
            InitializeComponent();
            Init();
            this.SetLanguage(this);
        }
        private void Init()
        {
            table1 = new DataTable(Const.REMARK);
            DataColumnCollection columns = table1.Columns;
            columns.Add(Const.REMARK_NO, typeof(System.String));
            columns.Add(Const.REMARK_TEXT, typeof(System.String));
            columns.Add(Const.REMARK_FillColor, typeof(Color));
            columns.Add(Const.REMARK_LineColor, typeof(Color));
            columns.Add(Const.REMARK_RectangleX, typeof(System.String));
            columns.Add(Const.REMARK_RectangleY, typeof(System.String));
            columns.Add(Const.REMARK_RectangleWidth, typeof(System.String));
            columns.Add(Const.REMARK_RectangleHeight, typeof(System.String));
            columns.Add(Const.REMARK_StartPointX, typeof(System.String));
            columns.Add(Const.REMARK_StartPointY, typeof(System.String));
            BindDGLogin();
        }
        public List<Remark> RemarkList
        {
            get { return _RemarkList; }
        }
        private void BindDGLogin()
        {
            table1.Rows.Clear();
            DataRow dr;
            for (int i = 0; i < _RemarkList.Count; i++)
            {
                dr = table1.NewRow();
                dr[Const.REMARK_NO] = (i+1).ToString();
                dr[Const.REMARK_TEXT] = _RemarkList[i].Text;
                dr[Const.REMARK_FillColor] = _RemarkList[i].FillColor;
                dr[Const.REMARK_LineColor] = _RemarkList[i].LineColor;
                dr[Const.REMARK_RectangleX] = _RemarkList[i].Rectangle.X;
                dr[Const.REMARK_RectangleY] = _RemarkList[i].Rectangle.Y;
                dr[Const.REMARK_RectangleWidth] = _RemarkList[i].Rectangle.Width;
                dr[Const.REMARK_RectangleHeight] = _RemarkList[i].Rectangle.Height;
                dr[Const.REMARK_StartPointX] = _RemarkList[i].StartPoint.X;
                dr[Const.REMARK_StartPointY] = _RemarkList[i].StartPoint.Y;
                table1.Rows.Add(dr);
            }

            dg_Remark.DataSource = table1;

            DataGridViewCellStyle dataGridViewCellStyle0 = CreatDataGridViewCellStyle();
            dg_Remark.Columns[Const.REMARK_NO].DefaultCellStyle = dataGridViewCellStyle0;
            dg_Remark.Columns[Const.REMARK_NO].HeaderCell.Style.BackColor = Color.SkyBlue;
            dg_Remark.Columns[Const.REMARK_NO].SortMode = DataGridViewColumnSortMode.NotSortable;
            dg_Remark.Columns[Const.REMARK_NO].Width = (dg_Remark.Width - 20)/4;

            dg_Remark.Columns[Const.REMARK_TEXT].DefaultCellStyle = dataGridViewCellStyle0;
            dg_Remark.Columns[Const.REMARK_TEXT].HeaderCell.Style.BackColor = Color.SkyBlue;
            dg_Remark.Columns[Const.REMARK_TEXT].SortMode = DataGridViewColumnSortMode.NotSortable;
            dg_Remark.Columns[Const.REMARK_TEXT].Width = (dg_Remark.Width - 20)*3/4;

            dg_Remark.Columns[Const.REMARK_FillColor].Visible = false;
            dg_Remark.Columns[Const.REMARK_LineColor].Visible = false;
            dg_Remark.Columns[Const.REMARK_RectangleX].Visible = false;
            dg_Remark.Columns[Const.REMARK_RectangleY].Visible = false;
            dg_Remark.Columns[Const.REMARK_RectangleWidth].Visible = false;
            dg_Remark.Columns[Const.REMARK_RectangleHeight].Visible = false;
            dg_Remark.Columns[Const.REMARK_StartPointX].Visible = false;
            dg_Remark.Columns[Const.REMARK_StartPointY].Visible = false;


            if (table1.Rows.Count > 0)
            {
                nameIndex = 0;
                dg_Remark.Rows[nameIndex].Selected = true;
                ShowDetail(((DataTable) dg_Remark.DataSource).Rows[nameIndex]);
            }
        }

        private void dg_Remark_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                dg_Remark.Rows[e.RowIndex].Selected = true;
                nameIndex = e.RowIndex;

                ShowDetail(((DataTable) dg_Remark.DataSource).Rows[nameIndex]);
            }
        }

        private void ShowDetail(DataRow drRemark)
        {
            txt_Remark.Text = drRemark[Const.REMARK_TEXT].ToString();
            p_BackColor.BackColor = (Color)(drRemark[Const.REMARK_FillColor]);
            line.ForeColor = (Color)(drRemark[Const.REMARK_LineColor]);
        }

        private void btn_OK1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private DialogResult _DialogResult;

        private void btn_BackColor_Click(object sender, EventArgs e)
        {
            DialogResult result = colorDialog1.ShowDialog();
            if (result == DialogResult.OK)//保存ʼþÏìÓ¦
            {
                p_BackColor.BackColor = colorDialog1.Color;//»ñÈ¡»òÉèÖÃÓû§Ñ¡ÖеÄÑÕÉ«
            }

        }

        private void btn_ForColor_Click(object sender, EventArgs e)
        {
            DialogResult result = colorDialog1.ShowDialog();
            if (result == DialogResult.OK)//保存ʼþÏìÓ¦
            {
                line.ForeColor = colorDialog1.Color;//»ñÈ¡»òÉèÖÃÓû§Ñ¡ÖеÄÑÕÉ«
            }
        }

        private void btn_Add_Click(object sender, EventArgs e)
        {
            if (SameText(_RemarkList.Count + 1,txt_Remark.Text.Trim()))
            {
                ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.SAME_REMARK);
                return;
            }
            if (txt_Remark.Text.Length > 20 || txt_Remark.Text.Length==0)
            {
                ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.REMARK_LENGTH_WRONG);
                return;
            }
            _Rectangle.Width = txt_Remark.Text.Trim().Length*12;
            _Remark = new Remark(p_BackColor.BackColor, line.ForeColor, _Rectangle, _StartPoint, txt_Remark.Text.Trim());
            _RemarkList.Add(_Remark);
            BindDGLogin();
        }

        private bool SameText(int No, string text)
        {
            for (int i = 0; i < _RemarkList.Count; i++)
            {
                if (_RemarkList[i].Text == text && No != (i + 1))
                    return true;
            }
            return false;
        }

        private void btn_Update_Click(object sender, EventArgs e)
        {
            if (SameText(nameIndex + 1, txt_Remark.Text.Trim()))
            {
                ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.SAME_REMARK);
                return;
            }
            if (txt_Remark.Text.Length > 20 || txt_Remark.Text.Length == 0)
            {
                ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.REMARK_LENGTH_WRONG);
                return;
            }
            _Remark = new Remark(p_BackColor.BackColor, line.ForeColor,
                _RemarkList[nameIndex].Rectangle, _RemarkList[nameIndex].StartPoint, txt_Remark.Text.Trim());
            _RemarkList[nameIndex]=_Remark;
            BindDGLogin();
        }

        private void btn_Delete_Click(object sender, EventArgs e)
        {
            _RemarkList.RemoveAt(nameIndex);
            BindDGLogin();
        }

        private void btn_Cancel1_Click(object sender, EventArgs e)
        {
            _RemarkList = _OldRemarkList;
            this.Close();
        }

        private void btn_OK_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}