Ejemplo n.º 1
0
        private void LoadControlToPage(int ReportId)
        {
            try
            {
                Panel.Controls.Clear();
                cls_Report_User objUser = new cls_Report_User();
                DataSet _ds = objUser.GetConfigReport(ReportId);
                DataTable _dtConfig = _ds.Tables[0];
                if (_dtConfig.Rows.Count == 0) return;
                ViewState["Config"] = _dtConfig;
                short TabIndex = 1;
                Label LB;
                string[] ArrRow =null;
                int t = 0;
                int k = 0;
                while (k < _dtConfig.Rows.Count)
                {
                    if (ArrRow == null)
                        Array.Resize(ref ArrRow, 1);
                    else
                        Array.Resize(ref ArrRow, ArrRow.Length + 1);
                    if (k < _dtConfig.Rows.Count - 1 && (Convert.ToInt32(_dtConfig.Rows[k]["Width"]) + Convert.ToInt32(_dtConfig.Rows[k + 1]["Width"]) <= (848 - 848 / 3)))
                    {

                        ArrRow[t] = k.ToString() + ":" + (k + 1).ToString();
                        k++;
                    }
                    else
                    {
                        ArrRow[t] = k.ToString();
                    }
                    t++;
                    k++;
                }
                //Lay max text

                string strMax = "";
                for (k = 0; k < ArrRow.Length; k++)
                {
                    if (ArrRow[k] != null && ArrRow[k].Length > 0)
                    {
                        if (ArrRow[k].IndexOf(":") >= 0)
                        {
                            string[] ArStr = ArrRow[k].Split(':');
                            if (_dtConfig.Rows[Convert.ToInt32(ArStr[0])]["Parameter_Name"].ToString().Length > strMax.Length)
                                strMax = _dtConfig.Rows[Convert.ToInt32(ArStr[0])]["Parameter_Name"].ToString();
                        }
                        else
                        {
                            if (_dtConfig.Rows[Convert.ToInt32(ArrRow[k])]["Parameter_Name"].ToString().Length > strMax.Length)
                                strMax = _dtConfig.Rows[Convert.ToInt32(ArrRow[k])]["Parameter_Name"].ToString();
                        }
                    }
                }
                strMax += ": ";
                //
                for (k = 0; k < ArrRow.Length; k++)
                {
                    if (k > 0)
                    {
                        HtmlAnchor te = new HtmlAnchor();
                        te.InnerHtml = "<br />";
                        Panel.Controls.Add(te);
                        HtmlAnchor te1 = new HtmlAnchor();
                        te1.InnerHtml = "<br />";
                        Panel.Controls.Add(te1);
                    }
                    if (ArrRow[k].Length > 0)
                    {
                        if (ArrRow[k].IndexOf(":") >= 0)
                        {
                            string[] ArStr = ArrRow[k].Split(':');
                            for (int j = 0; j < ArStr.Length; j++)
                            {

                                LB = new Label();

                                if (j > 0)
                                {
                                  HtmlAnchor tex = new HtmlAnchor();
                                  //tex.InnerText =
                                    tex.InnerHtml = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                                    Panel.Controls.Add(tex);
                                }
                                string str = _dtConfig.Rows[Convert.ToInt32(ArStr[j])]["Parameter_Name"].ToString() + ": ";
                                LB.Text = str;
                                Panel.Controls.Add(LB);
                                if(j==0)
                                if (str.Length < strMax.Length)
                                {
                                    string sadd ="";
                                    for (int y = 0; y <= strMax.Length - str.Length;y++ )
                                        sadd += "&nbsp;";
                                     HtmlAnchor add = new HtmlAnchor();
                                      add.InnerHtml  = sadd;
                                     Panel.Controls.Add(add);
                                }
                               string sCate = _dtConfig.Rows[Convert.ToInt32(ArStr[j])]["Control_Type"].ToString();
                                if (sCate == "TextBox")
                                {
                                    TextBox TB = new TextBox();
                                    TB.ID = _dtConfig.Rows[Convert.ToInt32(ArStr[j])]["Parameter_Code"].ToString();
                                    TB.Height =  Convert.ToInt32(_dtConfig.Rows[Convert.ToInt32(ArStr[j])]["Height"]);
                                    TB.Width = Convert.ToInt32(_dtConfig.Rows[Convert.ToInt32(ArStr[j])]["Width"]);
                                    TB.TabIndex = TabIndex;
                                    Panel.Controls.Add(TB);
                                }
                                if (sCate == "DatePicker")
                                {
                                    RadDatePicker date = new RadDatePicker();
                                    date.Height = Convert.ToInt32(_dtConfig.Rows[Convert.ToInt32(ArStr[j])]["Height"]);
                                    date.Width = Convert.ToInt32(_dtConfig.Rows[Convert.ToInt32(ArStr[j])]["Width"]);
                                    date.Skin = "Vista";
                                    date.DateInput.DateFormat = "dd/MM/yyyy";
                                    date.ID = _dtConfig.Rows[Convert.ToInt32(ArStr[j])]["Parameter_Code"].ToString();
                                   // date.Culture = new  System.Globalization.CultureInfo("Vietnamese");
                                    date.Font.Bold = true; date.Font.Name = "Times New Roman";
                                    date.Font.Size = 12;
                                    date.SelectedDate = DateTime.Now;
                                    date.TabIndex = TabIndex;
                                    Panel.Controls.Add(date);

                                }
                                if (sCate == "DateTimePicker")
                                {

                                    RadDateTimePicker date = new RadDateTimePicker();
                                    date.Height = Convert.ToInt32(_dtConfig.Rows[Convert.ToInt32(ArStr[j])]["Height"]);
                                    date.Width = Convert.ToInt32(_dtConfig.Rows[Convert.ToInt32(ArStr[j])]["Width"]);
                                    date.Skin = "Vista";
                                    date.DateInput.DateFormat = "dd/MM/yyyy";
                                    date.ID = _dtConfig.Rows[Convert.ToInt32(ArStr[j])]["Parameter_Code"].ToString();

                                    // date.Culture = new  System.Globalization.CultureInfo("Vietnamese");
                                    date.Font.Bold = true; date.Font.Name = "Times New Roman";
                                    date.Font.Size = 12;
                                    date.SelectedDate = DateTime.Now;
                                    date.TabIndex = TabIndex;
                                    Panel.Controls.Add(date);
                                }

                                if (sCate == "ComboBox")
                                {
                                    RadComboBox com = new RadComboBox();
                                    com.Skin = "Vista";
                                    com.Height = Convert.ToInt32(_dtConfig.Rows[Convert.ToInt32(ArStr[j])]["Height"])*5;
                                    com.Width = Convert.ToInt32(_dtConfig.Rows[Convert.ToInt32(ArStr[j])]["Width"]);
                                    com.ID = _dtConfig.Rows[Convert.ToInt32(ArStr[j])]["Parameter_Code"].ToString();

                                    com.EnableVirtualScrolling = true;
                                    string SQL = _dtConfig.Rows[Convert.ToInt32(ArStr[j])]["Data_SQL"].ToString();
                                    if (SQL.Length > 0)
                                    {
                                        DataTable _dt;
                                        if (_dtConfig.Rows[Convert.ToInt32(ArStr[j])]["IsSP"] != null && Convert.ToBoolean(_dtConfig.Rows[Convert.ToInt32(ArStr[j])]["IsSP"]) == true)
                                        {
                                            int Index = SQL.IndexOf('@');
                                            if (Index >= 0)
                                                _dt = objUser.GetSP(SQL.Substring(0, Index), SQL.Substring(Index, SQL.Length - Index), Session["UserId"] == null ? "0" : Session["UserId"].ToString());
                                            else
                                                _dt = objUser.GetSP(SQL);
                                        }
                                        else
                                      _dt = objUser.GetSQL(SQL);
                                        com.DataValueField = "ID";
                                        com.DataTextField = "Name";
                                        com.DataSource = _dt;
                                        com.DataBind();
                                    }
                                    com.TabIndex = TabIndex;
                                    Panel.Controls.Add(com);
                                }
                                 TabIndex++;
                            }

                        }
                        else
                        {
                            LB = new Label();
                            string str = _dtConfig.Rows[Convert.ToInt32(ArrRow[k])]["Parameter_Name"].ToString() + ": ";
                            LB.Text = str;
                            Panel.Controls.Add(LB);

                                if (str.Length < strMax.Length)
                                {
                                    string sadd = "";
                                    for (int y = 0; y <= strMax.Length - str.Length; y++)
                                        sadd += "&nbsp;";
                                    HtmlAnchor add = new HtmlAnchor();
                                    add.InnerHtml = sadd;
                                    Panel.Controls.Add(add);
                                }
                            string sCate = _dtConfig.Rows[Convert.ToInt32(ArrRow[k])]["Control_Type"].ToString();
                            if (sCate == "TextBox")
                            {
                                TextBox TB = new TextBox();
                                TB.ID = _dtConfig.Rows[Convert.ToInt32(ArrRow[k])]["Parameter_Code"].ToString();
                                TB.Height = Convert.ToInt32(_dtConfig.Rows[Convert.ToInt32(ArrRow[k])]["Height"]);
                                TB.Width = Convert.ToInt32(_dtConfig.Rows[Convert.ToInt32(ArrRow[k])]["Width"]);
                                TB.TabIndex = TabIndex;
                                Panel.Controls.Add(TB);
                            }
                            if (sCate == "DatePicker")
                            {
                                RadDatePicker date = new RadDatePicker();
                                date.Height = Convert.ToInt32(_dtConfig.Rows[Convert.ToInt32(ArrRow[k])]["Height"]);
                                date.Width = Convert.ToInt32(_dtConfig.Rows[Convert.ToInt32(ArrRow[k])]["Width"]);
                                date.Skin = "Vista";
                                date.DateInput.DateFormat = "dd/MM/yyyy";
                                date.ID = _dtConfig.Rows[Convert.ToInt32(ArrRow[k])]["Parameter_Code"].ToString();
                                // date.Culture = new  System.Globalization.CultureInfo("Vietnamese");
                                date.Font.Bold = true; date.Font.Name = "Times New Roman";
                                date.Font.Size = 12;
                                date.SelectedDate = DateTime.Now;
                                date.TabIndex = TabIndex;
                                Panel.Controls.Add(date);
                            }
                            if (sCate == "DateTimePicker")
                            {
                                RadDateTimePicker date = new RadDateTimePicker();
                                date.Height = Convert.ToInt32(_dtConfig.Rows[Convert.ToInt32(ArrRow[k])]["Height"]);
                                date.Width = Convert.ToInt32(_dtConfig.Rows[Convert.ToInt32(ArrRow[k])]["Width"]);
                                date.Skin = "Vista";
                                date.DateInput.DateFormat = "dd/MM/yyyy";
                                date.ID = _dtConfig.Rows[Convert.ToInt32(ArrRow[k])]["Parameter_Code"].ToString();
                                // date.Culture = new  System.Globalization.CultureInfo("Vietnamese");
                                date.Font.Bold = true; date.Font.Name = "Times New Roman";
                                date.Font.Size = 12;
                                date.SelectedDate = DateTime.Now;
                                date.TabIndex = TabIndex;
                                Panel.Controls.Add(date);
                            }

                            if (sCate == "ComboBox")
                            {
                                RadComboBox com = new RadComboBox();
                                com.Skin = "Vista";
                                com.Height = Convert.ToInt32(_dtConfig.Rows[Convert.ToInt32(ArrRow[k])]["Height"]) * 5;
                                com.Width = Convert.ToInt32(_dtConfig.Rows[Convert.ToInt32(ArrRow[k])]["Width"]);
                                com.ID = _dtConfig.Rows[Convert.ToInt32(ArrRow[k])]["Parameter_Code"].ToString();
                                com.EnableVirtualScrolling = true;
                                string SQL = _dtConfig.Rows[Convert.ToInt32(ArrRow[k])]["Data_SQL"].ToString();
                                if (SQL.Length > 0)
                                {
                                    DataTable _dt;
                                    if (_dtConfig.Rows[Convert.ToInt32(ArrRow[k])]["IsSP"] != null && Convert.ToBoolean(_dtConfig.Rows[Convert.ToInt32(ArrRow[k])]["IsSP"]) == true)
                                    {
                                        int Index = SQL.IndexOf('@');
                                        if (Index >= 0)
                                            _dt = objUser.GetSP(SQL.Substring(0, Index), SQL.Substring(Index, SQL.Length - Index), Session["UserId"] == null ? "0" : Session["UserId"].ToString());
                                        else
                                            _dt = objUser.GetSP(SQL);
                                    }
                                    else
                                        _dt = objUser.GetSQL(SQL);
                                    com.DataValueField = "ID";
                                    com.DataTextField = "Name";
                                    com.DataSource = _dt;
                                    com.DataBind();
                                }
                                com.TabIndex = TabIndex;
                                Panel.Controls.Add(com);
                            }

                            TabIndex++;
                        }
                    }
                  }
                //
            }

            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 2
0
        private void ViewReport()
        {
            try
            {
                ReportDocument reportDocument = new ReportDocument();
                string sReportID = Request.QueryString["ID_Report"].ToString();
                cls_Catalog_Report objRe = new cls_Catalog_Report();
                DataTable _dtRe = objRe.GetReport(sReportID);
                DataTable _dtPara = Session["ReportPara"] == null ? null : (DataTable)(Session["ReportPara"]);
                DataTable _dtP = _dtPara.Clone();
                DataTable _dtPReport = _dtPara.Clone();
                DataTable _dtSource;
                string[] sArr = _dtRe.Rows[0]["SPName"].ToString().Split('@');
                cls_Report_User objUser = new cls_Report_User();
                if (sArr.Length > 1)
                {
                    for (int i = 0; i < _dtPara.Rows.Count; i++)
                    {
                        bool Exist = false;
                        for (int k = 1; k < sArr.Length; k++)
                            if (_dtPara.Rows[i]["ParaName"].ToString().ToUpper() == sArr[k].ToUpper())
                            {
                                Exist = true;
                                break;
                            }
                        if (Exist)
                        {
                            _dtP.ImportRow(_dtPara.Rows[i]);
                        }
                        else
                            _dtPReport.ImportRow(_dtPara.Rows[i]);
                    }
                  _dtSource = objUser.GetDataSourceReport(_dtP, sArr[0]);
                }
                else
                    _dtSource = objUser.GetSP(sArr[0]);
                //
                if (sArr.Length >= 1 && sArr[0].Length <= 0)
                    _dtPReport = _dtPara;

                string sPath = ConfigurationManager.AppSettings["Report_File"].ToString() + _dtRe.Rows[0]["File_Path"].ToString();
                reportDocument.Load(sPath);
                //tham so bao cao

                if (_dtSource != null)
                    reportDocument.SetDataSource(_dtSource);

                for (int k = 0; k < _dtP.Rows.Count; k++)
                {
                    for (int i = 0; i < reportDocument.ParameterFields.Count; i++)
                    {
                        if (reportDocument.ParameterFields[i].Name.ToUpper() == _dtP.Rows[k]["ParaName"].ToString().ToUpper())
                            reportDocument.SetParameterValue(reportDocument.ParameterFields[i].Name, _dtP.Rows[k]["ParaValue"]);
                    }
                }
                if (_dtPReport.Rows.Count > 0)
                    for (int i = 0; i < _dtPReport.Rows.Count; i++)
                        reportDocument.SetParameterValue(_dtPReport.Rows[i]["ParaName"].ToString(), _dtPReport.Rows[i]["ParaValue"]);

                CrystalReportViewer.ReportSource = reportDocument;

                CrystalReportViewer.DataBind();
            }
            catch (Exception ex)
            {
            }
        }