public FishEntity.SetreviewEntity getModel(DataRow row)
        {
            FishEntity.SetreviewEntity model = new FishEntity.SetreviewEntity();

            if (row != null)
            {
                if (row["userName"] != null)
                {
                    model.userName = row["userName"].ToString();
                }
                if (row["programId"] != null)
                {
                    model.programId = row["programId"].ToString();
                }
                if (row["level"] != null)
                {
                    model.level = bool.Parse(row["level"].ToString());
                }
                if (row["realname"] != null)
                {
                    model.Realname = row["realname"].ToString();
                }
                if (row["programName"] != null)
                {
                    model.ProgramName = row["programName"].ToString();
                }
            }

            return(model);
        }
        void insert(FishEntity.SetreviewEntity list, Hashtable SQLString, StringBuilder strSql)
        {
            strSql = new StringBuilder();
            strSql.Append("insert into t_setreview (");
            strSql.Append("userName,programId,level,createTime,createMan,modifyTime,modifyMan)");
            strSql.Append("values (");
            strSql.Append("@userName,@programId,@level,@createTime,@createMan,@modifyTime,@modifyMan)");
            MySqlParameter[] parameter =
            {
                new MySqlParameter("@userName",   MySqlDbType.VarChar,   45),
                new MySqlParameter("@programId",  MySqlDbType.VarChar,   45),
                new MySqlParameter("@level",      MySqlDbType.Bit,        1),
                new MySqlParameter("@createTime", MySqlDbType.DateTime),
                new MySqlParameter("@createMan",  MySqlDbType.VarChar,   45),
                new MySqlParameter("@modifyTime", MySqlDbType.DateTime),
                new MySqlParameter("@modifyMan",  MySqlDbType.VarChar, 45)
            };

            parameter[0].Value = list.userName;
            parameter[1].Value = list.programId;
            parameter[2].Value = list.level;
            parameter[3].Value = list.createTime;
            parameter[4].Value = list.createMan;
            parameter[5].Value = list.modifyTime;
            parameter[6].Value = list.modifyMan;

            SQLString.Add(strSql, parameter);
        }
        void edit(FishEntity.SetreviewEntity list, Hashtable SQLString, StringBuilder strSql)
        {
            strSql = new StringBuilder();
            strSql.Append("update t_setreview set ");
            strSql.Append("level=@level,");
            strSql.Append("modifyTime=@modifyTime,");
            strSql.Append("modifyMan=@modifyMan ");
            strSql.Append("where userName=@userName and ");
            strSql.Append("programId=@programId");
            MySqlParameter[] parameter =
            {
                new MySqlParameter("@userName",   MySqlDbType.VarChar,   45),
                new MySqlParameter("@programId",  MySqlDbType.VarChar,   45),
                new MySqlParameter("@level",      MySqlDbType.Bit,        1),
                new MySqlParameter("@modifyTime", MySqlDbType.DateTime),
                new MySqlParameter("@modifyMan",  MySqlDbType.VarChar, 45)
            };

            parameter[0].Value = list.userName;
            parameter[1].Value = list.programId;
            parameter[2].Value = list.level;
            parameter[3].Value = list.modifyTime;
            parameter[4].Value = list.modifyMan;

            SQLString.Add(strSql, parameter);
        }
Beispiel #4
0
        public override void Save( )
        {
            dataGridView1.EndEdit( );

            //if ( check ( ) == false )
            //    return;

            List <FishEntity.SetreviewEntity> modelList = new List <FishEntity.SetreviewEntity> ( );

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if (row.IsNewRow)
                {
                    continue;
                }

                _list             = new FishEntity.SetreviewEntity( );
                _list.programId   = row.Cells ["programId"].Value == null ? string.Empty : row.Cells ["programId"].Value.ToString( );
                _list.ProgramName = row.Cells ["ProgramName"].Value == null ? string.Empty : row.Cells ["ProgramName"].Value.ToString( );
                _list.userName    = row.Cells ["userName"].Value == null ? string.Empty : row.Cells ["userName"].Value.ToString( );
                _list.Realname    = row.Cells ["userNum"].Value == null ? string.Empty : row.Cells ["userNum"].Value.ToString( );
                _list.level       = row.Cells ["level"].Value == null ? false : bool.Parse(row.Cells ["level"].Value.ToString( ));

                modelList.Add(_list);
            }

            if (modelList == null)
            {
                return;
            }

            bool result = _bll.add(modelList, FishEntity.Variable.User.username);

            if (result == true)
            {
                MessageBox.Show("保存成功");

                dataGridView1.AllowUserToAddRows    = false;
                dataGridView1.AllowUserToDeleteRows = false;
                dataGridView1.ReadOnly = true;

                tmiAdd.Visible      = true;
                tmiQuery.Visible    = true;
                tmiModify.Visible   = false;
                tmiDelete.Visible   = false;
                tmiReview.Visible   = false;
                tmiSave.Visible     = false;
                tmiCancel.Visible   = false;
                tmiExport.Visible   = false;
                tmiNext.Visible     = false;
                tmiPrevious.Visible = false;
                tmiClose.Visible    = true;
            }
            else
            {
                MessageBox.Show("保存失败,请重试");
            }

            base.Save( );
        }
        /// <summary>
        /// 保存记录
        /// </summary>
        /// <param name="modelList"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public bool add(List <FishEntity.SetreviewEntity> modelList, string userName)
        {
            Hashtable     SQLString = new Hashtable();
            StringBuilder strSql    = new StringBuilder();

            foreach (FishEntity.SetreviewEntity list in modelList)
            {
                list.createTime = list.modifyTime = dt();
                list.createMan  = list.modifyMan = userName;

                if (Exists(list.userName, list.programId) == true)
                {
                    edit(list, SQLString, strSql);
                }
                else
                {
                    insert(list, SQLString, strSql);
                }
            }

            DataTable tab = table();

            if (tab != null && tab.Rows.Count > 0)
            {
                FishEntity.SetreviewEntity list = new FishEntity.SetreviewEntity();
                string person = string.Empty, proId = string.Empty;
                for (int i = 0; i < tab.Rows.Count; i++)
                {
                    person = tab.Rows[i]["userName"].ToString();
                    proId  = tab.Rows[i]["programId"].ToString();
                    list   = modelList.Find((k) =>
                    {
                        return(k.userName.Equals(person) && k.programId.Equals(proId));
                    });

                    if (list == null)
                    {
                        del(person, proId, SQLString, strSql);
                    }
                }
            }

            return(MySqlHelper.ExecuteSqlTran(SQLString));
        }