void delete_art(Hashtable SQLString, StringBuilder strSql, ProductionErpEntity.ArtEntity _model) { strSql = new StringBuilder( ); strSql.Append("DELETE FROM MOXART "); strSql.AppendFormat("WHERE idx={0}", _model.Idx); SQLString.Add(strSql, null); }
/// <summary> /// 泛型获取 /// </summary> /// <param name="_model"></param> /// <returns></returns> //T getValueForType<T> ( DataRow row , string name ) //{ // T result = default ( T ); // var value = row [ name ]; // if ( value != null || !Convert . IsDBNull ( value ) ) // { // result = ( T ) value; // } // return result; //} //static T getValueForType<T> ( this DataRow row , string name ) //{ // T result = default ( T ); // var value = row [ name ]; // if ( value != null && !Convert . IsDBNull ( value ) ) // { // result = ( T ) value; // } // return result; //} bool Exists(ProductionErpEntity.ArtEntity _model) { StringBuilder strSql = new StringBuilder( ); strSql.Append("SELECT COUNT(1) FROM MOXART "); strSql.Append("WHERE ART001=@ART001 AND ART002=@ART002"); SqlParameter [] parameter = { new SqlParameter("@ART001", SqlDbType.NVarChar, 50), new SqlParameter("@ART002", SqlDbType.NVarChar, 50) }; parameter [0].Value = _model.Art001; parameter [1].Value = _model.Art002; return(SqlHelper.Exists(strSql.ToString( ), parameter)); }
void add_art(Hashtable SQLString, StringBuilder strSql, ProductionErpEntity.ArtEntity _model) { strSql = new StringBuilder( ); strSql.Append("INSERT INTO MOXART ("); strSql.Append("ART001,ART002) "); strSql.Append("VALUES ("); strSql.Append("@ART001,@ART002) "); SqlParameter [] parameter = { new SqlParameter("@ART001", SqlDbType.NVarChar, 50), new SqlParameter("@ART002", SqlDbType.NVarChar, 50) }; parameter [0].Value = _model.Art001; parameter [1].Value = _model.Art002; SQLString.Add(strSql, parameter); }
void edit_art(Hashtable SQLString, StringBuilder strSql, ProductionErpEntity.ArtEntity _model) { strSql = new StringBuilder( ); strSql.Append("UPDATE MOXART SET "); strSql.Append("ART001=@ART001,"); strSql.Append("ART002=@ART002 "); strSql.Append(" WHERE idx=@idx "); SqlParameter [] parameter = { new SqlParameter("@ART001", SqlDbType.NVarChar, 50), new SqlParameter("@ART002", SqlDbType.NVarChar, 50), new SqlParameter("@idx", SqlDbType.Int, 4) }; parameter [0].Value = _model.Art001; parameter [1].Value = _model.Art002; parameter [2].Value = _model.Idx; SQLString.Add(strSql, parameter); }
public FormArt( ) { InitializeComponent( ); tableView = new DataTable( ); _model = new ProductionErpEntity.ArtEntity( ); _bll = new ProductionErpBll.Bll.ArtBll( ); Utility.GridViewMoHuSelect.SetFilter(gridView1); FieldInfo fi = typeof(XPaint).GetField("graphics", BindingFlags.Static | BindingFlags.NonPublic); fi.SetValue(null, new DrawXPaint( )); barMenu.LinksPersistInfo.RemoveAt(toolExport.Id); barMenu.LinksPersistInfo.RemoveAt(toolPrint.Id); barMenu.LinksPersistInfo.RemoveAt(toolEdit.Id); gridView1.OptionsBehavior.Editable = false; }
/// <summary> /// 保存数据到数据库 /// </summary> /// <param name="table"></param> /// <returns></returns> public bool Save(DataTable table, List <int> intList) { //StringBuilder strSql = new StringBuilder ( ); //strSql . Append ( "SELECT idx,ART001,ART002 FROM MOXART WHERE 1=2" ); //return SqlHelper . UpdateToSql ( table ,strSql . ToString ( ) ); Hashtable SQLString = new Hashtable( ); StringBuilder strSql = new StringBuilder( ); ProductionErpEntity.ArtEntity _model = new ProductionErpEntity.ArtEntity( ); for (int i = 0; i < table.Rows.Count; i++) { _model.Idx = string.IsNullOrEmpty(table.Rows [i] ["idx"].ToString( )) == true ? 0 : Convert.ToInt32(table.Rows [i] ["idx"].ToString( )); //_model . Idx = table . Rows [ i ] . getValueForType<int> ( "idx" ); _model.Art001 = table.Rows [i] ["ART001"].ToString( ); _model.Art002 = table.Rows [i] ["ART002"].ToString( ); if (Exists(_model) == false) { if (_model.Idx < 1) { add_art(SQLString, strSql, _model); } else { edit_art(SQLString, strSql, _model); } } } foreach (int id in intList) { _model.Idx = id; delete_art(SQLString, strSql, _model); } return(SqlHelper.ExecuteSqlTran(SQLString)); }