| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594 |
-
- using System.Data;
- using System.Drawing;
- using System.Windows.Forms;
- namespace Dongke.WinForm.Controls.InvoiceLayout
- {
- internal partial class GridItemSetting : Setting
- {
- #region 成员变量
- private bool _isTransparent = false; // 背景是否透明
- private Color _fillColor = Color.Black; // 背景颜色
- private bool _isColChanged = false;
- #endregion 成员变量
- #region 属性
- /// <summary>
- /// 列属性是否改变
- /// </summary>
- public bool ColumnsChanged
- {
- get
- {
- return _isColChanged;
- }
- }
- /// <summary>
- /// X(mm)
- /// </summary>
- public float ShapeLocationX
- {
- get
- {
- return System.Convert.ToSingle(numLoctionX.Value);
- }
- set
- {
- decimal d = System.Convert.ToDecimal(value);
- if (d < numLoctionX.Minimum)
- {
- d = numLoctionX.Minimum;
- }
- else if (numLoctionX.Maximum < d)
- {
- d = numLoctionX.Maximum;
- }
- numLoctionX.Value = d;
- }
- }
- /// <summary>
- /// Y(mm)
- /// </summary>
- public float ShapeLocationY
- {
- get
- {
- return System.Convert.ToSingle(numLoctionY.Value);
- }
- set
- {
- decimal d = System.Convert.ToDecimal(value);
- if (d < numLoctionY.Minimum)
- {
- d = numLoctionY.Minimum;
- }
- else if (numLoctionY.Maximum < d)
- {
- d = numLoctionY.Maximum;
- }
- numLoctionY.Value = d;
- }
- }
- /// <summary>
- /// 宽(mm)
- /// </summary>
- public float ShapeWidth
- {
- get
- {
- return System.Convert.ToSingle(numWidth.Value);
- }
- set
- {
- decimal d = System.Convert.ToDecimal(value);
- if (d < numWidth.Minimum)
- {
- d = numWidth.Minimum;
- }
- else if (numWidth.Maximum < d)
- {
- d = numWidth.Maximum;
- }
- numWidth.Value = d;
- }
- }
- /// <summary>
- /// 高(mm)
- /// </summary>
- public float ShapeHeight
- {
- get
- {
- return System.Convert.ToSingle(numHeight.Value);
- }
- set
- {
- decimal d = System.Convert.ToDecimal(value);
- if (d < numHeight.Minimum)
- {
- d = numHeight.Minimum;
- }
- else if (numHeight.Maximum < d)
- {
- d = numHeight.Maximum;
- }
- numHeight.Value = d;
- }
- }
- /// <summary>
- /// 列头行高
- /// </summary>
- public float HeadRowsHeight
- {
- get
- {
- return System.Convert.ToSingle(numHeadRowsHeight.Value);
- }
- set
- {
- decimal d = System.Convert.ToDecimal(value);
- if (d < numHeadRowsHeight.Minimum)
- {
- d = numHeadRowsHeight.Minimum;
- }
- else if (numHeadRowsHeight.Maximum < d)
- {
- d = numHeadRowsHeight.Maximum;
- }
- numHeadRowsHeight.Value = d;
- }
- }
- /// <summary>
- /// 线的颜色
- /// </summary>
- public Color LineColor
- {
- get
- {
- return lblLineColor.BackColor;
- }
- set
- {
- lblLineColor.BackColor = value;
- if (lblLineColor.BackColor != Color.White)
- {
- lblLineBColor.BackColor = lblLineColor.BackColor;
- }
- else
- {
- lblLineBColor.BackColor = Color.Black;
- }
- }
- }
- /// <summary>
- /// 背景颜色
- /// </summary>
- public Color FillColor
- {
- get
- {
- return _fillColor;
- }
- set
- {
- _fillColor = value;
- SetFillColor();
- }
- }
- /// <summary>
- /// 线宽
- /// </summary>
- public float LineWidth
- {
- get
- {
- return System.Convert.ToSingle(numLineWidth.Value);
- }
- set
- {
- decimal d = System.Convert.ToDecimal(value);
- if (d < numLineWidth.Minimum)
- {
- d = numLineWidth.Minimum;
- }
- else if (numLineWidth.Maximum < d)
- {
- d = numLineWidth.Maximum;
- }
- numLineWidth.Value = d;
- }
- }
- /// <summary>
- /// 背景是否透明
- /// </summary>
- public bool Transparent
- {
- get
- {
- return _isTransparent;
- }
- set
- {
- _isTransparent = value;
- SetFillColor();
- }
- }
- /// <summary>
- /// 是否显示列标题
- /// </summary>
- public bool TitleVisible
- {
- get
- {
- return cbxTitleVisible.Checked;
- }
- set
- {
- cbxTitleVisible.Checked = value;
- }
- }
- /// <summary>
- /// 是否每页都显示列标题
- /// </summary>
- public bool AlwaysTitleVisible
- {
- get
- {
- return cbxAlwaysTitleVisible.Checked;
- }
- set
- {
- cbxAlwaysTitleVisible.Checked = value;
- }
- }
- /// <summary>
- /// 行高
- /// </summary>
- public float RowsHeight
- {
- get
- {
- return System.Convert.ToSingle(numRowsHeight.Value);
- }
- set
- {
- decimal d = System.Convert.ToDecimal(value);
- if (d < numRowsHeight.Minimum)
- {
- d = numRowsHeight.Minimum;
- }
- else if (numRowsHeight.Maximum < d)
- {
- d = numRowsHeight.Maximum;
- }
- numRowsHeight.Value = d;
- }
- }
- /// <summary>
- /// 一页显示的行数
- /// </summary>
- public int RowsCount
- {
- get
- {
- return System.Convert.ToInt32(numRowsCount.Value);
- }
- set
- {
- decimal d = System.Convert.ToDecimal(value);
- if (d < numRowsCount.Minimum)
- {
- d = numRowsCount.Minimum;
- }
- else if (numRowsCount.Maximum < d)
- {
- d = numRowsCount.Maximum;
- }
- numRowsCount.Value = d;
- }
- }
- public GridItemColumnCollection Columns
- {
- get;
- set;
- }
- #endregion 属性
- #region 构造函数
- /// <summary>
- /// 构造函数
- /// </summary>
- public GridItemSetting()
- {
- InitializeComponent();
- }
- #endregion 构造函数
- #region 函数
- /// <summary>
- /// 设置背景颜色
- /// </summary>
- private void SetFillColor()
- {
- if (_isTransparent)
- {
- lblFillColor.BackColor = Color.Empty;
- lblFillBColor.BackColor = Color.Empty;
- }
- else
- {
- lblFillColor.BackColor = _fillColor;
- if (_fillColor != Color.White)
- {
- lblFillBColor.BackColor = _fillColor;
- }
- else
- {
- lblFillBColor.BackColor = Color.Black;
- }
- }
- }
- #endregion 函数
- #region 事件处理
- /// <summary>
- /// Shown
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void GridItemSetting_Shown(object sender, System.EventArgs e)
- {
- this.lisCols.DisplayMember = GridItemColumnCollection.DisplayMember;
- this.lisCols.DataSource = Columns;
- }
- /// <summary>
- /// 设置线的颜色
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void btnSelectLineColor_Click(object sender, System.EventArgs e)
- {
- colorDialog.Color = (lblLineColor.BackColor == Color.Transparent) ? Color.Empty : lblLineColor.BackColor;
- if (colorDialog.ShowDialog() == DialogResult.OK)
- {
- LineColor = colorDialog.Color;
- }
- }
- /// <summary>
- /// 设置背景颜色
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void btnSelectFillColor_Click(object sender, System.EventArgs e)
- {
- colorDialog.Color = _isTransparent ? Color.Empty : _fillColor;
- if (colorDialog.ShowDialog() == DialogResult.OK)
- {
- _fillColor = colorDialog.Color;
- Transparent = false;
- }
- }
- /// <summary>
- /// 设置线段是否透明
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void btnSelectLineTransparent_Click(object sender, System.EventArgs e)
- {
- lblLineColor.BackColor = Color.Transparent;
- lblLineBColor.BackColor = Color.Transparent;
- }
- /// <summary>
- /// 设置背景是否透明
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void btnFillTransparent_Click(object sender, System.EventArgs e)
- {
- Transparent = true;
- }
- #region 表格列编辑
- /// <summary>
- /// 上移列
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnColUp_Click(object sender, System.EventArgs e)
- {
- if (lisCols.SelectedIndex < 1)
- {
- return;
- }
- int index = lisCols.SelectedIndex - 1;
- GridItemColumn gic = (lisCols.SelectedItem as GridItemColumn);
- gic.DisplayIndexInternal = index;
- gic = (lisCols.Items[index] as GridItemColumn);
- gic.DisplayIndexInternal = lisCols.SelectedIndex;
- Columns.UpdateColumnsOrder();
- lisCols.DataSource = null;
- this.lisCols.DisplayMember = GridItemColumnCollection.DisplayMember;
- this.lisCols.DataSource = Columns;
- lisCols.SelectedIndex = index;
- _isColChanged = true;
- }
- /// <summary>
- /// 下移列
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnColDown_Click(object sender, System.EventArgs e)
- {
- if (lisCols.SelectedIndex < 0 || lisCols.SelectedIndex == Columns.Count - 1)
- {
- return;
- }
- int index = lisCols.SelectedIndex + 1;
- GridItemColumn gic = (lisCols.SelectedItem as GridItemColumn);
- gic.DisplayIndexInternal = index;
- gic = (lisCols.Items[index] as GridItemColumn);
- gic.DisplayIndexInternal = lisCols.SelectedIndex;
- Columns.UpdateColumnsOrder();
- lisCols.DataSource = null;
- this.lisCols.DisplayMember = GridItemColumnCollection.DisplayMember;
- this.lisCols.DataSource = Columns;
- lisCols.SelectedIndex = index;
- _isColChanged = true;
- }
- /// <summary>
- /// 编辑列
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnColEdit_Click(object sender, System.EventArgs e)
- {
- if (lisCols.SelectedIndex < 0)
- {
- return;
- }
- int index = lisCols.SelectedIndex;
- GridItemColumn gic = (lisCols.SelectedItem as GridItemColumn);
- using (GridItemColumnSetting itemPropertySetting = new GridItemColumnSetting())
- {
- itemPropertySetting.IsNew = false;
- itemPropertySetting.TextWidth = gic.Width;
- itemPropertySetting.Culture = gic.Culture;
- itemPropertySetting.LineSpaceHead = gic.LineSpaceHead;
- itemPropertySetting.CharacterSpaceHead = gic.CharacterSpaceHead;
- itemPropertySetting.CharacterCountHead = gic.CharacterCountHead;
- itemPropertySetting.TextAlignHead = gic.TextAlignHead;
- itemPropertySetting.TextAlignVerticalHead = gic.TextAlignVerticalHead;
- itemPropertySetting.TextColorHead = gic.TextColorHead;
- itemPropertySetting.TextFontHead = gic.FontHead;
- itemPropertySetting.WrapHead = gic.WrapHead;
- itemPropertySetting.LineSpace = gic.LineSpace;
- itemPropertySetting.CharacterSpace = gic.CharacterSpace;
- itemPropertySetting.CharacterCount = gic.CharacterCount;
- itemPropertySetting.TextAlign = gic.TextAlign;
- itemPropertySetting.TextAlignVertical = gic.TextAlignVertical;
- itemPropertySetting.TextPreview = gic.DisplayValue;
- itemPropertySetting.TextColor = gic.TextColor;
- itemPropertySetting.ItemStyle = gic.ItemStyle;
- itemPropertySetting.ColName = gic.Name;
- itemPropertySetting.HeaderText = gic.HeaderText;
- itemPropertySetting.TextFormat = gic.Format;
- itemPropertySetting.TextFont = gic.Font;
- itemPropertySetting.Wrap = gic.Wrap;
- itemPropertySetting.DefaultValue = gic.DefaultValue;
- itemPropertySetting.IsDataBinding = gic.IsDataBinding;
- itemPropertySetting.chkFixedRatio.Checked = gic.FixedRatio;
- itemPropertySetting.chkM.Checked = gic.PicMargin;
- itemPropertySetting.chkPic.Checked = gic.PicColumn;
- itemPropertySetting.chkFixedRatio.Enabled = gic.PicColumn;
- itemPropertySetting.chkM.Enabled = gic.PicColumn;
- DialogResult result = itemPropertySetting.ShowDialog();
- if (result == DialogResult.OK)
- {
- gic.Width = itemPropertySetting.TextWidth;
- gic.LineSpaceHead = itemPropertySetting.LineSpaceHead;
- gic.CharacterSpaceHead = itemPropertySetting.CharacterSpaceHead;
- gic.CharacterCountHead = itemPropertySetting.CharacterCountHead;
- gic.TextAlignHead = itemPropertySetting.TextAlignHead;
- gic.TextAlignVerticalHead = itemPropertySetting.TextAlignVerticalHead;
- gic.TextColorHead = itemPropertySetting.TextColorHead;
- gic.FontHead = itemPropertySetting.TextFontHead;
- gic.WrapHead = itemPropertySetting.WrapHead;
- gic.LineSpace = itemPropertySetting.LineSpace;
- gic.CharacterSpace = itemPropertySetting.CharacterSpace;
- gic.CharacterCount = itemPropertySetting.CharacterCount;
- gic.Font = itemPropertySetting.TextFont;
- gic.Wrap = itemPropertySetting.Wrap;
- gic.TextAlign = itemPropertySetting.TextAlign;
- gic.TextAlignVertical = itemPropertySetting.TextAlignVertical;
- gic.TextColor = itemPropertySetting.TextColor;
- gic.DisplayValue = itemPropertySetting.TextPreview;
- gic.ItemStyle = itemPropertySetting.ItemStyle;
- gic.Name = itemPropertySetting.ColName;
- gic.HeaderText = itemPropertySetting.HeaderText;
- gic.Format = itemPropertySetting.TextFormat;
- gic.Culture = itemPropertySetting.Culture;
- gic.DefaultValue = itemPropertySetting.DefaultValue;
- gic.FixedRatio = itemPropertySetting.chkFixedRatio.Checked;
- gic.PicMargin = itemPropertySetting.chkM.Checked;
- gic.PicColumn = itemPropertySetting.chkPic.Checked;
- lisCols.DataSource = null;
- this.lisCols.DisplayMember = GridItemColumnCollection.DisplayMember;
- this.lisCols.DataSource = Columns;
- lisCols.SelectedIndex = index;
- _isColChanged = true;
- }
- }
- }
- /// <summary>
- /// 添加列
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnColAdd_Click(object sender, System.EventArgs e)
- {
- // 生成列名
- string colName = Columns.GeNewColumnName();
- Columns.Add(colName, colName);
- lisCols.DataSource = null;
- this.lisCols.DisplayMember = GridItemColumnCollection.DisplayMember;
- this.lisCols.DataSource = Columns;
- lisCols.SelectedIndex = lisCols.Items.Count - 1;
- _isColChanged = true;
- }
- /// <summary>
- /// 移除列
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnColRemove_Click(object sender, System.EventArgs e)
- {
- if (lisCols.SelectedIndex < 0)
- {
- return;
- }
- int index = lisCols.SelectedIndex;
- lisCols.SelectedIndex = (index < Columns.Count - 1) ? index : index - 1;
- Columns.RemoveAtInternal(index, false);
- lisCols.DataSource = null;
- this.lisCols.DisplayMember = GridItemColumnCollection.DisplayMember;
- this.lisCols.DataSource = Columns;
- lisCols.SelectedIndex = (index < Columns.Count) ? index : index - 1;
- _isColChanged = true;
- }
- #endregion 表格列编辑
- private void cbxTitleVisible_CheckedChanged(object sender, System.EventArgs e)
- {
- cbxAlwaysTitleVisible.Enabled = cbxTitleVisible.Checked;
- }
- #endregion 事件处理
- }
- }
|