zoukankan      html  css  js  c++  java
  • 后台用C#中的Attributes

    第一种写法:控件ID名.Attributes.Add(“事件名称”,“JS方法”);

    如:一个按钮控件Button1.Attributes.Add(“onclick”,“return confirm('确认?')”);

    另外还可以控制某一个文本框的属性,比如文本框的大小,宽度等。

    如:TextBox1.Attributes.Add(“width”,“80px”);

    this.Panel1.Attributes.Add("style","display:none");
    this.Panel2.Attributes.Add("style","display:block");

    在gridview中行中:

    row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("CJZTBH")].Attributes.Add("style", "font-size:16px");
    row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("CJZTBH")].BackColor = Color.LightSteelBlue;

    namespace SC //s生产
    {
        /// <summary>
        /// 装配计划员操作 -> 装配作业 PU 3811
        /// </summary>
        public class ClsSCDDZT : ISuwfBus
        {
            #region 变量声明
            private SlnSuwfPage _page;
            #endregion
            #region 初始化
            /// <summary>
            /// 初始化
            /// </summary>
            /// <param name="page">程序单元</param>
            public void Initial(SlnSuwfPage page)
            {
                this._page = page;
                this._page.afterFillGrid += new AfterFillGrid(this.SetGridTextBox);
            }
            #endregion
          
            #region SetGridTextBox
            /// <summary>
            /// SetGridTextBox
            /// </summary>
            private void SetGridTextBox()
            {
                GridView grid = this._page.MainGrid;
    
                foreach (GridViewRow row in grid.Rows)
                {
                   
                    var JHZTBH = ConvertFunction.ObjToInt32(this._page.GetRowDataByKey(row.RowIndex, "JHZTBH"));
                    var CJZTBH = ConvertFunction.ObjToInt32(this._page.GetRowDataByKey(row.RowIndex, "CJZTBH"));
                    var ZXZTBH = ConvertFunction.ObjToInt32(this._page.GetRowDataByKey(row.RowIndex, "ZXZTBH"));
                  
    
                    //(0,初始;1,下达;2,关闭;3,暂停;4,终止;5,请购)
                //    if(SlnString.IsNull(JHZTBH) == true)
                    switch (JHZTBH)
                {
                        case 0:
                        row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("JHZTBH")].BackColor = Color.Orange;
                        break;
                        case 1 :
                      //  row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("JHZTBH")].Style.Add("Font-Size", "14px");
                        row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("JHZTBH")].Attributes.Add("style","font-size:14px");
                        row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("JHZTBH")].Attributes.Add("style", "font-weight:bold");
                     // row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("JHZTBH1")].Style.Add("Font-Size", "14px");
                     //   row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("JHZTBH")].Style.Add("Font-weight","bold");
    
                      //      lblDSRText.Style["Style"] = "left: 500px; position: absolute;top:400px";//设置
                      //  row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("JHZTBH1")].Attributes.Add("Font-Size", "14px");
                        //.ForeColor = Color.Green;
                        //("Font-Size", "14px");
                        break;
                        case 2:
                        row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("JHZTBH")].BackColor = Color.Gold;
                        break;
                        case 3:
                        row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("JHZTBH")].BackColor = Color.Blue;
                    break;
                        case 4:
            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("JHZTBH")].BackColor = Color.Red;
                        break;
                        case 5:
            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("JHZTBH")].BackColor = Color.LightGray;
      break;
                        default: break;
    }
                    switch (ZXZTBH)
                    {
                        case 0:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("ZXZTBH")].BackColor = Color.Orange;
                            break;
                        case 1:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("ZXZTBH")].Style.Add("Font-Size", "14px");
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("ZXZTBH")].Style.Add("Font-weight", "bold");
                            break;
                        case 2:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("ZXZTBH")].BackColor = Color.Gold;
                            break;
                        default: break;
                    }
    
                      /*decode(JHZTBH,0,'初始',1,'下达',3,'暂停',4,'终止',5,'请购')*/
                  
                    switch (CJZTBH)
                    {
                        case 0:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("CJZTBH")].BackColor = Color.Orange;
                            break;
                        case 1:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("CJZTBH")].Style.Add("Font-Size", "14px");
                            // row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("CJZTBH1")].Style.Add("Font-Size", "14px");
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("CJZTBH")].Style.Add("Font-weight", "bold");
    
                            break;
                        case 2:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("CJZTBH")].BackColor = Color.Gold;
                            break;
                        case 3:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("CJZTBH")].BackColor = Color.Blue;
                            break;
                        case 4:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("CJZTBH")].BackColor = Color.Red;
                            break;
                        case 5:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("CJZTBH")].BackColor = Color.LightGray;
                            break;
                              case 6:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("CJZTBH")].BackColor = Color.LightSkyBlue;
                            break;
                              case 7:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("CJZTBH")].BackColor = Color.LightSeaGreen;
                            break;
                              case 8:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("CJZTBH")].BackColor = Color.LightGreen;
                            break;
                              case 9:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("CJZTBH")].BackColor = Color.LightSeaGreen;
                            break;
                              case 10:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("CJZTBH")].BackColor = Color.LightPink;
                            break;
                              case 11:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("CJZTBH")].BackColor = Color.LightYellow;
                            break;
                              case 12:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("CJZTBH")].Attributes.Add("style", "font-size:16px");
                            break;
                              case 13:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("CJZTBH")].BackColor = Color.LightSteelBlue;
                            break;
                              default: break;
                    }
                      
                    try
                    {
                     var field_SCDDZT = _page.Unit.ProgUnit.FieldList.GetFieldByKey("SCDDZT");
                    }
                    catch(Exception ex)
                    {
                              return;
                    }
                   
                    var SCDDZT = ConvertFunction.ObjToStr(this._page.GetRowDataByKey(row.RowIndex, "SCDDZT"));
                    switch (ClsPub.PUB.ToSafeInt(SCDDZT,99))
                    {
                        case 0:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("SCDDZT")].BackColor = Color.Orange;
                            break;
                        case 1:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("SCDDZT")].Style.Add("Font-Size", "14px");
                            // row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("CJZTBH1")].Style.Add("Font-Size", "14px");
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("SCDDZT")].Style.Add("Font-weight", "bold");
                            break;
                        case 2:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("SCDDZT")].BackColor = Color.Gold;
                            break;
                        case 3:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("SCDDZT")].BackColor = Color.Blue;
                            break;
                        case 4:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("SCDDZT")].BackColor = Color.Red;
                            break;
                        case 5:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("SCDDZT")].BackColor = Color.LightGray;
                            break;
                        case 6:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("SCDDZT")].BackColor = Color.LightSkyBlue;
                            break;
                        case 7:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("CJZTBH")].BackColor = Color.LightSeaGreen;
                            break;
                        case 8:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("SCDDZT")].BackColor = Color.LightGreen;
                            break;
                        case 9:
                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey("SCDDZT")].BackColor = Color.LightSeaGreen;
                            break;                  
                        default: break;
                    }
                }
       }
            #endregion
        }
    }
    

      

  • 相关阅读:
    033 流程控制之if判断
    032 基本运算符
    031 格式化输出的三种方式
    030 Python与用户交互
    029 解压缩
    028 布尔类型
    027 字典类型
    026 列表类型
    025 字符串类型
    023 数据类型基础
  • 原文地址:https://www.cnblogs.com/nuaaydh/p/9258105.html
Copyright © 2011-2022 走看看