void AddOrder(Hashtable SQLString, StringBuilder strSql, SiftingDataEntity.OrderWorkEntity model) { strSql = new StringBuilder( ); strSql.Append("INSERT INTO SGMRAB ("); strSql.Append("RAB001,RAB002,RAB003,RAB004,RAB005,RAB007,RAB020,RAB980,RAB981,RAB982) "); strSql.Append("VALUES ("); strSql.Append("@RAB001,@RAB002,@RAB003,@RAB004,@RAB005,@RAB007,@RAB020,@RAB980,@RAB981,@RAB982) "); SqlParameter [] parameter = { new SqlParameter("@RAB001", SqlDbType.NVarChar), new SqlParameter("@RAB002", SqlDbType.NVarChar), new SqlParameter("@RAB003", SqlDbType.NVarChar), new SqlParameter("@RAB004", SqlDbType.NVarChar), new SqlParameter("@RAB005", SqlDbType.NVarChar), new SqlParameter("@RAB007", SqlDbType.Decimal), new SqlParameter("@RAB020", SqlDbType.NVarChar), new SqlParameter("@RAB980", SqlDbType.Decimal), new SqlParameter("@RAB981", SqlDbType.Decimal), new SqlParameter("@RAB982", SqlDbType.Decimal) }; parameter [0].Value = model.RAB001; parameter [1].Value = model.RAB002; parameter [2].Value = model.RAB003; parameter [3].Value = model.RAB004; parameter [4].Value = model.RAB005; parameter [5].Value = model.RAB007; parameter [6].Value = model.RAB020; parameter [7].Value = model.RAB980; parameter [8].Value = model.RAB981; parameter [9].Value = model.RAB982; SQLString.Add(strSql, parameter); }
/// <summary> /// 插入工单单身数据 /// </summary> /// <param name="oddNum"></param> /// <returns></returns> public int SaveOrder(string oddNum) { bool isOk = true; Hashtable SQLString = new Hashtable( ); StringBuilder strSql = new StringBuilder( ); strSql.AppendFormat("SELECT COUNT(1) FROM SGMRAA WHERE RAA001='{0}'", oddNum); if (SqlHelper.Exists(strSql.ToString( )) == false) { //表示易助订单没有单头数据 return(-1); } strSql = new StringBuilder( ); strSql.AppendFormat("SELECT RAB002,RAB003 FROM SGMRAB WHERE RAB001='{0}'", oddNum); DataTable dt = SqlHelper.ExecuteDataTable(strSql.ToString( )); if (dt == null || dt.Rows.Count < 1) { isOk = false; } strSql = new StringBuilder( ); strSql.AppendFormat("SELECT DEL011 RAB001,DEL001 RAB003,DEL002 RAB004,DEL003 RAB020,DEL004 RAB005,SUM(DEL007*DEL008+DEL009) RAB007,SUM(DEL007) RAB980,SUM(DEL008) RAB981,SUM(DEL010) RAB982 FROM QIXDEL WHERE DEL011='{0}' GROUP BY DEL011,DEL001,DEL002,DEL004,DEL003", oddNum); DataTable table = SqlHelper.ExecuteDataTable(strSql.ToString( )); if (table == null || table.Rows.Count < 1) { //表示本单号在本程序没有单身数据 return(-2); } List <string> strList = new List <string> ( ); SiftingDataEntity.OrderWorkEntity model = new SiftingDataEntity.OrderWorkEntity( ); model.RAB001 = oddNum; for (int i = 0; i < table.Rows.Count; i++) { model.RAB003 = table.Rows [i] ["RAB003"].ToString( ); if (isOk) { model.RAB002 = dt.Compute("MAX(RAB002)", null).ToString( ); if (strList.Contains(model.RAB002)) { model.RAB002 = strList.Max( ); model.RAB002 = (Convert.ToInt32(model.RAB002) + 1).ToString( ).PadLeft(3, '0'); strList.Add(model.RAB002); } else { strList.Add(model.RAB002); model.RAB002 = (Convert.ToInt32(model.RAB002) + 1).ToString( ).PadLeft(3, '0'); strList.Add(model.RAB002); } } else { model.RAB002 = i.ToString( ).PadLeft(3, '0'); if (strList.Contains(model.RAB002)) { model.RAB002 = strList.Max( ); model.RAB002 = (Convert.ToInt32(model.RAB002) + 1).ToString( ).PadLeft(3, '0'); strList.Add(model.RAB002); } else { strList.Add(model.RAB002); } } model.RAB004 = table.Rows [i] ["RAB004"].ToString( ); model.RAB005 = table.Rows [i] ["RAB005"].ToString( ); model.RAB007 = string.IsNullOrEmpty(table.Rows [i] ["RAB007"].ToString( )) == true ? 0 : Convert.ToDecimal(table.Rows [i] ["RAB007"].ToString( )); model.RAB980 = string.IsNullOrEmpty(table.Rows [i] ["RAB980"].ToString( )) == true ? 0 : Convert.ToDecimal(table.Rows [i] ["RAB980"].ToString( )); model.RAB981 = string.IsNullOrEmpty(table.Rows [i] ["RAB981"].ToString( )) == true ? 0 : Convert.ToDecimal(table.Rows [i] ["RAB981"].ToString( )); model.RAB982 = string.IsNullOrEmpty(table.Rows [i] ["RAB982"].ToString( )) == true ? 0 : Convert.ToDecimal(table.Rows [i] ["RAB982"].ToString( )); model.RAB020 = table.Rows [i] ["RAB020"].ToString( ); if (dt.Select("RAB003='" + model.RAB003 + "'").Length < 1) { AddOrder(SQLString, strSql, model); } } if (SqlHelper.ExecuteSqlTran(SQLString)) { return(1); } else { return(2); } }