Exemplo n.º 1
0
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            //��ȡ��ѯ��������Ϣ
            string DesignGuid =  Request.QueryString["DesignGuid"].ToString();
            DataView dv = new FrameSearchDesign().Select(DesignGuid);
            string SqlStr = dv[0]["SQL"].ToString();
            string[] SearchFields = dv[0]["SearchFields"].ToString().Split(';');
            string Labels = dv[0]["Labels"].ToString();
            string SeriesName = dv[0]["SeriesName"].ToString();
            string Caption = dv[0]["ChartCaption"].ToString();
            string XName = dv[0]["XName"].ToString();
            string YName = dv[0]["YName"].ToString();
            string ChartWidth = dv[0]["ChartWidth"].ToString().Trim();
            ChartWidth =( ChartWidth == "" ? "450" : ChartWidth);
            string ChartHeight = dv[0]["ChartHeight"].ToString().Trim();
            ChartHeight = (ChartHeight == "" ? "350" : ChartHeight);
            string ChartType = dv[0]["ChartType"].ToString();
            string ConfigValue = dv[0]["ConfigValue"].ToString();

            string VarFlag = ""; //SQL�������ͣ�OracleΪ����SQLServerΪ@
            if (SqlStr.IndexOf(":") > 0)
                VarFlag = ":";
            else if (SqlStr.IndexOf("@") > 0)
                VarFlag = "@";

            //����в������򽫲����滻��SQL��
              if(ViewState["MyControl"].ToString()!="")
              {
              string[] MyControlList = ViewState["MyControl"].ToString().Split(';');
              for (int i = 0; i < MyControlList.Length; i++)
              {
                  string[] ControlInfo = MyControlList[i].ToString().Split(':');
                  if (ControlInfo[1] == "string")
                  {
                      TextBox txt = new TextBox();
                      txt = (TextBox)trHolder.FindControl(ControlInfo[0]);
                      if (txt.Text.Trim() == "")
                      {
                          //���Ϊ�գ�����Ҫ��SQL�и��ֶ�ɾ��
                          SqlStr = DeleteSQLVar(SqlStr, ControlInfo[0], SearchFields);
                      }
                      else
                      {
                        //�滻
                          SqlStr = SqlStr.Replace(" like " + VarFlag + ControlInfo[0], " like '%" + txt.Text.Trim() + "%'");
                          SqlStr = SqlStr.Replace(VarFlag + ControlInfo[0], "'" + txt.Text.Trim() + "'");
                      }

                  }
                 else if (ControlInfo[1] == "number")
                  {
                      ZJGEport.WebControls35.TextBoxControls.NumericTextBox ntb = new ZJGEport.WebControls35.TextBoxControls.NumericTextBox();
                      ntb = (ZJGEport.WebControls35.TextBoxControls.NumericTextBox)trHolder.FindControl(ControlInfo[0]);
                    //  ShowJsMessage(ntb.Text);
                      if (ntb.Text.Trim() == "")
                      {
                          //���Ϊ�գ�����Ҫ��SQL�и��ֶ�ɾ��
                          SqlStr = DeleteSQLVar(SqlStr, ControlInfo[0], SearchFields);
                      }
                      else
                      {
                          //�滻������ǣ�����like�������like����Ҫǰ���%
                          SqlStr = SqlStr.Replace(VarFlag + ControlInfo[0], ntb.Text);

                      }
                  }
                  else if (ControlInfo[1] == "datetime")
                  {
                   //���datebox����datefromto
                      if (ControlInfo[0].IndexOf("&") == -1) //datebox
                      {
                          ZJGEport.WebControls35.DateTextBox dtb = new ZJGEport.WebControls35.DateTextBox();
                          dtb = (ZJGEport.WebControls35.DateTextBox)trHolder.FindControl(ControlInfo[0]);
                          if (dtb.Text.Trim() == "")
                          {
                              SqlStr = DeleteSQLVar(SqlStr, ControlInfo[0], SearchFields);
                          }
                          else
                          {
                              if (VarFlag == "@")
                                  SqlStr = SqlStr.Replace(VarFlag + ControlInfo[0], "'" + dtb.Text + "'");
                              else if(VarFlag == ":")
                                  SqlStr = SqlStr.Replace(VarFlag + ControlInfo[0], "TO_DATE('" + dtb.Text + "','yyyy-mm-dd')");
                          }
                      }
                      else //datefromto
                      {
                          ZJGEport.WebControls35.DateFromTo dft = new ZJGEport.WebControls35.DateFromTo();
                          dft = (ZJGEport.WebControls35.DateFromTo)trHolder.FindControl(ControlInfo[0]);
                          //��dateFromTo�����
                          string From = dft.FromText.Trim();
                          if (From == "")
                          {
                              From = "1900/1/1";
                          }
                          string To=dft.ToText.Trim();
                          if (To == "")
                          {
                              To = "2099/1/1";
                          }
                          //��ȡ������������
                          string DateFromVar = ControlInfo[0].Split('&')[0];
                          string DateToVar = ControlInfo[0].Split('&')[1];
                          if (VarFlag == "@")
                          {
                              SqlStr = SqlStr.Replace(VarFlag + DateFromVar, "'" + From + "'");
                              SqlStr = SqlStr.Replace(VarFlag + DateToVar, "'" + To + "'");
                          }
                          else if (VarFlag == ":")
                          {
                              SqlStr = SqlStr.Replace(VarFlag + DateFromVar, "TO_DATE('" + From + "','yyyy-mm-dd')");
                              SqlStr = SqlStr.Replace(VarFlag + DateToVar, "TO_DATE('" + To + "','yyyy-mm-dd')");
                          }
                      }
                  }

              }

               }

            dv = new FrameSearchDesign().GetDataBySQL(SqlStr);
            if (dv.Count == 0)
            {
                ShowJsMessage("û�����ݿ�����ʾ��");
                return;
            }
            StringBuilder strXML = new StringBuilder();
            //���ݲ�ͬ��ͼ�����ͼ���ͷ
            int palette = new System.Random().Next(1, 6);
            strXML.Append("<chart palette='" + palette + "'  caption='");
            strXML.Append(Caption);
            strXML.Append("'  xAxisName='");
            strXML.Append(XName);
            strXML.Append("' yAxisName='");
            strXML.Append(YName);
            strXML.Append("'  rotateYAxisName='0' baseFontSize='12' alternateHGridColor='FCB541' lineColor='FCB541' divLineColor='FCB541'  showValues='1' decimals='0' formatNumberScale='0' useRoundEdges='1' " + ConfigValue + " >");
            //����ͼ������ݲ��֣���Ϊ��ϵ�кͶ�ϵ��
            //��ϵ�в���
            if (ChartType.ToLower() == "column2d.swf" || ChartType.ToLower() == "column3d.swf" || ChartType.ToLower() == "line.swf" || ChartType.ToLower() == "pie2d.swf" || ChartType.ToLower() == "pie3d.swf")
            {
                for (int i = 0; i < dv.Count; i++)
                {
                    strXML.AppendFormat("<set label='{0}' value='{1}' />", dv[i][Labels].ToString(), dv[i][SeriesName].ToString());
                }
            }
            else //��ϵ�в��ֺͶ�ϵ�в���
            {

            }
            strXML.Append("</chart>");

            string outPut = FusionCharts.RenderChartHTML("/ChartsView/" + ChartType, "", strXML.ToString(), "chart1", ChartWidth, ChartHeight, false, false);
            phChart.Controls.Add(new LiteralControl(outPut));
        }
Exemplo n.º 2
0
        protected void ViewChart()
        {
            ViewState["MyControl"] = ""; //���ڱ��浱ǰ�ؼ���ID�Ϳؼ������ͣ�
            string DesignGuid = Request.QueryString["DesignGuid"].ToString();
            DataView dv = new FrameSearchDesign().Select(DesignGuid);
            this.CurrentPosition = dv[0]["ChartCaption"].ToString();
            string SQL = dv[0]["SQL"].ToString();
            //������������ؼ�
            string[] SearchFields = dv[0]["SearchFields"].ToString().Split(';');
            //����ͬһ��������ֻ����һ�Σ�����ʱ�����͵ģ�����ǡ������򹹽�һ��ʱ��ѡ��򣬶��ڡ�> <����Χ���͵ģ�����һ��datefomto
            ArrayList oneTimeVar = new ArrayList();
            for (int i = 0; i < SearchFields.Length; i++)
            {
                if (SearchFields[i].Trim() != "" && !oneTimeVar.Contains(SearchFields[i].Trim()))
                    oneTimeVar.Add(SearchFields[i].Trim());
            }

            for (int i = 0; i < oneTimeVar.Count; i++)
            {
                if (oneTimeVar[i].ToString() != ":::")
                {

                    bool IsDateTimeType = false;
                    if (oneTimeVar[i].ToString().Split(':')[3].ToLower() == "datetime")
                        IsDateTimeType = true;
                    TableCell tc = new TableCell();
                    string[] Lables = oneTimeVar[i].ToString().Split(':');
                    Label lb = new Label();
                    lb.Text = "&nbsp;&nbsp;&nbsp;" + Lables[0];
                    tc.Controls.Add(lb); //��ӿؼ�����
                    trHolder.Controls.Add(tc);
                    if (!IsDateTimeType) //������ʱ���Ϳؼ�
                    {
                        //�жϴ����������͵������
                        TableCell tc1 = new TableCell();
                        if (Lables[3].ToString().Trim().ToLower() == "string")
                        {
                            TextBox tb = new TextBox();
                            tb.ID = Lables[2].ToString().Trim();
                            if (ViewState["MyControl"].ToString() == "")
                            {
                                ViewState["MyControl"] = tb.ID + ":string";
                            }
                            else
                            {
                                ViewState["MyControl"] =ViewState["MyControl"].ToString()+ ";" + tb.ID + ":string";
                            }
                            tb.Width = Unit.Pixel(150);
                            tb.MaxLength = 20;
                            tc1.Controls.Add(tb);

                        }
                        else if (Lables[3].ToString().Trim().ToLower() == "number")
                        {
                            ZJGEport.WebControls35.TextBoxControls.NumericTextBox ntb = new ZJGEport.WebControls35.TextBoxControls.NumericTextBox();
                            ntb.ID = Lables[2].ToString().Trim();
                            if (ViewState["MyControl"].ToString() == "")
                            {
                                ViewState["MyControl"] = ntb.ID + ":number";
                            }
                            else
                            {
                                ViewState["MyControl"] = ViewState["MyControl"].ToString() + ";" + ntb.ID + ":number";
                            }
                            ntb.Width = Unit.Pixel(60);
                            ntb.MaxLength = 10;
                            tc1.Controls.Add(ntb);
                        }

                        trHolder.Controls.Add(tc1);
                    }
                    else  //����DateTime�ؼ�
                    {
                        TableCell tc1 = new TableCell();
                        //���ݸò�ѯ�ֶ�����Ӧ��SQL�ֶη���������ֻ����һ�����򹹽�datetime��������������������datefromto
                        string label2 = Lables[1].ToString().Trim();
                        int k = 0;
                        for (; k < oneTimeVar.Count; k++)
                        {
                            string[] tmp = oneTimeVar[k].ToString().Split(':');
                            if (k != i && label2 == tmp[1].Trim() && tmp[3].Trim().ToLower() == "datetime")
                            {
                                //����datefromto
                                ZJGEport.WebControls35.DateFromTo dft = new ZJGEport.WebControls35.DateFromTo();
                                dft.ID = Lables[2].Trim()+"&"+tmp[2].Trim();
                                if (ViewState["MyControl"].ToString() == "")
                                {
                                    ViewState["MyControl"] = dft.ID + ":datetime";
                                }
                                else
                                {
                                    ViewState["MyControl"] = ViewState["MyControl"].ToString() + ";" + dft.ID + ":datetime";
                                }
                                dft.FromWidth = Unit.Pixel(80);
                                dft.ToWidth = Unit.Pixel(80);
                                tc1.Controls.Add(dft);
                                //�����󣬽���Ӧ���ֶ�����������ѹ��������ֶ��ٴι���
                                oneTimeVar[k] = ":::";
                                oneTimeVar[i] = ":::";
                                break;
                            }
                        }
                        //���û���ҵ����򹹽�datetime
                        if (k == oneTimeVar.Count)
                        {
                            ZJGEport.WebControls35.DateTextBox dtb = new ZJGEport.WebControls35.DateTextBox();
                            dtb.ID = Lables[2].ToString().Trim();
                            if (ViewState["MyControl"].ToString() == "")
                            {
                                ViewState["MyControl"] = dtb.ID + ":datetime";
                            }
                            else
                            {
                                ViewState["MyControl"] = ViewState["MyControl"].ToString() + ";" + dtb.ID + ":datetime";
                            }
                            dtb.Width = Unit.Pixel(80);
                            dtb.ID = Lables[2].ToString().Trim();
                            tc1.Controls.Add(dtb);
                            oneTimeVar[i] = ":::";
                        }
                        trHolder.Controls.Add(tc1);
                    }
                }

            }
        }