SM5604btnCGRK-遍历gridView

================SLSHTestEdit===============
namespace SLSHTestEdit
{
    public class Class1 : ISuwfBus
    {
        private SlnSuwfPage _page;
        GridView grd;
        
        void ISuwfBus.Initial(SlnSuwfPage page)
        {
            this._page = page;           
            _page.Load += new EventHandler(Page_Load);
        }

        private void Page_Load(object sender, EventArgs e)
        {           
            ChageEdit(null, null);         
            return;
        }
         #region ChageCellColor
        private void ChageEdit(object sender, EventArgs e)
        {   
            int indexID = _page.Unit.ProgUnit.FieldList.GetFieldByKey("ID").Index;//流水号
            int indx_edit = _page.Unit.ProgUnit.FieldList.GetFieldByKey("edit").Index;//是否编辑
            grd = _page.MainGrid;
            foreach (GridViewRow row in grd.Rows)
            {               
               if( ConvertFunction.ObjToInt32(row.Cells[indexID].Text)==1)
               {
                   row.Cells[indx_edit].Text = "";
               }              
            }
        }
        #endregion ChageCellColor

    }
}
===============ClsCalculateZPDJ .cs==========
namespace WXSMGZ
{
    class ClsCalculateZPDJ : ISuwfBus
    {
        private SlnSuwfPage _page;
        public void Initial(SlnSuwfPage page)
        {
            _page = page;
            _page.afterFillGrid += new AfterFillGrid(afterFillGrid);
           
        }
        #region afterFillGrid
        private void afterFillGrid()
        {

            GridView grd = _page.MainGrid;
            int ZPDJ = _page.Unit.ProgUnit.FieldList.GetIndexByKey("ZPDJ");

            foreach (GridViewRow row in grd.Rows)
            {
                string ZGZ = ConvertFunction.ObjToStr(_page.GetRowDataByKey(row.RowIndex,"ZGZ")).Trim();
                string GHGZ = ConvertFunction.ObjToStr(_page.GetRowDataByKey(row.RowIndex,"GHGZ")).Trim();
                string RKSL = ConvertFunction.ObjToStr(_page.GetRowDataByKey(row.RowIndex,"RKSL")).Trim();
                if (SlnString.IsNull(ZGZ)==true) { row.Cells[ZPDJ].Text =""; }
                else if (SlnString.IsNull(GHGZ)==true) { row.Cells[ZPDJ].Text=""; }
                else if (SlnString.IsNull(RKSL)==true) { row.Cells[ZPDJ].Text =""; }
                else
                {              row.Cells[ZPDJ].Text =CalcZPDJ(ZGZ, GHGZ, RKSL);
                }     
            }

        }
        #endregion      

    }
}
========SLSHNYGL_ONLINE.PUB=============
namespace SLSHNYGL_ONLINE.PUB
{
    public class ClsFun
    {
        public static int GetSelectedRowNum(SlnSuwfPage _page, int iCol)
        {
            int iCount = 0;
            int iSelectRowNum = -1;

            for (int i = 0; i < _page.MainGrid.Rows.Count; i++)
            {
                if (_page.MainGrid.Rows[i].HasControls())
                {
                    if (_page.MainGrid.Rows[i].Controls[iCol].HasControls())
                    {
                        if (((_page.MainGrid.Rows[i].Controls[iCol].Controls[0]) as CheckBox) != null)
                        {
                            if (((_page.MainGrid.Rows[i].Controls[iCol].Controls[0]) as CheckBox).Checked)
                            {
                                iSelectRowNum = i;
                                iCount++;
                            }
                        }
                    }
                }
            }

            if (iCount == 1)//只能选择一个
            {
                iSelectRowNum = 1;
            }
            else
            {
                iSelectRowNum = -1;
            }

            return iSelectRowNum;
        }      
    }
}
========ClsMX_BD============
  private void btnCalculate1_click(object sender, EventArgs e)
        {
            if (grd.Rows.Count == 0)
            {
                return;
            }
            isCalculate = true;
            
            listParameter = new List<DataFieldEntity>();
            GetParameterDataTable();//查询数据库 根据模型id 获取模型下的需要公式计算的参数 
            str_ParametersInGs = this.GetAllParameterIdInGsToStr(mx_id);//根据 模型下参数对应的 公式 获取公式中用到的参数字符串 (1,2,3)形式
            //return;
            if (str_ParametersInGs == null || str_ParametersInGs == "")
            {
                _page.ShowMessage("没有指标需要计算");
                return;
            }

            GetGridBoxValueList("PARAMETER_ID", "MXBD_BD");//获取网格编辑值

            getAllParameterDataTable();//查询数据库,获取与模型相关的所有参数,包含模型下参数 和 公式中涉及到的参数,按照公式层级由0向上

            LoadLevel0Parameter();//界面上已计算0级参数           
            LoadData();//根据公式计算 从1级开始往上递归计算     
            setGridValue();//将计算后的数据填到界面上
          
        }
        //给界面数据赋值时,将原始值为空的,赋值,用颜色标示
        private void setGridValue()
        {
            string temp_str = "";
            try
            {
                string ys_value = "";
                string bd_value = "";
                int index = 0;
                DataFieldEntity temp = new DataFieldEntity();
                int zb_ys = this._page.Unit.ProgUnit.FieldList.GetIndexByKey("ZB_YS");
                int mx_ys = this._page.Unit.ProgUnit.FieldList.GetIndexByKey("MXBD_YS");
                string temp_level = "";
                string str_tips = _page.GetValueByName("dataTips");


                bdysnewParameter = _page.Session["bdysnew"]==null?null:(Dictionary<string, string>)_page.Session["bdysnew"];
                zbysnewParameter = _page.Session["zbysnew"]==null?null:(Dictionary<string, string>)_page.Session["zbysnew"];

                foreach (GridViewRow row in grd.Rows)
                {
                    ys_value = "";
                    bd_value = "";

                    index = row.RowIndex;
                    current_pid = _page.GetRowDataByKey(index, "PARAMETER_ID");
                    temp = listParameter.Find(getValue);
                 
                    //---lzw 更具session给原始赋值
                    
                    if (bdysnewParameter.ContainsKey(current_pid))
                    {
                        row.Cells[mx_ys].Text = bdysnewParameter[current_pid];
                        row.Cells[mx_ys].ForeColor = Color.Red;

                        ys_value = bdysnewParameter[current_pid];
                    }
                    else
                    {
                        ys_value = _page.GetRowDataByKey(index, "MXBD_YS");
                    }

                    bd_value = _page.GetRowDataByKey(index, "MXBD_BD");

                    try
                    {
                        if (double.Parse(bd_value) != double.Parse(ys_value))//和原始值不同变色
                        {
                            (_page.GetTextBoxInGridCell(index, "MXBD_BD") as TextBox).BackColor = Color.Yellow;
                        }
                    }
                    catch (Exception)
                    {
                    }
                    

                    ys_value = "";
                    bd_value = "";

                    //---lzw 只给指标赋值
                    current_pid = _page.GetRowDataByKey(index, "ZB_ID");
                    temp = listParameter.Find(getValue);
                    if (temp != null)
                    {
                        temp_str += index + "行 指标标定赋值" + temp.U_VALUE + ";";                        
                        if (temp.CanCalculate)
                        {
                            (_page.GetTextBoxInGridCell(index, "ZB_BD") as TextBox).Text = temp.U_VALUE;
                            bd_value = temp.U_VALUE;
                        }
                        else
                        {
                            (_page.GetTextBoxInGridCell(index, "ZB_BD") as TextBox).Text = str_tips;
                            bd_value = str_tips;
                        }
                    }

                    //---lzw 根据session给原始赋值
                    
                    if (zbysnewParameter.ContainsKey(current_pid))
                    {
                        row.Cells[zb_ys].Text = zbysnewParameter[current_pid];
                        //row.ForeColor = Color.Red;
                        row.Cells[zb_ys].ForeColor = Color.Red;
                        ys_value = zbysnewParameter[current_pid];
                    }
                    else
                    {
                        ys_value = _page.GetRowDataByKey(index, "ZB_YS");
                    }

                    try
                    {
                        if (double.Parse(bd_value) != double.Parse(ys_value))//和原始值不同变色
                        {
                            (_page.GetTextBoxInGridCell(index, "ZB_BD") as TextBox).BackColor = Color.Yellow;
                        }
                    }
                    catch (Exception)
                    {
                    }

                }
        _page.ShowMessage("计算完成");
            }
            catch (System.Exception e)
            {               
                for (int m = 0; m < listParameter.Count;m++ )
                {
                    temp_str += listParameter[m].PARAMETER_ID + ":" + listParameter[m].U_VALUE + ";";
                }
                _page.ShowMessage("参数个数:" + listParameter.Count + "; 参数信息" + temp_str + ";" + strError + "; 计算出错" + e.Message);
            }
           
        }
===============HY27101btnBC===============
namespace SLSH20701 //用于HY20702中
{
    public class ClsBC : ISuwfBus
    {        
        private SlnSuwfPage _page;
        public ArrayList CheckBoxSelectedIndex = new ArrayList();//复选框勾选索引,用来勾选错误时间信息的数据行
        void ISuwfBus.Initial(SlnSuwfPage page)
        {
            this._page = page;
            _page.Load += new EventHandler(page_Load);
            PUB.BindButtonEvent(_page, "btnBC", new EventHandler(btnBC_Click));
        }        
        void page_Load(object sender, EventArgs e)
        {        }       
        void btnBC_Click(object sender, EventArgs e)
        {
            try
            {
                string strPK = _page.GetRowDataPrimaryKeys();
                if (SlnString.IsNull(strPK) == true)
                {
                    _page.ShowMessage(SlnString.ScriptAlertMessage("请先选择网格数据"));
                    return;
                }
                List<string> lstSql = new List<string>();
                string strNF = _page.GetControlValue("val_NF");
                string strYF = _page.GetControlValue("val_YF");
                if (strNF == "" && strYF != "")
                {
                    _page.ShowMessage("年份不能为空!");
                    return;
                }
                if (strYF == "" && strNF != "")
                {
                    _page.ShowMessage("月份不能为空!");
                    return;
                }
                if (strNF == "" && strYF == "")
                {
                    _page.ShowMessage("年份月份不能为空!");
                    return;
                }
                string id = string.Empty;
                string strKSJHRQ = string.Empty;//开始交货日期
                string strJZJHRQ = string.Empty;//截止交货日期
                string strMsg = string.Empty;//输出错误信息
                string strBZ = string.Empty;//备注信息
                GridView grd = _page.MainGrid;
                foreach (GridViewRow gridRow in grd.Rows)
                {
                    if (_page.GridRowIsSelected(gridRow.RowIndex))
                    {
                        id = _page.GetRowDataByKey(gridRow.RowIndex, "ID");
                        strKSJHRQ = _page.GetRowDataByKey(gridRow.RowIndex, "KSJHRQ");
                        strJZJHRQ = _page.GetRowDataByKey(gridRow.RowIndex, "JZJHRQ");
                        strBZ = _page.GetRowDataByKey(gridRow.RowIndex, "BZ");
                        int result = JudgeDate(strNF, strYF, strKSJHRQ, strJZJHRQ);//调用判断日期填写是否正确的方法
                     
                        if (result == 1)//只填写截止交货日期
                        {//更新表中的截止交货日期
                            lstSql.Add(string.Format("update cgyclyddhj_GYS_tb set jzjhrq=to_date('{0}','yyyy-mm-dd') where id = {1} ", strJZJHRQ, id));
                            lstSql.Add(string.Format("update cgyclyddhj_GYS_tb set bz='{0}' where id = {1} ", strBZ, id));
                           
                        }
                        else if (result == 2)//同时填写了开始交货日期和截止交货日期
                        {
//更新表中的开始交货日期和截止交货日期
                            lstSql.Add(string.Format("update cgyclyddhj_GYS_tb set ksjhrq=to_date('{0}','yyyy-mm-dd'),jzjhrq=to_date('{1}','yyyy-mm-dd') where id = {2} ", strKSJHRQ, strJZJHRQ, id));
                            lstSql.Add(string.Format("update cgyclyddhj_GYS_tb set bz='{0}' where id = {1} ", strBZ, id));
                         
                        }
//其他都属于输入错误的情况,将索引号获取,并输出更新错误信息输出字符串
                        else
                        {
                            strMsg = strMsg + "" + (gridRow.RowIndex + 1) + "行输入信息有误  ";
                            CheckBoxSelectedIndex.Add(gridRow.RowIndex);//将需要勾选的错误数据行加入动态数组当中                        
                        }
                    }
                }
                string SqlMsg = SlnDataAccess.ExecuteSqlTransaction(lstSql);//专门处理执行SQL批操作是出现的错误
                if (string.IsNullOrEmpty(SqlMsg))
                {
                    if (strMsg.IndexOf("") > -1)//如果包含“第”字样,说明有错误时间信息,则输出错误提示
                    {
                        this._page.ShowMessage("保存成功!其中" + strMsg);
                    }
                    else
                    {
                        this._page.ShowMessage("保存成功");//否则直接提示保存成功
                    }
                }
                else
                {
                    this._page.ShowMessage("保存出错" + strMsg);
                }
                _page.btnQuery_Click(null, null);//需要刷新一下页面,更新PU中输入的错误时间信息
                foreach (object SelectIndex in CheckBoxSelectedIndex)//遍历动态数组中的索引,挨个将复选框进行选中
                {
                    _page.SetGridRowSelected(ConvertFunction.ObjToInt32(SelectIndex), true);
                }
            }
            catch (Exception ex)
            {
                _page.ShowMessage(ex.Message);
            }
        }
    }
}
========ClsOperatePage.cs===============

namespace SLNPAGEPUB
{
    /// <summary>
    /// 页面操作公共类
    /// </summary>
    public class ClsOperatePage
    {
        public enum ForeColor
        {
            Red = 1,
            Green = 2,
            Blue = 3,
            Yellow = 4,
            White = 5,
            Black = 6,
            Null = 7,
        }
        public enum ControlType
        {
            Button = 1,
            Label = 2,
            TextBox = 3,
            DropDownList = 4,
            Null = 5,
        }
        #region 变量声明
        private SlnSuwfPage _page;
        #endregion
        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="page">程序单元</param>
        public ClsOperatePage(SlnSuwfPage page)
        {
            this._page = page;
        }
        #endregion
        #region 设置页面按钮不可见
        /// <summary>
        /// 设置页面按钮不可见
        /// </summary>
        /// <param name="ctrl"></param>
        public static void SetControlUnVisible(Control ctrl)
        {
            if (ctrl.UniqueID.IndexOf("btn") >= 0)
            {
                ctrl.Visible = false;
                return;
            }
            foreach (Control c in ctrl.Controls)
            {
                ClsOperatePage.SetControlUnVisible(c);
            }
        }
        #endregion
        #region 打印Excel模板
        /// <summary>
        /// 打印Excel模板
        /// </summary>
        /// <param name="page">平台页面</param>
        /// <param name="templateName">模板名称</param>
        /// <param name="key">数据主键</param>
        /// <param name="isPrint">设置是打印还是预览</param>
        /// <returns></returns>
        public static string PrintExcel(SlnSuwfPage page, string templateName, string key, bool isPrint)
        {
            string strMsg = string.Empty;
            string strSql = string.Empty;

            if (string.IsNullOrEmpty(templateName)) return "";

            try
            {
                DataSet ds = new DataSet();

                strSql = "SELECT TABLENAME, QUERYSQL FROM XT_DYXD_TB WHERE TEMPLATENAME = '" + templateName + "'";

                DataTable table = SlnDataAccess.GetDataTable(strSql);

                foreach (DataRow row in table.Rows)
                {
                    string strTableName = row[0].ToString();
                    string strQuerySql = row[1].ToString();

                    strQuerySql = strQuerySql.Replace("{$PKValue$}", key);

                    DataTable dt = SlnDataAccess.GetDataTable(strQuerySql);

                    dt.TableName = strTableName;
                    dt.PrimaryKey = new DataColumn[] { dt.Columns[0] };
                    ds.Tables.Add(dt.Copy());
                }

                //strMsg += Salien.Utility.SUWF.ClsPrintExcel.ExportExcel(page.Unit.ProgUnit.PU_BM, ds, templateName + ".xls", true, "", "");
                strMsg += Salien.Utility.SUWF.ClsPrintExcel.ExportExcel(page.Unit.ProgUnit.PU_BM, ds, templateName + ".xls", true, "", "", "", "Portrait=false&IsPreView=" + (!isPrint).ToString().ToLower());

                return strMsg;
            }
            catch (Exception err)
            {
                return err.Source + " " + err.Message;
            }
        }
        #endregion
        #region 打印Excel模板
        /// <summary>
        /// 打印Excel模板
        /// </summary>
        /// <param name="page">平台页面</param>
        /// <param name="templateName">模板名称</param>
        /// <param name="key">数据主键</param>
        /// <returns></returns>
        public static string PrintExcel(SlnSuwfPage page, string templateName, string key)
        {
            string strMsg = string.Empty;
            string strSql = string.Empty;

            if (string.IsNullOrEmpty(templateName)) return "";

            try
            {
                DataSet ds = new DataSet();

                strSql = "SELECT TABLENAME, QUERYSQL FROM XT_DYXD_TB WHERE TEMPLATENAME = '" + templateName + "'";

                DataTable table = SlnDataAccess.GetDataTable(strSql);

                foreach (DataRow row in table.Rows)
                {
                    string strTableName = row[0].ToString();
                    string strQuerySql = row[1].ToString();

                    strQuerySql = strQuerySql.Replace("{$PKValue$}", key);

                    DataTable dt = SlnDataAccess.GetDataTable(strQuerySql);

                    dt.TableName = strTableName;
                    dt.PrimaryKey = new DataColumn[] { dt.Columns[0] };
                    ds.Tables.Add(dt.Copy());
                }

                strMsg += Salien.Utility.SUWF.ClsPrintExcel.ExportExcel(page.Unit.ProgUnit.PU_BM, ds, templateName + ".xls", true);
                //strMsg += Salien.Utility.SUWF.ClsPrintExcel.ExportExcel(page.Unit.ProgUnit.PU_BM, ds, templateName + ".xls", true, "HTML");

                return strMsg;
            }
            catch (Exception err)
            {
                return err.Source + " " + err.Message;
            }
        }
        #endregion
        #region 导出Excel模板
        /// <summary>
        /// 导出Excel模板
        /// </summary>
        /// <param name="page">平台页面</param>
        /// <param name="templateName">模板名称</param>
        /// <param name="key">数据主键</param>
        /// <returns></returns>
        public static string ExportExcel(SlnSuwfPage page, string templateName, string key)
        {
            string strMsg = string.Empty;
            string strSql = string.Empty;

            if (string.IsNullOrEmpty(templateName)) return "";

            try
            {
                DataSet ds = new DataSet();

                strSql = "SELECT TABLENAME, QUERYSQL FROM XT_DYXD_TB WHERE TEMPLATENAME = '" + templateName + "'";

                DataTable table = SlnDataAccess.GetDataTable(strSql);

                foreach (DataRow row in table.Rows)
                {
                    string strTableName = row[0].ToString();
                    string strQuerySql = row[1].ToString();

                    strQuerySql = strQuerySql.Replace("{$PKValue$}", key);

                    DataTable dt = SlnDataAccess.GetDataTable(strQuerySql);

                    dt.TableName = strTableName;
                    dt.PrimaryKey = new DataColumn[] { dt.Columns[0] };
                    ds.Tables.Add(dt.Copy());
                }

                //strMsg += Salien.Utility.SUWF.ClsPrintExcel.ExportExcel(page.Unit.ProgUnit.PU_BM, ds, templateName + ".xls", false, "", "");
                strMsg += Salien.Utility.SUWF.ClsPrintExcel.ExportExcel(page.Unit.ProgUnit.PU_BM, ds, templateName + ".xls", false, "", "", "", "");

                return strMsg;
            }
            catch (Exception err)
            {
                return err.Source + " " + err.Message;
            }
        }
        #endregion
        #region 关闭页面
        /// <summary>
        /// 关闭页面
        /// </summary>
        public void CloseWindow()
        {
            string strJS = "<script type='text/javascript'>"
                    + "window.close();"
                    + "</script>";
            this._page.Response.Write(strJS);
        }
        #endregion
        #region 刷新父页面
        /// <summary>
        /// 刷新父页面
        /// </summary>
        public void RefreshParentWindow()
        {
            string strJS = "<script type='text/javascript'>"

                + "var pWindow = window.parent.parent;"
                + "if(pWindow != null && pWindow.gridframe != null && pWindow.gridframe.document.all.btnQuery != null)"
                + "{pWindow.gridframe.document.all.btnQuery.click();}"

                + "pWindow = window.parent.parent.parent.parent;"
                + "if(pWindow != null && pWindow.gridframe != null && pWindow.gridframe.document.all.btnQuery != null)"
                + "{pWindow.gridframe.document.all.btnQuery.click();}"

                + "</script>";

            this._page.Response.Write(strJS);
        }
        #endregion
        #region 刷新父页面
        /// <summary>
        /// 刷新父页面
        /// </summary>
        public void RefreshParentWindow(bool ModalWindow)
        {
            if (ModalWindow == true)
            {
                string strJS = "<script type='text/javascript'>"
                            + "var pWindow = window.opener.parent.parent.parent;"
                            + "if(pWindow != null && pWindow.gridframe != null && pWindow.gridframe.document.all.btnQuery != null)"
                            + "{pWindow.gridframe.document.all.btnQuery.click();}"
                            + "pWindow = window.opener.parent.parent;"
                            + "if(pWindow != null && pWindow.gridframe != null && pWindow.gridframe.document.all.btnQuery != null)"
                            + "{pWindow.gridframe.document.all.btnQuery.click();}"
                            + "pWindow = window.opener.parent.parent.parent.parent;"
                            + "if(pWindow != null && pWindow.gridframe != null && pWindow.gridframe.document.all.btnQuery != null)"
                            + "{pWindow.gridframe.document.all.btnQuery.click();}"

                            + "pWindow = window.opener.parent;"
                            + "if(pWindow != null)"
                            + "{pWindow.document.location.reload();}"

                            + "</script>";

                this._page.Response.Write(strJS);
            }
        }
        #endregion
        #region 刷新子页面
        /// <summary>
        /// 刷新子页面
        /// </summary>
        public void RefreshChildWindow()
        {
            string strJS = "<script type='text/javascript'>"
                    + "var pWindow = window.parent;"
                    + "if(pWindow != null && pWindow.cardframe != null && pWindow.cardframe.subinfoframe.gridframe != null && pWindow.cardframe.subinfoframe.gridframe.document.all.btnQuery != null)"
                    + "{pWindow.cardframe.subinfoframe.gridframe.document.all.btnQuery.click();}"

                    + "else if(pWindow != null && pWindow.cardframe != null)"
                    + "{window.parent.cardframe.document.location.reload();}"
                    + "</script>";
            this._page.Response.Write(strJS);
        }
        #endregion
        #region 设置页面不被缓存
        /// <summary>
        /// 设置页面不被缓存
        /// </summary>
        public void SetPageNoCache()
        {
            this._page.Response.Buffer = true;
            this._page.Page.Response.Cache.SetNoStore();
        }
        #endregion
        #region 返回当前网格数据选中行里指定字段为空的行号,行号之间以逗号分割。
        /// <summary>
        /// 返回当前网格数据选中行里指定字段为空的行号,行号之间以逗号分割。
        /// </summary>
        /// <param name="field">要检索的字段</param>
        /// <returns></returns>
        public string SelectedRowsWithXFieldIsNull(string field)
        {
            string rows = string.Empty;

            for (int i = 0; i < this._page.GridData.Rows.Count; i++)
            {
                if (this._page.GridRowIsSelected(i))
                {
                    if (string.IsNullOrEmpty(this._page.GetRowDataByKey(i, field)))
                    {
                        rows += i.ToString() + ",";
                    }
                }
            }

            rows = rows.TrimEnd(',');

            return rows;
        }
        #endregion
        #region 返回当前网格数据选中行里指定字段为空的行号,行号之间以逗号分割。
        /// <summary>
        /// 返回当前网格数据选中行里指定字段为空的行号,行号之间以逗号分割。
        /// </summary>
        /// <param name="field">要检索的字段。</param>
        /// <param name="isStartWithZero">指定返回的行号是否从零开始。</param>
        /// <returns></returns>
        public string SelectedRowsWithXFieldIsNull(string field, bool isStartWithZero)
        {
            string rows = string.Empty;

            for (int i = 0; i < this._page.GridData.Rows.Count; i++)
            {
                if (this._page.GridRowIsSelected(i))
                {
                    if (string.IsNullOrEmpty(this._page.GetRowDataByKey(i, field)))
                    {
                        rows += i.ToString() + ",";
                    }
                }
            }

            rows = rows.TrimEnd(',');

            if (isStartWithZero == false)
            {
                string[] arr = rows.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                for (int i = 0; i < arr.Length; i++)
                {
                    arr[i] = Convert.ToString(Int32.Parse(arr[i]) + 1);
                }

                rows = string.Empty;

                for (int i = 0; i < arr.Length; i++)
                {
                    rows += arr[i] + ",";
                }

                rows = rows.TrimEnd(',');
            }

            return rows;
        }
        #endregion
        #region 获取当前网格数据中选中的行号,行号之间以逗号分割。
        /// <summary>
        /// 获取当前网格数据中选中的行号,行号之间以逗号分割。
        /// </summary>
        /// <returns></returns>
        public string GetSelectedRows()
        {
            string rows = string.Empty;

            for (int i = 0; i < this._page.GridData.Rows.Count; i++)
            {
                if (this._page.GridRowIsSelected(i))
                {
                    rows += i.ToString() + ",";
                }
            }

            rows = rows.TrimEnd(',');

            return rows;
        }
        #endregion
        #region 保存网格数据。
        /// <summary>
        /// 保存网格数据。
        /// </summary>
        public void SaveGridData()
        {
            this._page.btnSave_Click(null, null);
        }
        #endregion
        #region 保存网格数据。
        /// <summary>
        /// 保存网格数据。
        /// </summary>
        /// <param name="isRestoreTickState">指示保存操作完成之后,是否需要恢复网格多选框的选中状态。</param>
        public void SaveGridData(bool isRestoreTickState)
        {
            try
            {
                if (isRestoreTickState == false)
                {
                    this._page.btnSave_Click(null, null);
                }
                else
                {
                    string strKeys = this._page.GetRowDataPrimaryKeys();

                    this._page.btnSave_Click(null, null);

                    string[] arrKeys = strKeys.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                    string strPU = this._page.Unit.ProgUnit.PU_BM;
                    string strPK = SlnDataAccess.GetValueBySql("SELECT FLD_KEY FROM SUF_FIELD_TB WHERE FLD_ISPRIMKEY = 1 AND PU_BM = " + strPU).ToString();

                    for (int i = 0; i < arrKeys.Length; i++)
                    {
                        for (int j = 0; j < this._page.GridData.Rows.Count; j++)
                        {
                            if (this._page.GetRowDataByKey(j, strPK) == arrKeys[i])
                            {
                                this._page.SetGridRowSelected(j, true);
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Source + " " + ex.Message);
            }
        }
        #endregion
        #region 设置网格单元格样式。
        /// <summary>
        /// 设置网格单元格样式。
        /// </summary>
        /// <param name="field">指定需要设置样式的网格字段名。</param>
        /// <param name="condition">指定设置样式的条件。</param>
        /// <param name="cellControlType">指定单元格的控件类型。</param>
        /// <param name="cellForeColor">设置单元格的前景色。</param>
        /// <param name="cellEnabled">设置单元格是否只读。</param>
        public void SetGridFieldStyle(string field, string condition, ControlType cellControlType, ForeColor cellForeColor, bool cellEnabled)
        {
            try
            {
                GridView grid = this._page.FindControl("grdTest") as GridView;

                foreach (GridViewRow row in grid.Rows)
                {
                    string strPU = this._page.Unit.ProgUnit.PU_BM;
                    string strPKField = SlnDataAccess.GetValueBySql("SELECT FLD_KEY FROM SUF_FIELD_TB WHERE FLD_ISPRIMKEY = 1 AND PU_BM = " + strPU).ToString();
                    string strPKValue = this._page.GetRowDataByKey(row.RowIndex, strPKField);
                    string strSql = string.Empty;

                    if (string.IsNullOrEmpty(condition))
                    {
                        strSql = "SELECT 1 FROM (" + this._page.GetQuerySql() + ") WHERE " + strPKField + "=" + strPKValue;
                    }
                    else
                    {
                        strSql = "SELECT 1 FROM (" + this._page.GetQuerySql() + ") WHERE " + strPKField + "=" + strPKValue + " AND " + condition;
                    }

                    object obj = SlnDataAccess.GetValueBySql(strSql);

                    if (obj != null)
                    {
                        if (!string.IsNullOrEmpty(field))
                        {
                            if (cellControlType != ControlType.Null)
                            {
                                if (cellEnabled == true)
                                {
                                    switch (cellControlType)
                                    {
                                        case ControlType.TextBox:
                                            switch (cellForeColor)
                                            {
                                                case ForeColor.Red: this._page.GetTextBoxInGridCell(row.RowIndex, field).ForeColor = Color.Red; break;
                                                case ForeColor.Green: this._page.GetTextBoxInGridCell(row.RowIndex, field).ForeColor = Color.Green; break;
                                                case ForeColor.Blue: this._page.GetTextBoxInGridCell(row.RowIndex, field).ForeColor = Color.Blue; break;
                                                case ForeColor.Yellow: this._page.GetTextBoxInGridCell(row.RowIndex, field).ForeColor = Color.Yellow; break;
                                                default: break;
                                            }
                                            this._page.GetTextBoxInGridCell(row.RowIndex, field).Attributes.Add("readonly", "false"); break;
                                        default:
                                            switch (cellForeColor)
                                            {
                                                case ForeColor.Red: row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey(field)].ForeColor = Color.Red; break;
                                                case ForeColor.Green: row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey(field)].ForeColor = Color.Green; break;
                                                case ForeColor.Blue: row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey(field)].ForeColor = Color.Blue; break;
                                                case ForeColor.Yellow: row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey(field)].ForeColor = Color.Yellow; break;
                                                default: break;
                                            }
                                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey(field)].Enabled = true; break;
                                    }
                                }
                                else
                                {
                                    switch (cellControlType)
                                    {
                                        case ControlType.TextBox:
                                            switch (cellForeColor)
                                            {
                                                case ForeColor.Red: this._page.GetTextBoxInGridCell(row.RowIndex, field).ForeColor = Color.Red; break;
                                                case ForeColor.Green: this._page.GetTextBoxInGridCell(row.RowIndex, field).ForeColor = Color.Green; break;
                                                case ForeColor.Blue: this._page.GetTextBoxInGridCell(row.RowIndex, field).ForeColor = Color.Blue; break;
                                                case ForeColor.Yellow: this._page.GetTextBoxInGridCell(row.RowIndex, field).ForeColor = Color.Yellow; break;
                                                default: break;
                                            }
                                            this._page.GetTextBoxInGridCell(row.RowIndex, field).Attributes.Add("readonly", "true"); break;
                                        default:
                                            switch (cellForeColor)
                                            {
                                                case ForeColor.Red: row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey(field)].ForeColor = Color.Red; break;
                                                case ForeColor.Green: row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey(field)].ForeColor = Color.Green; break;
                                                case ForeColor.Blue: row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey(field)].ForeColor = Color.Blue; break;
                                                case ForeColor.Yellow: row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey(field)].ForeColor = Color.Yellow; break;
                                                default: break;
                                            }
                                            row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey(field)].Enabled = false; break;
                                    }
                                }
                            }
                            else
                            {
                                if (cellEnabled == true)
                                {
                                    row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey(field)].Enabled = true;
                                }
                                else
                                {
                                    row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey(field)].Enabled = false;
                                }
                                switch (cellForeColor)
                                {
                                    case ForeColor.Red: row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey(field)].ForeColor = Color.Red; break;
                                    case ForeColor.Green: row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey(field)].ForeColor = Color.Green; break;
                                    case ForeColor.Blue: row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey(field)].ForeColor = Color.Blue; break;
                                    case ForeColor.Yellow: row.Cells[this._page.Unit.ProgUnit.FieldList.GetIndexByKey(field)].ForeColor = Color.Yellow; break;
                                    default: break;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Source + " " + ex.Message);
            }
        }
        #endregion
    }
}
namespace SM5604btnCGRK
{
    public class SM5604btnCGRK : ISuwfBus
    {
        private SlnSuwfPage _page;
        void ISuwfBus.Initial(SlnSuwfPage page)
        {
            _page = page;
            PUB.BindButtonEvent(_page, "btnCGRK", BtnCGRK_Click);
        }

        #region 采购入库
        private void BtnCGRK_Click(object sender, EventArgs e)
        {
            string pks = _page.GetRowDataPrimaryKeys();
            if (SlnString.IsNull(pks) == true)
            {
                _page.ShowMessage("没有选中网格");
                return;
            }

            if (SlnDataAccess.GetDataTableCount(
                $"select id from sm_kc_ckrkb_tb where cgzbid in ({pks})") > 0)
            {
                _page.ShowMessage("存在已经入库的采购记录");
                return;
            }
            List<string> lstDJBH = new List<string>();
            GridView grd = _page.MainGrid;
            string strMsg = "";

            foreach (GridViewRow gridRow in grd.Rows)
            {
                if (_page.GridRowIsSelected(gridRow.RowIndex))
                {
                    if (_page.GetRowDataByKey(gridRow.RowIndex, "CKID") == "39")/*外购成品库*/
                    {
                        continue;
                    }
                    if (_page.GetRowDataByKey(gridRow.RowIndex, "RKLB") == "9")/*红单*/
                    {
                        continue;
                    }
                    if (ConvertFunction.ObjToDouble(_page.GetRowDataByKey(gridRow.RowIndex, "JE")) < 1000.0)
                    {
                        continue;
                    }
                    if (_page.GetRowDataByKey(gridRow.RowIndex, "XTWLLBID") == "10")/*电化铝*/
                    {
                        continue;
                    }
                    if (_page.GetRowDataByKey(gridRow.RowIndex, "WLID") == "79071")/*外购成品*/
                    {
                        continue;
                    }
                    if (ConvertFunction.ObjToDouble(_page.GetRowDataByKey(gridRow.RowIndex, "TPSL")) > 0.0)
                    {
                        continue;
                    }
                    strMsg = strMsg + "" + (gridRow.RowIndex + 1) + "行需要上传图片";
                }
            }

            //如果包含“第”字样,说明有错误时间信息,则输出错误提示
            if (strMsg.IndexOf("") > -1)
            {
                _page.ShowMessage(strMsg);
                return;
            }

            foreach (GridViewRow gridRow in grd.Rows)
            {
                if (_page.GridRowIsSelected(gridRow.RowIndex))
                {
                    if (_page.GetRowDataByKey(gridRow.RowIndex, "ZT") == "0")
                    {
                        _page.ShowMessage($"第{gridRow.RowIndex + 1}行还没有登记无法做入库;");
                        return;
                    }
                    if (_page.GetRowDataByKey(gridRow.RowIndex, "ZT") == "2")
                    {
                        _page.ShowMessage($"第{gridRow.RowIndex + 1}行已经入库了不能再次做入库");
                        return;
                    }
                    if (_page.GetRowDataByKey(gridRow.RowIndex, "SSSL") == "0")
                    {
                        _page.ShowMessage($"第{gridRow.RowIndex + 1}行的入库数量为空不能提交,请录入入库数并点击保存按钮");
                        return;
                    }
                    AddUniqueDJBH(lstDJBH, _page.GetRowDataByKey(gridRow.RowIndex, "DJBH"));
                }
            }

            string sql = $@"insert into sm_kc_ckrkb_tb(id,WLID,SSSL,DDID,PCID,GYSID,CKMC,DJLX,CGZBID,DJ,JE,ZDSJ
              ,RKRQ,ZDR,CGY,ZTZD) select seqSM_KC_CKRKB.nextval,WLID,SSSL,SCDDMXID
               ,SCDDMXID,GYSID,CKID,RKLB,ID,JHDJ,JHDJ*SSSL,sysdate,sysdate,CZRID,CZRID,1 
               from SM_CG_CGZB_TB where id in ({pks})";
            try
            {
                string msg = SlnDataAccess.ExecuteSQL(sql);

                if (msg == "")
                {
                    _page.ShowMessage("采购入库成功");

                    SlnDataAccess.ExecuteProcedure("SM5604btnCGRKFX_SP('" + string.Join(",", lstDJBH) + "','" +
                      pks + "')");

                    _page.btnQuery_Click(null, null);
                    return;
                }
                else
                {
                    _page.ShowMessage("采购入库成功");
                    return;
                }
            }
            catch (Exception ex)
            {
                this._page.ShowMessage(ex.Message);
            }
        }

        #endregion

        #region SFSCTP 是否上传图片  
        private int SFSCTP(string CGZBID)
        {
            string sql = "SELECT WLID, ZT,JE,RKLB,(SELECT XTWLLBID FROM SM_ZDB_XTWL_TB T WHERE T.ID=ZB.WLID) as XTWLLBID,"
            + " (SELECT COUNT(FJ.ID)  From SM_CG_ZJFJ_TB FJ Where FJ.CGZBID=ZB.ID) as TPJLSL "
            + " FROM SM_CG_CGZB_TB ZB Where ZB.ID='" + CGZBID + "'";
            DataTable dt = SlnDataAccess.GetDataTable(sql);

            int is_success = 0;
            if (dt.Rows.Count > 0)
            {
                if (ConvertFunction.ObjToInt32(dt.Rows[0]["RKLB"]) != 9 && ConvertFunction.ObjToInt32(dt.Rows[0]["ZT"]) != 2
                    && ConvertFunction.ObjToDouble(dt.Rows[0]["JE"]) > 1000 && ConvertFunction.ObjToInt32(dt.Rows[0]["XTWLLBID"]) != 10
                    && ConvertFunction.ObjToInt32(dt.Rows[0]["WLID"]) != 79071 && ConvertFunction.ObjToInt32(dt.Rows[0]["TPJLSL"]) < 2)
                {/*wlid=79071 外购成品 不需要上传图片*/
                    is_success = 1;/*等于1 需要上传图片*/
                }
            }
            return is_success;
        }
        #endregion

        #region ReturnJson
        private string ReturnJson(string DJBHList, string CGZBIDList)
        {
            SortedList mySL = new SortedList
            {
              {"DJBHList",DJBHList},{ "CGZBIDList",CGZBIDList}
            };
            return SortedListToWxJson(mySL); ;
        }
        #endregion

        #region SortedList表转JSON方法
        public string SortedListToWxJson(SortedList mySL)
        {
            try
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.Append("{");
                foreach (DictionaryEntry e in mySL)
                {
                    object value = e.Value;
                    sb.Append("\"");
                    sb.Append(e.Key);
                    sb.Append("\":\"");
                    if (!String.IsNullOrEmpty(value.ToString()) && value != DBNull.Value)
                    {
                        sb.Append(value).Replace("\\", "/");
                    }
                    else
                    {
                        sb.Append("");
                    }
                    sb.Append("\",");
                }
                sb = sb.Remove(sb.Length - 1, 1);
                sb.Append("}");
                return sb.ToString();
            }
            catch (Exception)
            {
                return "";
            }
        }
        #endregion
        void AddUniqueDJBH(List<string> lstDJBH, string DJBH)
        {
            if (!lstDJBH.Contains(DJBH))
            {
                lstDJBH.Add(DJBH);
            }
        }
    }
}

 

posted @ 2025-08-13 15:31  知行一体2  阅读(5)  评论(0)    收藏  举报