Beispiel #1
0
        /// <summary>
        /// 返回节点的属性值
        /// </summary>
        /// <param name="childNode">节点</param>
        /// <param name="Name">属性名称</param>
        /// <param name="value">默认值</param>
        /// <returns>如果属性值存在,返回属性值,如果不存在,返回默认值</returns>
        public static float GetValFromDT(DataTable dt, string Name, int irow, float sValue)
        {
            try
            {
                if (dt == null)
                {
                    return(sValue);
                }

                string ss = "";
                if (dt.Columns.Contains(Name))
                {
                    ss = dt.Rows[irow][Name].ToString();
                }
                if (CABCSTR.IsFloat(ss) || CABCSTR.IsNum(ss))
                {
                    return(Convert.ToSingle(ss));
                }
                else
                {
                    return(sValue);
                }
            }
            catch
            {
                return(sValue);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 返回单元格值,如果没有返回默认值
        /// </summary>
        /// <param name="ncell">单元格</param>
        /// <param name="s0">默认值</param>
        /// <returns>返回值</returns>
        public static int GetValueFromCell(DataGridViewCell ncell, int s0)
        {
            string s1 = GetValueFromCell(ncell, "0");

            if (CABCSTR.IsNum(s1))
            {
                return(Convert.ToInt32(s1));
            }
            else
            {
                return(0);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 返回单元格值,如果没有返回默认值
        /// </summary>
        /// <param name="ncell">单元格</param>
        /// <param name="s0">默认值</param>
        /// <returns>返回值</returns>
        public static float GetValueFromCell(DataGridViewCell ncell, float s0)
        {
            string s1 = GetValueFromCell(ncell, "0");

            if (CABCSTR.IsFloat(s1))
            {
                return(Convert.ToSingle(s1));
            }
            else
            {
                return(0);
            }
        }
Beispiel #4
0
        /// <summary>
        /// 返回节点的属性值
        /// </summary>
        /// <param name="childNode">节点</param>
        /// <param name="Name">属性名称</param>
        /// <param name="value">默认值</param>
        /// <returns>如果属性值存在,返回属性值,如果不存在,返回默认值</returns>
        public static int GetValFromDT(DataSet ds, int index, string Name, int irow, int sValue)
        {
            try
            {
                DataTable dt;
                if (index < ds.Tables.Count)
                {
                    dt = ds.Tables[index];
                }
                else
                {
                    dt = ds.Tables[0];
                }
                if (dt == null)
                {
                    return(sValue);
                }

                string ss = "";
                if (ds.Tables[0].Columns.Contains(Name))
                {
                    ss = ds.Tables[0].Rows[irow][Name].ToString();
                }
                if (CABCSTR.IsFloat(ss) || CABCSTR.IsNum(ss))
                {
                    return((int)Convert.ToSingle(ss));
                }
                else
                {
                    return(sValue);
                }
            }
            catch
            {
                return(sValue);
            }
        }
Beispiel #5
0
        /// <summary>
        /// 按规律设定表格单元格
        /// </summary>
        /// <param name="dGV">表格名称</param>
        /// <param name="iCRC">循环行数</param>
        /// <param name="bAdd">是否递增</param>
        public static bool dGVSetByCrc(DataGridView dGV, int iCRC, bool bAdd)
        {
            try
            {
                List <int> LsRow = CABCDGV.GetSelRow(dGV);
                List <int> LsCol = CABCDGV.GetSelCol(dGV);
                if (LsRow.Count < iCRC + 1)
                {
                    return(false);
                }
                for (int n = 0; n < iCRC; n++)
                {
                    for (int i = 0; i < LsCol.Count; i++)
                    {
                        string sHead = dGV.Columns[LsCol[i]].HeaderText;
                        string str0  = "";
                        if (dGV.Rows[LsRow[n]].Cells[LsCol[i]].Value != null)
                        {
                            str0 = dGV.Rows[LsRow[n]].Cells[LsCol[i]].Value.ToString();
                        }
                        string str1 = "";
                        if (bAdd && dGV.Rows[LsRow[n + iCRC]].Cells[LsCol[i]].Value != null)
                        {
                            str1 = dGV.Rows[LsRow[n + iCRC]].Cells[LsCol[i]].Value.ToString();
                        }
                        else
                        {
                            str1 = str0;
                        }
                        double dStart = 0, dAdd = 0;
                        int    iStart = 0, iLen = 0;
                        string sChar = "";
                        int    iRes  = CABCSTR.Get2StrChange(str0, str1, ref dStart, ref dAdd, ref sChar, ref iStart, ref iLen);
                        if (iRes == 0)
                        {
                            return(false);
                        }
                        int kStart = 1;
                        if (bAdd)
                        {
                            kStart = 2;
                        }
                        for (int k = kStart; k < Math.Ceiling(((LsRow.Count / (double)iCRC))); k++)
                        {
                            if (n + k * iCRC >= LsRow.Count)
                            {
                                continue;
                            }
                            double dVal   = dStart + dAdd * k;
                            string sValue = "";
                            if (iRes == 1)
                            {
                                sValue = dVal.ToString();
                            }
                            else if (iRes == 2)
                            {
                                string sVal = new String('0', iLen) + dVal.ToString();
                                sValue = sChar.Insert(iStart, sVal.Substring(sVal.Length - iLen, iLen));
                            }
                            else if (iRes == 3)
                            {
                                sValue = str0;
                            }

                            dGV.Rows[LsRow[n + k * iCRC]].Cells[LsCol[i]].Value = sValue;
                        }
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }