Пример #1
0
        private void dataGridViewMembers_SelectionChanged(object sender, EventArgs e)
        {
            Telerik.WinControls.UI.RadGridView dgv = (Telerik.WinControls.UI.RadGridView)sender;

            try
            {
                if (dgv.SelectedRows.Count > 0)
                {
                    string clubMemberId = dgv.SelectedRows[0].Cells[0].Value.ToString();
                    memberId = int.Parse(clubMemberId);

                    DataRow dataRow = this.clubMemberService.GetClubMemberById(memberId);

                    txt2Name.Text                   = dataRow["Name"].ToString();
                    dt2DateOfBirth.Value            = Convert.ToDateTime(dataRow["DateOfBirth"]);
                    cmb2Occupation.SelectedValue    = dataRow.Field <Occupation>("Occupation");
                    cmb2MaritalStatus.SelectedValue = dataRow.Field <MaritalStatus>("MaritalStatus");
                    cmb2HealthStatus.SelectedValue  = dataRow.Field <HealthStatus>("HealthStatus");
                    txt2Salary.Text                 = dataRow["Salary"].ToString() == "0.0000" ? string.Empty : dataRow["Salary"].ToString();
                    txt2NoOfChildren.Text           = dataRow["NumberOfChildren"].ToString();
                }
            }
            catch (Exception ex)
            {
                this.ShowErrorMessage(ex);
            }
        }
Пример #2
0
 public void Print_DataGridView(Telerik.WinControls.UI.RadGridView dgv_01, string inXML)
 {
     Print_DataGridView(dgv_01, inXML, null, null);
 }
Пример #3
0
        public void Print_DataGridView(Telerik.WinControls.UI.RadGridView dgv_01, string inXML, string barCode, string[] concent)
        {
            _adopter.GetPrintSetting(CnasBaseData.MacAddress);
            barCodeValue = "";
            if (concent == null)
            {
                concent = printContentValue;
            }

            try
            {
                if (dgv_01.Rows.Count == 0)
                {
                    MessageBox.Show("没有需要打印的数据", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (_adopter.PrinterDialogResult != DialogResult.OK)
                {
                    return;
                }
                // Getting DataGridView object to print
                dgv = dgv_01;

                // Getting all Coulmns Names in the DataGridView
                AvailableColumns.Clear();

                foreach (GridViewColumn c in dgv.Columns)
                {
                    if (!c.IsVisible)
                    {
                        continue;
                    }
                    AvailableColumns.Add(c.HeaderText);
                }

                // Showing the PrintOption Form
                //PrintOptions dlg = new PrintOptions(AvailableColumns, titleList);

                #region  获取XML

                XmlDocument xmldoc = new XmlDocument();
                xmldoc.LoadXml(inXML);
                XmlElement printTitleValueXML = xmldoc["PrintData"]["Title"]["value"];
                XmlElement printTitleSizeXML  = xmldoc["PrintData"]["Attribute"]["titlesize"];
                XmlElement printTitleColorXML = xmldoc["PrintData"]["Attribute"]["titlecolor"];
                XmlElement printTitleStyleXML = xmldoc["PrintData"]["Attribute"]["titlestyle"];
                XmlElement printTitleFontXML  = xmldoc["PrintData"]["Attribute"]["titlefont"];
                XmlElement printconSizeXML    = xmldoc["PrintData"]["Attribute"]["consize"];
                XmlElement printconColorXML   = xmldoc["PrintData"]["Attribute"]["concolor"];
                XmlElement printconStyleXML   = xmldoc["PrintData"]["Attribute"]["constyle"];
                XmlElement printconFontXML    = xmldoc["PrintData"]["Attribute"]["confont"];
                XmlElement printdgvSizeXML    = xmldoc["PrintData"]["DataGrid"]["dgvfontSize"];
                XmlElement printdgvFontXML    = xmldoc["PrintData"]["DataGrid"]["dgvfont"];
                XmlElement printdgvStyleXML   = xmldoc["PrintData"]["DataGrid"]["dgvfontstyle"];


                XmlElement printContentDescriptionXML = xmldoc["PrintData"]["Content"]["description"];
                XmlElement printContentKeyXML         = xmldoc["PrintData"]["Content"]["key"];
                XmlElement printContentValueXML       = xmldoc["PrintData"]["Content"]["value"];

                string printTitleValue = printTitleValueXML != null ? printTitleValueXML.InnerXml : string.Empty;                 //标题
                string printTitleSize  = printTitleSizeXML != null ? printTitleSizeXML.InnerXml : "10";                           //标题字体大小
                string printTitleColor = printTitleColorXML != null ? printTitleColorXML.InnerXml : Color.Black.ToString();       //标题字体颜色
                string printTitleStyle = printTitleStyleXML != null ? printTitleStyleXML.InnerXml : FontStyle.Regular.ToString(); //标题字体风格
                string printTitleFont  = printTitleFontXML != null ? printTitleFontXML.InnerXml : "新宋体";                          //标题字体

                string printconSize  = printconSizeXML != null ? printconSizeXML.InnerXml : "9";                                  //内容字体大小
                string printconColor = printconColorXML != null ? printconColorXML.InnerXml : Color.Black.ToString();             //内容字体颜色
                string printconStyle = printconStyleXML != null ? printconStyleXML.InnerXml : FontStyle.Regular.ToString();       //内容字体风格
                string printconFont  = printconFontXML != null ? printconFontXML.InnerXml : string.Empty;                         //内容字体

                string printdgvSize  = printdgvSizeXML != null ? printdgvSizeXML.InnerXml : "9";                                  //Dgv字体大小
                string printdgvFont  = printdgvFontXML != null ? printdgvFontXML.InnerXml : "新宋体";                                //Dgv字体
                string printdgvStyle = printdgvStyleXML != null ? printdgvStyleXML.InnerXml : FontStyle.Regular.ToString();       //Dgv字体风格

                string   printContentDescription = printContentDescriptionXML.InnerXml;                                           //列表的基本信息
                string[] printContentKey         = printContentKeyXML.InnerXml.Split(',');                                        //列表的键
                printContentValue = printContentValueXML.InnerXml.Split(',');                                                     //列表的值
                #endregion


                for (int i = 0; i < printContentKey.Length; i++)
                {
                    if (concent == null)
                    {
                        printContentDescription = printContentDescription.Replace(printContentKey[i], printContentValue[i]);
                    }
                    if (concent != null)
                    {
                        if (concent.Length > 0)                 //如果有自定义传入参数值,则显示参数值
                        {
                            if (i > concent.Length - 1)
                            {
                                printContentDescription = printContentDescription.Replace(printContentKey[i], printContentValue[i]);
                            }
                            else
                            {
                                printContentDescription = printContentDescription.Replace(printContentKey[i], concent[i]);
                            }
                        }
                        else
                        {
                            printContentDescription = printContentDescription.Replace(printContentKey[i], printContentValue[i]);
                        }
                    }
                }

                #region 字体属性
                //标题字体属性
                FontColor = new SolidBrush(Color.FromName(printTitleColor));
                string titlefont = "新宋体";
                if (!string.IsNullOrEmpty(null))
                {
                    titlefont = "新宋体";
                }
                else
                {
                    titlefont = printTitleFont;
                }
                float titlesize = 20;
                float.TryParse(printTitleSize, out titlesize);
                if (titlesize == 0)
                {
                    titlesize = 20;
                }
                FontStyle titleStyle = FontStyle.Bold;
                Enum.TryParse(printTitleStyle, out titleStyle);
                TitleFont = new Font(titlefont, titlesize, titleStyle);

                ConFontColor = new SolidBrush(Color.FromName(printconColor));
                //内容字体属性
                string confont = "新宋体";
                if (!string.IsNullOrEmpty(null))
                {
                    confont = "新宋体";
                }
                else
                {
                    confont = printconFont;
                }
                FontStyle contentFontStyle = FontStyle.Regular;
                Enum.TryParse(printconStyle, out contentFontStyle);
                float consize = 12;
                float.TryParse(printconSize, out consize);
                if (consize == 0)
                {
                    consize = 12;
                }
                ConFont = new Font(confont, consize, contentFontStyle);


                //dgv字体属性
                string dgvfont = "新宋体";
                if (!string.IsNullOrEmpty(null))
                {
                    dgvfont = "宋体";
                }
                else
                {
                    dgvfont = printdgvFont;
                }
                FontStyle dgvFontStyle = FontStyle.Regular;
                Enum.TryParse(printdgvStyle, out dgvFontStyle);
                float dgvsize = 9;
                float.TryParse(printdgvSize, out dgvsize);
                if (dgvsize == 0)
                {
                    dgvsize = 9;
                }
                DgvFont = new Font(dgvfont, dgvsize, dgvFontStyle);
                #endregion
                PrintTitle = printTitleValue;                //标题的值

                // 判断用户是否有传入 barCode
                if (!string.IsNullOrEmpty(barCode))
                {
                    barCodeValue = barCode;
                }

                PrintContent    = printContentDescription; //内容的值
                PrintAllRows    = true;                    //所有行
                FitToPageWidth  = true;                    //页宽
                SelectedColumns = AvailableColumns;        //打印的列

                RowsPerPage = 0;

                _printPreviewDialog          = new PrintPreviewDialog();
                _printPreviewDialog.Document = printDoc;                //获取预览文档
                printDoc.PrinterSettings     = _printDialog.PrinterSettings;

                // 展现每一页打印内容
                printDoc.BeginPrint            += new System.Drawing.Printing.PrintEventHandler(PrintDoc_BeginPrint);
                printDoc.PrintPage             += new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);
                _printPreviewDialog.FormClosed += OnPrintPreviewDialogClosed;

                if (_printPreviewDialog.ShowDialog() != DialogResult.OK)
                {
                    printDoc.BeginPrint -= new System.Drawing.Printing.PrintEventHandler(PrintDoc_BeginPrint);
                    printDoc.PrintPage  -= new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);
                    return;
                }

                //开始打印
                printDoc.Print();
                printDoc.BeginPrint -= new System.Drawing.Printing.PrintEventHandler(PrintDoc_BeginPrint);
                printDoc.PrintPage  -= new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);
                printDoc.EndPrint   += printDoc_EndPrint;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
            }
        }
Пример #4
0
 public void Print_DataGridView(Telerik.WinControls.UI.RadGridView dgv1)
 {
     Print_DataGridView(dgv1, null, null, null);
 }