using System; 
 | 
using System.Collections.Generic; 
 | 
using System.ComponentModel; 
 | 
using System.Data; 
 | 
using System.Drawing; 
 | 
using System.Linq; 
 | 
using System.Text; 
 | 
using System.Windows.Forms; 
 | 
  
 | 
namespace BLL 
 | 
{ 
 | 
    public partial class Xt_SystemParameterForOrg : Form 
 | 
    { 
 | 
        public Xt_SystemParameterForOrg() 
 | 
        { 
 | 
            InitializeComponent(); 
 | 
        } 
 | 
  
 | 
        public const int HInterIDCol = 0; 
 | 
        public const int HKeyCol = 1; 
 | 
        public const int HOrgIDCol = 2; 
 | 
        public const int HOrgNumberCol = 3; 
 | 
        public const int HOrgNameCol = 4; 
 | 
        public const int HValueCol = 5; 
 | 
        public string sHKey; 
 | 
  
 | 
        private void timer1_Tick(object sender, EventArgs e) 
 | 
        { 
 | 
            timer1.Enabled = false; 
 | 
            initGrid(); 
 | 
            Display(); 
 | 
        } 
 | 
  
 | 
        private void initGrid() 
 | 
        { 
 | 
            // 
 | 
            grdMain.ColumnCount = 6;                       //总列数 
 | 
            DBUtility.Xt_BaseBillFun.initGridFst(grdMain, this.Name); 
 | 
            //= 
 | 
            grdMain.Columns[HOrgNumberCol].HeaderText = "组织代码"; 
 | 
            grdMain.Columns[HOrgNameCol].HeaderText = "组织名称"; 
 | 
            grdMain.Columns[HValueCol].HeaderText = "参数值"; 
 | 
            ////固定赋值===================================================== 
 | 
            //============================================================================= 
 | 
            //格式化  
 | 
  
 | 
            //设置 手工隐藏 
 | 
            DBUtility.ClsPub.HideGridView(grdMain, Name, DBUtility.ClsPub.AppPath);//设置隐藏列 
 | 
            ////隐藏列 
 | 
            grdMain.Columns[HInterIDCol].Visible = false; 
 | 
            grdMain.Columns[HKeyCol].Visible = false; 
 | 
            grdMain.Columns[HOrgIDCol].Visible = false;  
 | 
            //隐藏源单信息  
 | 
            //设置可编辑列 
 | 
            string sAllowCol = HValueCol.ToString() ; 
 | 
            //设置合计列 
 | 
            string sTotalCol = ""; 
 | 
            //格式化网格 
 | 
            //DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol, oSumGrid); 
 | 
            DBUtility.Xt_BaseBillFun.GetGrid(grdMain, this.Name); 
 | 
        } 
 | 
  
 | 
        private void Display() 
 | 
        { 
 | 
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); 
 | 
            try 
 | 
            { 
 | 
                //根据 HKEY 来获取 现有信息 
 | 
                DataSet ds = oCn.RunProcReturn("exec h_p_Xt_SystemParameter_GetValue '" + sHKey + "'", "h_p_Xt_SystemParameter_GetValue"); 
 | 
                if(ds==null) 
 | 
                { 
 | 
                    MessageBox.Show("读取失败1!没有返回任何数据!"); 
 | 
                    return; 
 | 
                } 
 | 
                if (ds.Tables[0].Rows.Count != 0) 
 | 
                { 
 | 
                    //显示到 表头  
 | 
                    txtHKey.Text = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HKey"]); 
 | 
                    txtHCaption.Text = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HCaption"]); 
 | 
                    txtHValue.Text = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HMainValue"]); 
 | 
                    txtHExplanation.Text = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HExplanation"]); 
 | 
                    txtHFarmat.Text = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HFarmat"]); 
 | 
                } 
 | 
                else 
 | 
                { 
 | 
                    MessageBox.Show("读取失败2!没有返回任何数据!"); 
 | 
                    return; 
 | 
                } 
 | 
                //显示到 表体   
 | 
                grdMain.RowCount = ds.Tables[0].Rows.Count; 
 | 
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++) 
 | 
                { 
 | 
                    if (i >= grdMain.RowCount - 1) 
 | 
                        grdMain.Rows.Add(); 
 | 
                    //单据固定赋值 
 | 
                    grdMain.Rows[i].Cells[HInterIDCol].Value = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["HInterID"]); 
 | 
                    grdMain.Rows[i].Cells[HKeyCol].Value = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HKey"]); 
 | 
                    grdMain.Rows[i].Cells[HOrgIDCol].Value = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["HOrgID"]); 
 | 
                    grdMain.Rows[i].Cells[HOrgNumberCol].Value = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HOrgNumber"]); 
 | 
                    grdMain.Rows[i].Cells[HOrgNameCol].Value = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HOrgName"]); 
 | 
                    grdMain.Rows[i].Cells[HValueCol].Value = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HValue"]); 
 | 
                } 
 | 
            } 
 | 
            catch(Exception e1) 
 | 
            { 
 | 
                MessageBox.Show("读取失败!" + e1.Message); 
 | 
  
 | 
            } 
 | 
  
 | 
        } 
 | 
  
 | 
        private void cmdCancel_Click(object sender, EventArgs e) 
 | 
        { 
 | 
            DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name); 
 | 
            this.Close(); 
 | 
        } 
 | 
  
 | 
        private void cmdOK_Click(object sender, EventArgs e) 
 | 
        { 
 | 
            //保存前判断 
 | 
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); 
 | 
  
 | 
            try 
 | 
            { 
 | 
                //清除 子表信息 
 | 
                oCn.RunProc(" delete from Xt_SystemParameterSub Where HKey= '" + sHKey + "'"); 
 | 
                //循环写入子表 
 | 
                for (int i = 0; i < grdMain.Rows.Count; i++) 
 | 
                { 
 | 
                    if (DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HValueCol].Value).ToString() !="" && 
 | 
                         DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HKeyCol].Value).ToString() !="") 
 | 
                    { 
 | 
                        oCn.RunProc(" insert into  Xt_SystemParameterSub (HInterID,HValue,HKey,HOrgID) " + 
 | 
                            " values(  " + 
 | 
                            "  " + DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HInterIDCol].Value).ToString() + " " + 
 | 
                            ",  '" + DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HValueCol].Value).ToString() + "' " + 
 | 
                            ",  '" + DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HKeyCol].Value).ToString() + "' " + 
 | 
                            ",  " + DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HOrgIDCol].Value).ToString() + " " + 
 | 
                            ") "); 
 | 
                    } 
 | 
                } 
 | 
                MessageBox.Show("保存完毕!"); 
 | 
            } 
 | 
            catch(Exception e1) 
 | 
            { 
 | 
                MessageBox.Show("保存失败!"+ e1.Message); 
 | 
  
 | 
            } 
 | 
        } 
 | 
  
 | 
        private void grdMain_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) 
 | 
        { 
 | 
            int i = grdMain.CurrentCell.ColumnIndex; 
 | 
            if (i == HKeyCol || i == HOrgNumberCol || i == HOrgNameCol) 
 | 
            { 
 | 
                e.Cancel = true; 
 | 
            } 
 | 
        } 
 | 
    } 
 | 
} 
 |