public int CompareTo(object obj) { Category2Info b = obj as Category2Info; if (this.Status < b.Status) { return(1); } else if (this.Status > b.Status) { return(-1); } else { int result = String.Compare(this.C2ID, b.C2ID); if (result > 0) { return(1); } else { return(-1); } } }
public void Insert(Category2Info oParam) { //foreach( Category2Info item in C2Hash.Values ) //{ // if ( item.C2ID == oParam.C2ID ) // throw new BizException("the same second category ID exists"); //} string _c1ID = ""; string _c2ID=""; int _tmpInt = -1; string _tmpStr = ""; Category1Info _oC1 = CategoryManager.GetInstance().GetC1Hash()[oParam.C1SysNo] as Category1Info; if(_oC1.C1ID.Trim()=="") throw new BizException("�Բ�����������Ŵ��������"); _c1ID=_oC1.C1ID.Trim(); string sql = "select max(C2ID) from Category2 where c2id like '"+_c1ID+"%'"; _tmpStr = SqlHelper.ExecuteScalar(sql).ToString(); if (_tmpStr.Trim() == "") _tmpStr = _c1ID+"00"; if(_tmpStr.Length!=4) throw new BizException("�Բ������������Ŵ��������"); _tmpStr = _tmpStr.Substring(2,2); if(!Util.IsInteger(_tmpStr)) throw new BizException("�Բ������������Ŵ��������"); _tmpInt = Convert.ToInt32(_tmpStr); if (_tmpInt >= 99)//��λ��� { throw new BizException("�Բ��𣬱��Խ�磬���������"); } _tmpInt++; if (_tmpInt < 10) _c2ID = _c1ID+"0" + _tmpInt.ToString(); else _c2ID = _c1ID+ _tmpInt.ToString(); oParam.C2ID = _c2ID; oParam.SysNo = SequenceDac.GetInstance().Create("Category_Sequence"); new CategoryDac().Insert(oParam); SyncManager.GetInstance().SetDbLastVersion( (int)AppEnum.Sync.Category ); C2Hash.Add(oParam.SysNo, oParam); }
public void ImportCategory() { if ( !AppConfig.IsImportable) throw new BizException("Is Importable is false"); /* do not use the following code after Data Pour in */ string sql = " select top 1 * from category1 "; DataSet ds = SqlHelper.ExecuteDataSet(sql); if ( Util.HasMoreRow(ds) ) throw new BizException("the table category is not empty"); TransactionOptions options = new TransactionOptions(); options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted; options.Timeout = TransactionManager.DefaultTimeout; using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options)) { try { string sql1 = @"select cf.*, cfl.firstcategoryname from ipp2003..category_first cf, ipp2003..category_first_language cfl where cf.sysno = cfl.firstcategorysysno and languageid = 'cn'"; DataSet ds1 = SqlHelper.ExecuteDataSet(sql1); foreach(DataRow dr1 in ds1.Tables[0].Rows ) { Category1Info oC1 = new Category1Info(); oC1.C1ID = Util.TrimNull(dr1["FirstCategoryID"]); oC1.C1Name = Util.TrimNull(dr1["FirstCategoryName"]); oC1.Status = Util.TrimIntNull(dr1["Status"]); this.Insert(oC1); //insert into convert table ImportInfo oC1Convert = new ImportInfo(); oC1Convert.OldSysNo = Util.TrimIntNull(dr1["SysNo"]); oC1Convert.NewSysNo = oC1.SysNo; new ImportDac().Insert(oC1Convert, "Category1"); string sql2 = @"select a.*, b.secondcategoryname from ipp2003..category_second a, ipp2003..category_second_language b where a.sysno = b.secondcategorysysno and languageid = 'cn' and firstcategorysysno = " + Util.TrimIntNull(dr1["SysNo"]); DataSet ds2 = SqlHelper.ExecuteDataSet(sql2); foreach( DataRow dr2 in ds2.Tables[0].Rows ) { Category2Info oC2 = new Category2Info(); oC2.C1SysNo = oC1.SysNo; oC2.C2ID = Util.TrimNull(dr2["SecondCategoryID"]); oC2.C2Name = Util.TrimNull(dr2["SecondCategoryName"]); oC2.Status = Util.TrimIntNull(dr2["Status"]); this.Insert(oC2); //insert into convert table ImportInfo oC2Convert = new ImportInfo(); oC2Convert.OldSysNo = Util.TrimIntNull(dr2["SysNo"]); oC2Convert.NewSysNo = oC2.SysNo; new ImportDac().Insert(oC2Convert,"Category2"); string sql3 = @"select a.*, b.thirdcategoryname from ipp2003..category_third a, ipp2003..category_third_language b where a.sysno = b.thirdcategorysysno and languageid = 'cn' and secondcategorysysno = "+ Util.TrimIntNull(dr2["SysNo"]); DataSet ds3 = SqlHelper.ExecuteDataSet(sql3); foreach( DataRow dr3 in ds3.Tables[0].Rows ) { Category3Info oC3 = new Category3Info(); oC3.C2SysNo = oC2.SysNo; oC3.C3ID = Util.TrimNull(dr3["ThirdCategoryID"]); oC3.C3Name = Util.TrimNull(dr3["ThirdCategoryName"]); oC3.Status = Util.TrimIntNull(dr3["Status"]); this.Insert(oC3); //insert into convert table ImportInfo oC3Convert = new ImportInfo(); oC3Convert.OldSysNo = Util.TrimIntNull(dr3["SysNo"]); oC3Convert.NewSysNo = oC3.SysNo; new ImportDac().Insert(oC3Convert, "Category3"); string sql4 = @"select a.*,b.AttributeName from ipp2003..category_attribute as a, ipp2003..category_attribute_language as b where a.ThirdCategorySysNo = b.ThirdCategorySysNo and a.AttributeID = b.AttributeID and languageid = 'cn' and AttributeName <>'' and a.thirdcategorysysno = "+ Util.TrimIntNull(dr3["SysNo"]); DataSet ds4 = SqlHelper.ExecuteDataSet(sql4); int count = 0; foreach( DataRow dr4 in ds4.Tables[0].Rows ) { if ( count == 0) { InitAttribute(Util.TrimIntNull(oC3.SysNo)); count ++; } CategoryAttributeInfo oCA = new CategoryAttributeInfo(); oCA.C3SysNo = oC3.SysNo; oCA.AttributeID = Util.TrimNull(dr4["AttributeID"]); oCA.AttributeName = Util.TrimNull(dr4["AttributeName"]); oCA.OrderNum = Util.TrimIntNull(dr4["SequenceNo"]); oCA.Status = Util.TrimIntNull(dr4["Status"]); new CategoryDac().UpdateAttributeByC3andAID(oCA); } } } } } catch(Exception ex) { C1Hash.Clear(); C2Hash.Clear(); C3Hash.Clear(); throw ex; } scope.Complete(); } }
private void Map(Category2Info oParam, DataRow tempdr) { oParam.SysNo = Util.TrimIntNull(tempdr["SysNo"]); oParam.C1SysNo = Util.TrimIntNull(tempdr["C1SysNo"]); oParam.C2ID = Util.TrimNull(tempdr["C2ID"]); oParam.C2Name = Util.TrimNull(tempdr["C2Name"]); oParam.Status = Util.TrimIntNull(tempdr["Status"]); }
private void InitC2() { lock ( categoryLocker ) { C2Hash.Clear(); string sql = " select * from category2 order by sysno"; DataSet ds = SqlHelper.ExecuteDataSet(sql); if ( !Util.HasMoreRow(ds)) return; foreach( DataRow dr in ds.Tables[0].Rows ) { Category2Info item = new Category2Info(); Map(item, dr); C2Hash.Add(item.SysNo, item); } } }
public void Update(Category2Info oParam) { //foreach(Category2Info item in C2Hash.Values) //{ // if ( item.SysNo!=oParam.SysNo && item.C2ID == oParam.C2ID) // throw new BizException("the same second category ID exists"); //} new CategoryDac().Update(oParam); SyncManager.GetInstance().SetDbLastVersion( (int)AppEnum.Sync.Category ); if ( C2Hash.ContainsKey(oParam.SysNo)) { C2Hash.Remove(oParam.SysNo); C2Hash.Add(oParam.SysNo, oParam); } }
public int Update(Category2Info oParam) { string sql = @"UPDATE Category2 SET C1SysNo=@C1SysNo, C2ID=@C2ID, C2Name=@C2Name, Status=@Status WHERE SysNo=@SysNo"; SqlCommand cmd = new SqlCommand(sql); SqlParameter paramSysNo = new SqlParameter("@SysNo", SqlDbType.Int,4); SqlParameter paramC1SysNo = new SqlParameter("@C1SysNo", SqlDbType.Int,4); SqlParameter paramC2ID = new SqlParameter("@C2ID", SqlDbType.NVarChar,20); SqlParameter paramC2Name = new SqlParameter("@C2Name", SqlDbType.NVarChar,200); SqlParameter paramStatus = new SqlParameter("@Status", SqlDbType.Int,4); paramSysNo.Value = oParam.SysNo; paramC1SysNo.Value = oParam.C1SysNo; paramC2ID.Value = oParam.C2ID; paramC2Name.Value = oParam.C2Name; paramStatus.Value = oParam.Status; cmd.Parameters.Add(paramSysNo); cmd.Parameters.Add(paramC1SysNo); cmd.Parameters.Add(paramC2ID); cmd.Parameters.Add(paramC2Name); cmd.Parameters.Add(paramStatus); return SqlHelper.ExecuteNonQuery(cmd); }
public int Insert(Category2Info oParam) { string sql = @"INSERT INTO Category2 ( SysNo, C1SysNo, C2ID, C2Name, Status ) VALUES ( @SysNo, @C1SysNo, @C2ID, @C2Name, @Status )"; SqlCommand cmd = new SqlCommand(sql); SqlParameter paramSysNo = new SqlParameter("@SysNo", SqlDbType.Int,4); SqlParameter paramC1SysNo = new SqlParameter("@C1SysNo", SqlDbType.Int,4); SqlParameter paramC2ID = new SqlParameter("@C2ID", SqlDbType.NVarChar,20); SqlParameter paramC2Name = new SqlParameter("@C2Name", SqlDbType.NVarChar,200); SqlParameter paramStatus = new SqlParameter("@Status", SqlDbType.Int,4); paramSysNo.Value = oParam.SysNo; paramC1SysNo.Value = oParam.C1SysNo; paramC2ID.Value = oParam.C2ID; paramC2Name.Value = oParam.C2Name; paramStatus.Value = oParam.Status; cmd.Parameters.Add(paramSysNo); cmd.Parameters.Add(paramC1SysNo); cmd.Parameters.Add(paramC2ID); cmd.Parameters.Add(paramC2Name); cmd.Parameters.Add(paramStatus); return SqlHelper.ExecuteNonQuery(cmd); }