コード例 #1
0
ファイル: Account.cs プロジェクト: huaminglee/Code
        //method
        #region 按钮事件

        //保存
        private void btnAccSubmit_Click
            (object sender, EventArgs e)
        {
              bool bRst         = false;
            string strSpid      = Spid.Text.Trim();
            string strCom       = Com.Text.Trim();
            string strComName   = ComName.Text.Trim();
            string strLoginName = LoginName.Text.Trim();
            string strPassword  = Password.Text.Trim();
            string strQueryCNT  = QueryCNT.Text.Trim();

            string strAattribute = (string)Aattribute.SelectedValue;



            if (strSpid.Length == 0
                || strCom.Length == 0
                || strComName.Length == 0
                ||strLoginName.Length == 0
                || strPassword.Length == 0
                || strQueryCNT.Length ==0)
            {
                Msg("请将注册信息填写完整", "警告信息", "warning");
                return;
            };

            

            List<string> field = new List<string>();
            List<string> value = new List<string>();

            field.Add("Spid");
            field.Add("Com");
            field.Add("LoginName");
            field.Add("Password");
            field.Add("ComName");
            field.Add("QueryCNT");
            field.Add("Aattribute");

            value.Add(strSpid);
            value.Add(strCom);
            value.Add(strLoginName);
            value.Add(strPassword);
            value.Add(strComName);
            value.Add(strQueryCNT);
            value.Add(strAattribute);



            LogicHandle lgH = new LogicHandle();
            string where = " [Id] = '" + this.strId
                + "' AND [Aattribute] = '" + strAattribute + "'";
                     
            //判断是否已有数据
            int iCount 
                = lgH.GetCount("[dbo].[CFG_Account]", where);


            if (this.bItOrUp)//update
            {

                if (iCount > 0)
                {
                    where += " AND Id = " + this.strId;
                    bRst =
                        lgH.UpdateMany("[dbo].[CFG_Account]", field, value, where);
                }
                else 
                {
                    Msg("该企业或此通道不存在。", "警告信息", "warning");
                    return;
                };
            }
            else //insert 
            {
                string queryWhere = " [Spid] = '" + strSpid + "' ";

                int iCheck = lgH.GetCount("[dbo].[CFG_Account]", queryWhere);

                if (iCheck == 0)
                {   
                    bRst = 
                        lgH.Insert("[dbo].[CFG_Account]", field, value);
                }
                else
                {
                    Msg("该企业号或此通道已存在", "警告信息", "warning");
                    return;
                };
            };



            if (bRst)
            {
                //将父窗体传过来

                Main main = (Main)this.Owner;
                main.dataGridView1.DataSource = null;
                main.dataGridView1.DataSource = main.loadData();

                main.dataGridView1.Columns["Id"].Visible = false;
                main.dataGridView1.Columns["Password"].Visible = false;
                main.dataGridView1.Columns["CreateTime"].Visible = false;

                Msg("保存成功。", "提示信息", "ok");
                this.Close();
            }
            else
            {
                Msg("保存失败,请联系信息管理部。", "错误信息", "error");
                this.Close();
            }
        }