// 设置模式:编辑与非编辑,默认是非编辑模式
        public void SetEditable(bool bEditable)
        {
            m_bIsEditable = bEditable;
            if (m_bIsEditable)
            {
                // 编辑模式
                // 设定标题栏,默认有个隐藏列
                this.Header = new string[]
                {
                    CS_Delete, CS_StationID, CS_StationName, CS_TimeCollected, CS_Voltage, CS_DataState, CS_TimeReceived, CS_ChannelType, CS_MsgType
                };

                //   this.HideColomns = new int[] { 7};

                //开启编辑模式,设置可编辑列
                DataGridViewCheckBoxColumn deleteCol = new DataGridViewCheckBoxColumn();
                base.SetColumnEditStyle(0, deleteCol);

                //// 设置采集时间编辑列
                //CalendarColumn collectionCol = new CalendarColumn();
                //base.SetColumnEditStyle(2, collectionCol);

                // 累计电压编辑列
                DataGridViewNumericUpDownColumn voltage = new DataGridViewNumericUpDownColumn()
                {
                    Minimum       = 0,
                    Maximum       = 65537,
                    DecimalPlaces = 2 /*好像是设置小数点后面的位数*/
                };
                base.SetColumnEditStyle(4, voltage);

                // 数据状态,可编辑列
                DataGridViewComboBoxColumn dataStateCol = new DataGridViewComboBoxColumn();
                dataStateCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
                dataStateCol.Items.AddRange(new object[] { CS_DataState_Normal, CS_DataState_AbNormal });
                base.SetColumnEditStyle(5, dataStateCol);

                // 接收时间
                CalendarColumn recvTime = new CalendarColumn();
                base.SetColumnEditStyle(6, recvTime);

                // 通讯方式,不可编辑

                // 报文类型,不可编辑

                // 设置删除列的宽度
                this.Columns[0].Width = 40; //删除列宽度为20
                this.Columns[3].Width = 125;
                this.Columns[5].Width = 125;
            }
            else
            {
                this.Columns[2].Width = 125;
                this.Columns[4].Width = 125;
            }
        }
        private DataGridViewNumericUpDownColumn GenerateColumnStype_1()
        {
            DataGridViewNumericUpDownColumn C10_4 = new DataGridViewNumericUpDownColumn()
            {
                Minimum       = -9999999,
                Maximum       = 9999999,
                DecimalPlaces = 2,            /*好像是设置小数点后面的位数*/
                Increment     = (Decimal)0.01 /*增量*/
            };

            return(C10_4);
        }
        public void SetEditMode(bool bEnable)
        {
            if (bEnable)
            {
                // 设定标题栏,默认有个隐藏列
                this.Header = new string[]
                {
                    CS_Delete,
                    CS_PortNumber,
                    CS_ProtocolChannel,
                    CS_UDPorTCP,
                    CS_ProtocolData,
                    CS_StartType,
                    CS_CurrentStatus
                };
                //this.HideColomns = new int[] { 7, 8, 9, 10, 11 };
                //  添加删除列
                var delCol = new DataGridViewCheckBoxColumn();
                base.SetColumnEditStyle(0, delCol);

                //  添加端口号
                DataGridViewNumericUpDownColumn portNumberCol = new DataGridViewNumericUpDownColumn();
                portNumberCol.Minimum = 1000;
                portNumberCol.Maximum = 65535;
                base.SetColumnEditStyle(1, portNumberCol);

                //  添加通讯方式
                var ChannelCol = new DataGridViewComboBoxColumn();
                ChannelCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
                var channelNames = m_listProtocolGprs;
                ChannelCol.Items.Add(CS_None);
                foreach (var item in channelNames)
                {
                    ChannelCol.Items.Add(item);
                }
                foreach (var item in m_listProtocolTransparen)
                {
                    ChannelCol.Items.Add(item);
                }
                base.SetColumnEditStyle(2, ChannelCol);

                //  添加UDP/TCP协议选择
                var udpOrTcpCol = new DataGridViewComboBoxColumn();
                udpOrTcpCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
                udpOrTcpCol.Items.AddRange(new object[] { CS_UDPorTCP_UDP, CS_UDPorTCP_TCP });
                base.SetColumnEditStyle(3, udpOrTcpCol);

                //  添加数据协议
                var dataCol = new DataGridViewComboBoxColumn();
                dataCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
                var dataNames = m_listProtocolData;
                dataCol.Items.Add(CS_None);
                foreach (var item in dataNames)
                {
                    dataCol.Items.Add(item);
                }
                base.SetColumnEditStyle(4, dataCol);

                //启动方式
                var startedCol = new DataGridViewComboBoxColumn();
                startedCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
                startedCol.Items.AddRange(new object[] { CS_StartType_Auto, CS_StartType_Manaual });
                base.SetColumnEditStyle(5, startedCol);

                //当前状态
                var statusCol = new DataGridViewComboBoxColumn();
                statusCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
                statusCol.Items.AddRange(new object[] { CS_Status_Enabled, CS_Status_Disable });
                base.SetColumnEditStyle(6, statusCol);

                this.Columns[0].Width = 20; //删除列
            }
        }
        public void SetEditable(bool bEditable)
        {
            m_bIsEditable = bEditable;
            if (m_bIsEditable)
            {
                // 设定标题栏,默认有个隐藏列
                this.Header = new string[]
                {
                    CS_Delete, CS_StationID, CS_StationName, CS_TimeCollected, CS_TotalRain, CS_DifferenceRain, CS_PeriodRain, CS_DayRain, CS_DataState, CS_TimeReceived, CS_ChannelType, CS_MsgType
                };
                //  this.HideColomns = new int[] { 10 };

                //开启编辑模式,设置可编辑列

                DataGridViewCheckBoxColumn deleteCol = new DataGridViewCheckBoxColumn();
                base.SetColumnEditStyle(0, deleteCol);

                //// 设置采集时间编辑列
                //CalendarColumn collectionCol = new CalendarColumn();
                //base.SetColumnEditStyle(3, collectionCol);

                // 累计雨量编辑列
                DataGridViewNumericUpDownColumn totalRain = new DataGridViewNumericUpDownColumn()
                {
                    Minimum       = 0,
                    Maximum       = 65537,
                    DecimalPlaces = 1 /*好像是设置小数点后面的位数*/
                };
                base.SetColumnEditStyle(4, totalRain);

                //// 差值雨量编辑列
                //DataGridViewNumericUpDownColumn differneceRain = new DataGridViewNumericUpDownColumn()
                //{
                //    Minimum = 0,
                //    Maximum = 65537,
                //    DecimalPlaces = 1 /*好像是设置小数点后面的位数*/

                //};
                //base.SetColumnEditStyle(5, differneceRain);

                //// 时段雨量编辑列
                //DataGridViewNumericUpDownColumn periodRain = new DataGridViewNumericUpDownColumn()
                //{
                //    Minimum = 0,
                //    Maximum = 65537,
                //    DecimalPlaces = 1 /*好像是设置小数点后面的位数*/

                //};
                //base.SetColumnEditStyle(6, periodRain);

                //// 日雨量
                //DataGridViewNumericUpDownColumn dayRain = new DataGridViewNumericUpDownColumn()
                //{
                //    Minimum = 0,
                //    Maximum = 65537,
                //    DecimalPlaces = 1 /*好像是设置小数点后面的位数*/

                //};
                //base.SetColumnEditStyle(7, dayRain);

                // 数据状态,可编辑列
                DataGridViewComboBoxColumn dataStateCol = new DataGridViewComboBoxColumn();
                dataStateCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
                dataStateCol.Items.AddRange(new object[] { CS_DataState_Normal, CS_DataState_AbNormal, CS_DataState_Warning });
                base.SetColumnEditStyle(8, dataStateCol);

                // 接收时间
                CalendarColumn recvTime = new CalendarColumn();
                base.SetColumnEditStyle(9, recvTime);


                // 通讯方式,不可编辑

                // 报文类型,不可编辑


                // 设置删除列的宽度
                this.Columns[0].Width = 40; //删除列宽度为20
                this.Columns[1].Width = 60;
                this.Columns[3].Width = 125;
                this.Columns[4].Width = 70;
                this.Columns[5].Width = 70;
                this.Columns[6].Width = 70;
                this.Columns[7].Width = 70;
                this.Columns[8].Width = 60;
                this.Columns[9].Width = 125; // 接收时间
            }
            else
            {
                this.Columns[0].Width = 60;
                this.Columns[2].Width = 125;
                this.Columns[3].Width = 70;
                this.Columns[4].Width = 70;
                this.Columns[5].Width = 70;
                this.Columns[6].Width = 70;
                this.Columns[7].Width = 60;
                this.Columns[8].Width = 125; // 接收时间
                //this.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                //this.Columns[8].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            }
        }
        /// <summary>
        /// 外部调用可控制宽度,嘿嘿
        /// </summary>
        /// <param name="bEnable"></param>
        public void SetEditMode(bool bEnable)
        {
            if (bEnable)
            {
                // 设定标题栏,默认有个隐藏列
                this.Header = new string[]
                {
                    CS_StationId, CS_BGTM, CS_PTNO, CS_ZR, CS_Q1, CS_Q2, CS_Q3, CS_Q4, CS_Q5, CS_Q6, CS_currQ
                };
                //this.HideColomns = new int[]
                //{
                //    12 /*CS_RecordId*/
                //};

                //开启编辑模式,设置可编辑列
                DataGridViewCheckBoxColumn deleteCol = new DataGridViewCheckBoxColumn();
                base.SetColumnEditStyle(0, deleteCol);

                ////// 设置站号编辑列
                //DataGridViewNumericUpDownColumn stationIdCol = new DataGridViewNumericUpDownColumn();
                //// stationId.Maximum = Decimal.MaxValue;
                //base.SetColumnEditStyle(1, stationIdCol);


                ////// 设置站号编辑列
                //DataGridViewNumericUpDownColumn PTNOCol = new DataGridViewNumericUpDownColumn();
                //// stationId.Maximum = Decimal.MaxValue;
                //base.SetColumnEditStyle(3, PTNOCol);

                // 设置水位编辑列
                DataGridViewNumericUpDownColumn waterCol = new DataGridViewNumericUpDownColumn();
                waterCol.Maximum       = Decimal.MaxValue;
                waterCol.Minimum       = Decimal.MinValue;
                waterCol.DecimalPlaces = 2;
                base.SetColumnEditStyle(4, waterCol);

                //// 设置流量1编辑列
                DataGridViewNumericUpDownColumn Q1Col = new DataGridViewNumericUpDownColumn();
                Q1Col.Maximum       = Decimal.MaxValue;
                Q1Col.Minimum       = Decimal.MinValue;
                Q1Col.DecimalPlaces = 3;
                base.SetColumnEditStyle(5, Q1Col);

                //// 设置流量2编辑列
                DataGridViewNumericUpDownColumn Q2Col = new DataGridViewNumericUpDownColumn();
                Q2Col.Maximum       = Decimal.MaxValue;
                Q2Col.Minimum       = Decimal.MinValue;
                Q2Col.DecimalPlaces = 3;
                base.SetColumnEditStyle(6, Q2Col);

                //// 设置流量3编辑列
                DataGridViewNumericUpDownColumn Q3Col = new DataGridViewNumericUpDownColumn();
                Q3Col.Maximum       = Decimal.MaxValue;
                Q3Col.Minimum       = Decimal.MinValue;
                Q3Col.DecimalPlaces = 3;
                base.SetColumnEditStyle(7, Q3Col);

                //// 设置流量4编辑列
                DataGridViewNumericUpDownColumn Q4Col = new DataGridViewNumericUpDownColumn();
                Q4Col.Maximum       = Decimal.MaxValue;
                Q4Col.Minimum       = Decimal.MinValue;
                Q4Col.DecimalPlaces = 3;
                base.SetColumnEditStyle(8, Q4Col);

                //// 设置流量5编辑列
                DataGridViewNumericUpDownColumn Q5Col = new DataGridViewNumericUpDownColumn();
                Q5Col.Maximum       = Decimal.MaxValue;
                Q5Col.Minimum       = Decimal.MinValue;
                Q5Col.DecimalPlaces = 3;
                base.SetColumnEditStyle(9, Q5Col);

                //// 设置流量6编辑列
                DataGridViewNumericUpDownColumn Q6Col = new DataGridViewNumericUpDownColumn();
                Q6Col.Maximum       = Decimal.MaxValue;
                Q6Col.Minimum       = Decimal.MinValue;
                Q6Col.DecimalPlaces = 3;
                base.SetColumnEditStyle(10, Q6Col);


                var cmb_currQ = new DataGridViewComboBoxColumn();
                cmb_currQ.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;

                cmb_currQ.Items.Add("1");
                cmb_currQ.Items.Add("2");
                cmb_currQ.Items.Add("3");
                cmb_currQ.Items.Add("4");
                cmb_currQ.Items.Add("5");
                cmb_currQ.Items.Add("6");
                base.SetColumnEditStyle(11, cmb_currQ);

                // 设置删除列的宽度
                this.Columns[0].Width  = 15; //删除列宽度为20
                this.Columns[2].Width  = 25; //删除列宽度为25
                this.Columns[11].Width = 25; //删除列宽度为25
            }
            else
            {
                // 只读模式未编写
                // 设定标题栏,默认有个隐藏列
                this.Header = new string[]
                {
                    CS_StationId, CS_BGTM, CS_PTNO, CS_ZR, CS_Q1, CS_Q2, CS_Q3, CS_Q4, CS_Q5, CS_Q6, CS_currQ
                };
                //this.Columns[0].Width = 25; //删除列宽度为25
                //this.Columns[1].Width = 120; //删除列宽度为25
                //this.Columns[2].Width = 15; //删除列宽度为25
                //this.Columns[3].Width = 15; //删除列宽度为25
                //this.Columns[4].Width = 40; //删除列宽度为25
                //this.Columns[5].Width = 40; //删除列宽度为25
                //this.Columns[6].Width = 40; //删除列宽度为25
                //this.Columns[7].Width = 40; //删除列宽度为25
                //this.Columns[8].Width = 40; //删除列宽度为25
                //this.Columns[9].Width = 40; //删除列宽度为25
                //this.Columns[10].Width = 25; //删除列宽度为25
                AutoSizeColumn(this);
                this.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                //this.Columns[6].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            }
        }
        public void SetEditable(bool bEditable)
        {
            m_bIsEditable = bEditable;
            if (m_bIsEditable)
            {
                // 设定标题栏,默认有个隐藏列
                this.Header = new string[]
                {
                    CS_Delete, CS_StationID, CS_StationName, CS_TimeCollected, CS_Voltage,
                    CS_V10, CS_M10, CS_V20, CS_M20, CS_V30, CS_M30,
                    CS_V40, CS_M40, CS_V60, CS_M60,
                    CS_ChannelType, CS_MsgType, CS_ReciveTime
                };
                //  this.HideColomns = new int[] { 10 };

                //开启编辑模式,设置可编辑列

                DataGridViewCheckBoxColumn deleteCol = new DataGridViewCheckBoxColumn();
                base.SetColumnEditStyle(0, deleteCol);

                //// 设置采集时间编辑列
                //CalendarColumn collectionCol = new CalendarColumn();
                //base.SetColumnEditStyle(3, collectionCol);

                // 电压编辑列
                DataGridViewNumericUpDownColumn Voltage = new DataGridViewNumericUpDownColumn()
                {
                    Minimum       = 0,
                    Maximum       = 65537,
                    DecimalPlaces = 2 /*好像是设置小数点后面的位数*/
                };
                base.SetColumnEditStyle(4, Voltage);

                // 10CM电压编辑列
                DataGridViewNumericUpDownColumn V10 = new DataGridViewNumericUpDownColumn()
                {
                    Minimum       = 0,
                    Maximum       = 65537,
                    DecimalPlaces = 2/*好像是设置小数点后面的位数*/
                };
                base.SetColumnEditStyle(5, V10);

                // 10CM含水量编辑列
                DataGridViewNumericUpDownColumn M10 = new DataGridViewNumericUpDownColumn()
                {
                    Minimum       = 0,
                    Maximum       = 65537,
                    DecimalPlaces = 3 /*好像是设置小数点后面的位数*/
                };
                base.SetColumnEditStyle(6, M10);

                // 20CM电压编辑列
                DataGridViewNumericUpDownColumn V20 = new DataGridViewNumericUpDownColumn()
                {
                    Minimum       = 0,
                    Maximum       = 65537,
                    DecimalPlaces = 2 /*好像是设置小数点后面的位数*/
                };
                base.SetColumnEditStyle(7, V20);

                // 20CM含水量编辑列
                DataGridViewNumericUpDownColumn M20 = new DataGridViewNumericUpDownColumn()
                {
                    Minimum       = 0,
                    Maximum       = 65537,
                    DecimalPlaces = 3 /*好像是设置小数点后面的位数*/
                };
                base.SetColumnEditStyle(8, M20);

                // 30CM电压编辑列
                DataGridViewNumericUpDownColumn V30 = new DataGridViewNumericUpDownColumn()
                {
                    Minimum       = 0,
                    Maximum       = 65537,
                    DecimalPlaces = 2 /*好像是设置小数点后面的位数*/
                };
                base.SetColumnEditStyle(9, V30);


                // 30CM含水量编辑列
                DataGridViewNumericUpDownColumn M30 = new DataGridViewNumericUpDownColumn()
                {
                    Minimum       = 0,
                    Maximum       = 65537,
                    DecimalPlaces = 3 /*好像是设置小数点后面的位数*/
                };
                //M30.Displayed= DataGridViewComboBoxDisplayStyle.Nothing;
                //M30.
                base.SetColumnEditStyle(10, M30);

                // 40CM电压编辑列
                DataGridViewNumericUpDownColumn V40 = new DataGridViewNumericUpDownColumn()
                {
                    Minimum       = 0,
                    Maximum       = 65537,
                    DecimalPlaces = 2 /*好像是设置小数点后面的位数*/
                };
                base.SetColumnEditStyle(11, V40);


                // 40CM含水量编辑列
                DataGridViewNumericUpDownColumn M40 = new DataGridViewNumericUpDownColumn()
                {
                    Minimum       = 0,
                    Maximum       = 65537,
                    DecimalPlaces = 3 /*好像是设置小数点后面的位数*/
                };
                base.SetColumnEditStyle(12, M40);

                // 40CM电压编辑列
                DataGridViewNumericUpDownColumn V60 = new DataGridViewNumericUpDownColumn()
                {
                    Minimum       = 0,
                    Maximum       = 65537,
                    DecimalPlaces = 2 /*好像是设置小数点后面的位数*/
                };
                base.SetColumnEditStyle(13, V60);


                // 40CM含水量编辑列
                DataGridViewNumericUpDownColumn M60 = new DataGridViewNumericUpDownColumn()
                {
                    Minimum       = 0,
                    Maximum       = 65537,
                    DecimalPlaces = 3 /*好像是设置小数点后面的位数*/
                };
                base.SetColumnEditStyle(14, M60);

                //// 数据状态,可编辑列
                //DataGridViewComboBoxColumn dataStateCol = new DataGridViewComboBoxColumn();
                //dataStateCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
                //dataStateCol.Items.AddRange(new object[] { CS_DataState_Normal, CS_DataState_AbNormal });
                //base.SetColumnEditStyle(8, dataStateCol);

                // 接收时间
                //11.11
                //CalendarColumn recvTime = new CalendarColumn();
                //base.SetColumnEditStyle(17, recvTime);


                // 通讯方式,不可编辑

                // 报文类型,不可编辑


                // 设置删除列的宽度
                this.Columns[0].Width  = 40; //删除列宽度为20
                this.Columns[3].Width  = 125;
                this.Columns[17].Width = 125;
            }
            else
            {
                this.Columns[2].Width  = 125;
                this.Columns[16].Width = 125;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 设置每个每列对应的单元格的格式
        /// </summary>
        /// <param name="bEnable"></param>
        public void SetEditMode(bool bEnable)
        {
            if (bEnable)
            {
                // 设定标题栏,默认有个隐藏列
                this.Header = new string[]
                {
                    CS_Delete,
                    CS_ServerIp,
                    CS_Port,
                    CS_ProtocolChannel,
                    CS_ProtocolData,
                    CS_Account,
                    CS_Password,
                    CS_CurrentStatus
                };
                var delCol = new DataGridViewCheckBoxColumn();
                base.SetColumnEditStyle(0, delCol);

                //  添加IP
                DataGridViewTextBoxColumn ipCol = new DataGridViewTextBoxColumn();
                base.SetColumnEditStyle(1, ipCol);

                //  添加端口号
                DataGridViewNumericUpDownColumn portNumberCol = new DataGridViewNumericUpDownColumn();
                portNumberCol.Minimum = 1000;
                portNumberCol.Maximum = 65535;
                base.SetColumnEditStyle(2, portNumberCol);

                //  添加通讯方式
                var ChannelCol = new DataGridViewComboBoxColumn();
                ChannelCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
                var channelName = "WebGsm";
                ChannelCol.Items.Add(CS_None);
                ChannelCol.Items.Add(channelName);
                base.SetColumnEditStyle(3, ChannelCol);

                //  添加数据协议
                var dataCol = new DataGridViewComboBoxColumn();
                dataCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
                var dataNames = m_listProtocolData;
                dataCol.Items.Add(CS_None);
                foreach (var item in dataNames)
                {
                    dataCol.Items.Add(item);
                }
                base.SetColumnEditStyle(4, dataCol);

                //  添加用户账户
                DataGridViewTextBoxColumn accountCol = new DataGridViewTextBoxColumn();
                base.SetColumnEditStyle(5, accountCol);

                //  添加用户账户
                DataGridViewTextBoxColumn passCol = new DataGridViewTextBoxColumn();
                base.SetColumnEditStyle(6, passCol);

                //当前状态
                var statusCol = new DataGridViewComboBoxColumn();
                statusCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
                statusCol.Items.AddRange(new object[] { CS_Status_Enabled, CS_Status_Disable });
                base.SetColumnEditStyle(7, statusCol);

                this.Columns[0].Width = 20; //删除列
            }
        }