我先说下我的问题:
我要做一个动态生成的Grid(因为顺序不是定死的):中文 和 英文
比如:
C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
col.Caption="中文名字";
col.Name="英文名字";
有11个这样的列。这11个列是怎么样的顺序
string whole_backlog_act=outBlock.GetColVal(1,"whole_backlog_act");
这个whole_backlog_act的值就是一个顺序排列。
比如显示为:M1M4 H1H2HB C1C2CACBCECLCS
但是它也可显示为:M1M4 H1H2HB C2C1CACBCSCECL
但是它也可显示为:M1M4 H1H2HB C2C1CACBCE
等N种可能。当这个顺序不同,我动态生成的Grid列也是不同。
要在Grid的列根据这个whole_backlog_act显示,我应该怎么做???
为了好理解,抛开一切条件,做个单个的就是这个意思
if (whole_backlog_act.Substring(0,2) == "M1")
{
C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
col.Caption="熔铸生产持续时间";
col.Name="product_time1";
}
请各位高手帮帮忙,急,在线等~~~~

解决方案 »

  1.   


    我怎么把
    这个whole_backlog_act的值:M1M4H1H2HBC1C2CACBCECLCS 两位两位的截取出来
      

  2.   

    不能用循环吗
    while (StartPostion +CutLength <= SText.Length)
    {
    Ruls += SText.Substring(StartPostion,CutLength) +"--";
                          //StartPostion 开始位置 CutLength 截取指定长度
    StartPostion += CutLength;
    switch (SText.Substring (StartPostion ,CutLength))
    {
      case "M1":
              C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add(); 
              col.Caption="熔铸生产持续时间"; 
              col.Name="product_time1";  
               break; 
              case "M2":
                 //省略
                 break; 
    }
    }
      

  3.   

    忘了 说明下 上面只是我做的一个例子 
    SText 就是 whole_backlog_act  
      

  4.   

    我菜鸟写的这个方法有救么,表达意思大概就是这样,怎么写的专业一点。以及可能的情况能够更加全面。
    请各位高手出出主意吧~~ 谢谢~~~~bool p_query()
    {
    if(string.Equals( this.efLabelText1.EFEnterText.Trim(),"")) 
    {
    MessageBox.Show("请填写你要查询的材料号!");
    return false;
    } string out_mat_no=this.efLabelText1.EFEnterText;   if(out_mat_no.Length>7)
    {
    out_mat_no=out_mat_no.Substring(0,out_mat_no.Length-1);
    } EI.EIInfo inBlock = new EI.EIInfo();
    EI.EIInfo outBlock;

    inBlock.SetColName(1,"out_mat_no");  
    inBlock.SetColVal(1,"out_mat_no",out_mat_no); outBlock = EI.EITuxedo.CallService("mm0022a1_inq", inBlock); //判断调用是否正确
    if ((outBlock.sys_info.flag != 0) ||(outBlock.sys_info.sqlcode!=0))
    {
    this.EFMsgInfo = outBlock.sys_info.msg;
    return true;
    } //返回查询结果
    if (outBlock.blk_info[0].row > 0)  //查询到记录
    {
    string whole_backlog_act=outBlock.GetColVal(1,"whole_backlog_act");

    #region 动态生成GRID列
    #region 熔铸和热轧 这前面的工序是固定的,就从冷轧开始工序顺序就不同了
    if (whole_backlog_act.Substring(0,2) == "M1")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="熔铸生产持续时间";
    col.Name="product_time_M1";
    }
    if (whole_backlog_act.Substring(2,2) == "M4")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="锯切生产持续时间";
    col.Name="product_time_M4";
    }
    if (whole_backlog_act.Substring(4,2) == "H1")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="铣面生产持续时间";
    col.Name="product_time_H1";
    }
    if (whole_backlog_act.Substring(6,2) == "H2")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="加热生产持续时间";
    col.Name="product_time_HF";

    C1.Win.C1FlexGrid.Column colHR = this.efGrid1.Cols.Add();
    colHR.Caption="轧制生产持续时间";
    colHR.Name="product_time_HR"; //冷却箱/区持续时间
    C1.Win.C1FlexGrid.Column colHB = this.efGrid1.Cols.Add();
    colHB.Caption="冷却箱/区持续时间";
    colHB.Name="product_time_HB";
    }
    #endregion
    //冷轧第一道工序可能两种情况
    if (whole_backlog_act.Substring(8,2) == "C1")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="轧制道次1生产持续时间";
    col.Name="product_time_C1";
    }
    if (whole_backlog_act.Substring(8,2) == "C2")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="轧制道次2生产持续时间";
    col.Name="product_time_C2";
    } //冷轧第二道工序可能 情况
    if (whole_backlog_act.Substring(10,2) == "C1")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="轧制道次1生产持续时间";
    col.Name="product_time_C1";
    }
    if (whole_backlog_act.Substring(10,2) == "C2")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="轧制道次2生产持续时间";
    col.Name="product_time_C2";
    }
    if (whole_backlog_act.Substring(10,2) == "CA")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="退火生产持续时间";
    col.Name="product_time_CA"; //退火冷却箱/区持续时间
    C1.Win.C1FlexGrid.Column colCB = this.efGrid1.Cols.Add();
    colCB.Caption="退火冷却箱/区持续时间";
    colCB.Name="product_time_CB";
    }
    if (whole_backlog_act.Substring(10,2) == "CL")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="拉矫生产持续时间";
    col.Name="product_time_CL";
    }
    if (whole_backlog_act.Substring(10,2) == "CE")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="切边生产持续时间";
    col.Name="product_time_CE";
    }
    if (whole_backlog_act.Substring(10,2) == "CS")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="纵切生产持续时间";
    col.Name="product_time_CS";
    }
    //冷轧第三道工序可能 情况
    if (whole_backlog_act.Substring(12,2) == "C1")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="轧制道次1生产持续时间";
    col.Name="product_time_C1";
    }
    if (whole_backlog_act.Substring(12,2) == "C2")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="轧制道次2生产持续时间";
    col.Name="product_time_C2";
    }
    if (whole_backlog_act.Substring(12,2) == "CA")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="退火生产持续时间";
    col.Name="product_time_CA"; //退火冷却箱/区持续时间
    C1.Win.C1FlexGrid.Column colCB = this.efGrid1.Cols.Add();
    colCB.Caption="退火冷却箱/区持续时间";
    colCB.Name="product_time_CB";
    }
    if (whole_backlog_act.Substring(12,2) == "CL")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="拉矫生产持续时间";
    col.Name="product_time_CL";
    }
    if (whole_backlog_act.Substring(12,2) == "CE")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="切边生产持续时间";
    col.Name="product_time_CE";
    }
    if (whole_backlog_act.Substring(12,2) == "CS")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="纵切生产持续时间";
    col.Name="product_time_CS";
    }
    //冷轧第四道工序可能 情况
    if(whole_backlog_act.Length>14)
    {
    if (whole_backlog_act.Substring(14,2) == "CA")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="退火生产持续时间";
    col.Name="product_time_CA"; //退火冷却箱/区持续时间
    C1.Win.C1FlexGrid.Column colCB = this.efGrid1.Cols.Add();
    colCB.Caption="退火冷却箱/区持续时间";
    colCB.Name="product_time_CB";
    }
    if (whole_backlog_act.Substring(14,2) == "CL")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="拉矫生产持续时间";
    col.Name="product_time_CL";
    }
    if (whole_backlog_act.Substring(14,2) == "CE")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="切边生产持续时间";
    col.Name="product_time_CE";
    }
    if (whole_backlog_act.Substring(14,2) == "CS")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="纵切生产持续时间";
    col.Name="product_time_CS";
    }
    } //冷轧第五道工序可能 情况
    if(whole_backlog_act.Length>16)
    {
    if (whole_backlog_act.Substring(16,2) == "CA")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="退火生产持续时间";
    col.Name="product_time_CA"; //退火冷却箱/区持续时间
    C1.Win.C1FlexGrid.Column colCB = this.efGrid1.Cols.Add();
    colCB.Caption="退火冷却箱/区持续时间";
    colCB.Name="product_time_CB";
    }
    if (whole_backlog_act.Substring(16,2) == "CL")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="拉矫生产持续时间";
    col.Name="product_time_CL";
    }
    if (whole_backlog_act.Substring(16,2) == "CE")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="切边生产持续时间";
    col.Name="product_time_CE";
    }
    if (whole_backlog_act.Substring(16,2) == "CS")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="纵切生产持续时间";
    col.Name="product_time_CS";
    }
    } //冷轧第六道工序可能 情况
    if(whole_backlog_act.Length>18)
    {
    if (whole_backlog_act.Substring(18,2) == "CA")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="退火生产持续时间";
    col.Name="product_time_CA"; //退火冷却箱/区持续时间
    C1.Win.C1FlexGrid.Column colCB = this.efGrid1.Cols.Add();
    colCB.Caption="退火冷却箱/区持续时间";
    colCB.Name="product_time_CB";
    }
    if (whole_backlog_act.Substring(18,2) == "CL")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="拉矫生产持续时间";
    col.Name="product_time_CL";
    }
    if (whole_backlog_act.Substring(18,2) == "CE")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="切边生产持续时间";
    col.Name="product_time_CE";
    }
    if (whole_backlog_act.Substring(18,2) == "CS")
    {
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption="纵切生产持续时间";
    col.Name="product_time_CS";
    }
    }
    #endregion
    if(NEF.Utility.IsBlockHasError(outBlock, this))
    {
    return true;
    }
    //填充GRID
    outBlock.GetBlockVal(efGrid1);
    efGrid1.AutoSizeCols();

    this.EFMsgInfo =" 查询成功, " +"共有" +outBlock.blk_info[0].Row+"条记录满足条件!"; }
    else  //未查询到记录
    {
    this.efGrid1.Rows.Count = 1;
    this.EFMsgInfo ="没查询到满足条件的记录!";
    }
    return true; }
      

  5.   

    终于写出了一个可行的简单的方法。
    bool p_query()
    {
    int v_count = this.efGrid1.Cols.Count-1;
    for(int i=2;i<v_count;i++)
    {
    this.efGrid1.Cols.Remove(v_count-i+2);
    }
    if(string.Equals( this.efLabelText1.EFEnterText.Trim(),"")) 
    {
    MessageBox.Show("请填写你要查询的材料号!");
    return false;
    } string out_mat_no=this.efLabelText1.EFEnterText;   if(out_mat_no.Length>7)
    {
    out_mat_no=out_mat_no.Substring(0,out_mat_no.Length-1);
    } EI.EIInfo inBlock = new EI.EIInfo();
    EI.EIInfo outBlock;

    inBlock.SetColName(1,"out_mat_no");  
    inBlock.SetColVal(1,"out_mat_no",out_mat_no); outBlock = EI.EITuxedo.CallService("mm0022a1_inq", inBlock); //判断调用是否正确
    if ((outBlock.sys_info.flag != 0) ||(outBlock.sys_info.sqlcode!=0))
    {
    this.EFMsgInfo = outBlock.sys_info.msg;
    return true;
    } //返回查询结果
    if (outBlock.blk_info[0].row > 0)  //查询到记录
    {
    string whole_backlog_act=outBlock.GetColVal(1,"whole_backlog_act");
    string key =string.Empty;
    string pd = "product_time_";
    System.Collections.Hashtable hs= new System.Collections.Hashtable();
    hs.Add("product_time_M1", "熔铸生产持续时间");
    hs.Add("product_time_M4", "锯切生产持续时间");
    hs.Add("product_time_H1", "铣面生产持续时间");
    hs.Add("product_time_HF", "加热生产持续时间");
    hs.Add("product_time_HR", "轧制生产持续时间");
    hs.Add("product_time_HB", "冷却箱/区持续时间");
    hs.Add("product_time_C1", "轧制道次1生产持续时间");
    hs.Add("product_time_C2", "轧制道次2生产持续时间");
    hs.Add("product_time_CA", "退火生产持续时间");
    hs.Add("product_time_CB", "退火冷却箱/区持续时间");
    hs.Add("product_time_CL", "拉矫生产持续时间");
    hs.Add("product_time_CE", "切边生产持续时间");
    hs.Add("product_time_CS", "纵切生产持续时间"); while (whole_backlog_act.Length > 0)
    {
    if (whole_backlog_act.Length > 2)
    {
    key = whole_backlog_act.Substring(0, 2);
    whole_backlog_act = whole_backlog_act.Remove(0, 2);
    }
    else
    {
    key = whole_backlog_act;
    whole_backlog_act = string.Empty;
    }               
                                
    if ("H2".Equals(key))
    {
    key = string.Concat(pd, "HF");
    C1.Win.C1FlexGrid.Column col = this.efGrid1.Cols.Add();
    col.Caption = hs.ContainsKey(key) ? hs[key].ToString(): string.Empty;
    col.Name = key; key = string.Concat(pd, "HR");
    C1.Win.C1FlexGrid.Column colHR = this.efGrid1.Cols.Add();
    colHR.Caption = hs.ContainsKey(key) ? hs[key].ToString(): string.Empty;
    colHR.Name = key; //冷却箱/区持续时间
    key = string.Concat(pd, "HB");
    C1.Win.C1FlexGrid.Column colHB = this.efGrid1.Cols.Add();
    colHB.Caption = hs.ContainsKey(key) ? hs[key].ToString(): string.Empty;
    colHB.Name = key;
    }
    else
    {
    key = string.Concat(pd, key);
    C1.Win.C1FlexGrid.Column col2 = this.efGrid1.Cols.Add();
    col2.Name = key;
    col2.Caption = hs.ContainsKey(key) ? hs[key].ToString(): string.Empty;

    if (string.Concat(pd, "CA").Equals(key))
    {
    //冷却箱/区持续时间
    key = string.Concat(pd, "CB");
    C1.Win.C1FlexGrid.Column colHB = this.efGrid1.Cols.Add();
    colHB.Caption = hs.ContainsKey(key) ? hs[key].ToString(): string.Empty;
    colHB.Name = key;
    }
    }

    }
    if(NEF.Utility.IsBlockHasError(outBlock, this))
    {
    return true;
    }
    //填充GRID
    outBlock.GetBlockVal(efGrid1);
    efGrid1.AutoSizeCols();

    this.EFMsgInfo =" 查询成功, " +"共有" +outBlock.blk_info[0].Row+"条记录满足条件!"; }
    else  //未查询到记录
    {
    this.efGrid1.Rows.Count = 1;
    this.EFMsgInfo ="没查询到满足条件的记录!";
    }
    return true; }
    #endregion