Exemplo n.º 1
0
Arquivo: GNLB.cs Projeto: LGpan/myGit
        //private string code = null;
        //private string name = null;
        //private string zygn = null;
        //private string pt = null;
        //private string lx = null;
        //private string createDate = null;
        //private string cjyh = null;
        //private string updateDate = null;
        //private string gxyh = null;
        //private string xt = null;

        //查询
        private void button1_Click(object sender, EventArgs e)
        {
            GNLBEntity    gnlb = new GNLBEntity();
            string        lsSql;
            StringBuilder sql = new StringBuilder();

            gnlb.code = tbCode.Text.Trim();
            gnlb.name = tbName.Text.Trim();
            gnlb.zygn = tbZYGN.Text.Trim();
            gnlb.pt   = tbPT.Text.Trim();
            gnlb.xt   = cbTX.Text.Trim();
            //createDate = tbCode.Text.Trim();
            //cjyh = tbCode.Text.Trim();
            //updateDate = tbCode.Text.Trim();
            gnlb.gxyh = tbGXYH.Text.Trim();
            sql.Append("Select t10.XT,t10.Code,t10.Name,t10.ZYGN,t10.PT,t10.LX,t10.CreateDate,t10.CJYH,t10.UpdateDate,t10.GXYH from PMP000101 t10 where 1=1 ");
            //lsSql = "Select t10.XT,t10.Code,t10.Name,t10.ZYGN,t10.PT,t10.LX,t10.CreateDate,t10.CJYH,t10.UpdateDate,t10.GXYH from PMP000101 t10";
            if (!string.IsNullOrEmpty(gnlb.code))
            {
                sql.Append(" and Code like '%" + gnlb.code + "%'");
            }
            if (!string.IsNullOrEmpty(gnlb.name))
            {
                sql.Append(" and Name like '%" + gnlb.name + "%'");
            }
            if (!string.IsNullOrEmpty(gnlb.zygn))
            {
                sql.Append(" and ZYGN like '%" + gnlb.zygn + "%'");
            }
            if (!string.IsNullOrEmpty(gnlb.pt))
            {
                sql.Append(" and PT like '%" + gnlb.pt + "%'");
            }
            if (!string.IsNullOrEmpty(gnlb.createDate))
            {
                sql.Append(" and CreateDate like '%" + gnlb.createDate + "%'");
            }
            if (!string.IsNullOrEmpty(gnlb.gxyh))
            {
                sql.Append(" and GXYH like '%" + gnlb.gxyh + "%'");
            }
            if (!string.IsNullOrEmpty(gnlb.xt))
            {
                sql.Append(" and GXYH like '%" + gnlb.xt + "%'");
            }
            SqlHelperXhf loSqlHelperXhf = new SqlHelperXhf(Comm.ConnStringFrom);

            lsSql = sql.ToString();
            DataTable loDt = loSqlHelperXhf.ExecuteDataTable(lsSql);

            dataGridView1.Columns["XT"].DataPropertyName         = "XT";
            dataGridView1.Columns["Code"].DataPropertyName       = "Code";
            dataGridView1.Columns["U_Name"].DataPropertyName     = "Name";
            dataGridView1.Columns["ZYGN"].DataPropertyName       = "ZYGN";
            dataGridView1.Columns["PT"].DataPropertyName         = "PT";
            dataGridView1.Columns["GNLX"].DataPropertyName       = "LX";
            dataGridView1.Columns["CreateDate"].DataPropertyName = "CreateDate";
            dataGridView1.Columns["CJYH"].DataPropertyName       = "CJYH";
            dataGridView1.Columns["UpdateDate"].DataPropertyName = "UpdateDate";
            dataGridView1.Columns["GXYH"].DataPropertyName       = "GXYH";

            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource          = loDt;
        }
Exemplo n.º 2
0
Arquivo: GNLB.cs Projeto: LGpan/myGit
        //保存
        private void button2_Click(object sender, EventArgs e)
        {
            GNLBEntity    gnlb     = new GNLBEntity();
            string        lsSql    = string.Empty;
            StringBuilder loString = new StringBuilder();

            try
            {
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    if (dataGridView1.Rows[i].Cells["SC"].Value == null)  //第一次 都是null
                    {
                        dataGridView1.Rows[i].Cells["SC"].Value = "0";
                    }
                    if (dataGridView1.Rows[i].Cells["SC"].Value.ToString() == "1")
                    {
                        gnlb.code       = dataGridView1.Rows[i].Cells["Code"].Value.ToString();
                        gnlb.name       = dataGridView1.Rows[i].Cells["U_Name"].Value.ToString();
                        gnlb.zygn       = dataGridView1.Rows[i].Cells["ZYGN"].Value.ToString();
                        gnlb.xt         = dataGridView1.Rows[i].Cells["XT"].Value.ToString();
                        gnlb.pt         = dataGridView1.Rows[i].Cells["PT"].Value.ToString();
                        gnlb.lx         = dataGridView1.Rows[i].Cells["GNLX"].Value.ToString();
                        gnlb.createDate = dataGridView1.Rows[i].Cells["CreateDate"].Value.ToString();
                        gnlb.cjyh       = dataGridView1.Rows[i].Cells["CJYH"].Value.ToString();
                        gnlb.gxyh       = dataGridView1.Rows[i].Cells["GXYH"].Value.ToString();
                        if (string.IsNullOrEmpty(gnlb.code))
                        {
                            throw new Exception("功能代码不能为空");
                        }
                        if (string.IsNullOrEmpty(gnlb.name))
                        {
                            throw new Exception("功能名称不能为空");
                        }
                        if (string.IsNullOrEmpty(gnlb.pt))
                        {
                            throw new Exception("平台不能为空");
                        }
                        if (string.IsNullOrEmpty(gnlb.cjyh))
                        {
                            throw new Exception("创建用户不能为空");
                        }
                        string       sql            = "Select count(*) from PMP000101 t10 where Code='" + gnlb.code + "' ";
                        SqlHelperXhf loSqlHelperXhf = new SqlHelperXhf(Comm.ConnStringFrom);

                        if (Convert.ToInt32(loSqlHelperXhf.ExecuteScalar(sql)) == 0)
                        {
                            lsSql = @"Insert into PMP000101(Code,Name,XT,ZYGN,PT,LX,CreateDate,UpdateDate,CJYH,GXYH) values
                          ('" + gnlb.code + "','" + gnlb.name + "','" + gnlb.xt + "','" + gnlb.zygn + "','" + gnlb.pt + "','" + gnlb.lx + "','" + System.DateTime.Now + "','','" + gnlb.cjyh + "','" + gnlb.gxyh + "')";
                        }
                        else
                        {
                            lsSql = "update PMP000101 set Name='" + gnlb.name + "',XT='" + gnlb.xt + "',ZYGN='" + gnlb.zygn + "',PT='" + gnlb.pt + "',LX='" + gnlb.lx + "',CreateDate='" + gnlb.createDate + "',UpdateDate='" + System.DateTime.Now + "',CJYH='" + gnlb.cjyh + "',GXYH='" + gnlb.gxyh + "' where Code='" + gnlb.code + "' ";
                        }

                        loString.AppendLine(lsSql);
                    }
                }
                lsSql = loString.ToString();
                if (!string.IsNullOrEmpty(lsSql))
                {
                    SqlHelperXhf loSqlHelperXhf = new SqlHelperXhf(Comm.ConnStringFrom);
                    loSqlHelperXhf.ExecuteNonQuery(lsSql);
                }
                else
                {
                    MessageBox.Show("没有任何选中数据!");
                }
                button1_Click(null, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }