/// <summary> /// 增加一条数据 /// </summary> public void Insert(Entities.CarBrand model) { SqlParameter[] parameters = { new SqlParameter("@BrandID", SqlDbType.Int, 4), new SqlParameter("@Name", SqlDbType.NVarChar, 200), new SqlParameter("@Country", SqlDbType.NVarChar, 200), new SqlParameter("@NewCountry", SqlDbType.VarChar, 200), new SqlParameter("@AllSpell", SqlDbType.VarChar, 200), new SqlParameter("@Spell", SqlDbType.VarChar, 200), new SqlParameter("@BrandSEOName", SqlDbType.VarChar, 200), new SqlParameter("@MasterBrandID", SqlDbType.Int, 4), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@ModifyTime", SqlDbType.DateTime) }; parameters[0].Value = model.BrandID; parameters[1].Value = model.Name; parameters[2].Value = model.Country; parameters[3].Value = model.NewCountry; parameters[4].Value = model.AllSpell; parameters[5].Value = model.Spell; parameters[6].Value = model.BrandSEOName; parameters[7].Value = model.MasterBrandID; parameters[8].Value = model.CreateTime; parameters[9].Value = model.ModifyTime; SqlHelper.ExecuteNonQuery(CONNECTIONSTRINGS, CommandType.StoredProcedure, P_CARBRAND_INSERT, parameters); }
/// <summary> /// 同步车型(主品牌、系列)数据到表CarMasterBrand和CarSerial中 /// </summary> public void SyncCarInfo() { DeleteSyncCarTable(); DataSet ds = new DataSet(); ds.ReadXml(MasterToBrandToSerialXML); if (ds.Tables.Contains("MasterBrand") && ds.Tables["MasterBrand"].Rows.Count > 0)//查询MasterBrand信息 { //string msg = "同步车型(主品牌、系列)数据到表CarMasterBrand和CarSerial中——获取接口中表MasterBrand不存在或没有数据"; //BLL.Loger.Log4Net.Info(msg); //throw new Exception(msg); foreach (DataRow dr in ds.Tables["MasterBrand"].Rows) { Entities.CarMasterBrand cm = new Entities.CarMasterBrand(); cm.MasterBrandID = int.Parse(dr["ID"].ToString()); cm.Name = dr["Name"].ToString().Trim(); cm.EName = dr["EName"].ToString().Trim(); cm.Country = dr["Country"].ToString().Trim(); cm.AllSpell = dr["AllSpell"].ToString().Trim(); cm.Spell = dr["Spell"].ToString().Trim(); cm.CreateTime = DateTime.Now; BLL.CarMasterBrand.Instance.Insert(cm); } //品牌 if (ds.Tables.Contains("Brand") && ds.Tables["Brand"].Rows.Count > 0)//查询Brand信息 { foreach (DataRow drBrand in ds.Tables["Brand"].Rows) { int BrandId = int.Parse(drBrand["ID"].ToString().Trim()); string Name = drBrand["Name"].ToString(); string Country = drBrand["Country"].ToString(); string NewCountry = drBrand["NewCountry"].ToString(); string AllSpell = drBrand["AllSpell"].ToString(); string Spell = drBrand["Spell"].ToString(); string BrandSEOName = drBrand["BrandSEOName"].ToString(); int MasterBrand_Id = int.Parse(drBrand["MasterBrand_Id"].ToString().Trim()); if (ds.Tables.Contains("MasterBrand") && ds.Tables["MasterBrand"].Rows.Count > 0) { ds.Tables["MasterBrand"].DefaultView.RowFilter = "MasterBrand_ID=" + MasterBrand_Id; DataTable dtCarMaster = ds.Tables["MasterBrand"].DefaultView.ToTable(); if (dtCarMaster != null && dtCarMaster.Rows.Count > 0) { MasterBrand_Id = int.Parse(dtCarMaster.Rows[0]["ID"].ToString()); } } Entities.CarBrand CarBrandModel = new Entities.CarBrand() { BrandID = BrandId, Name = Name, Country = Country, NewCountry = NewCountry, AllSpell = AllSpell, Spell = Spell, BrandSEOName = BrandSEOName, MasterBrandID = MasterBrand_Id, CreateTime = DateTime.Now, ModifyTime = DateTime.Now }; BLL.CarBrand.Instance.Insert(CarBrandModel); } } //车型 if (ds.Tables.Contains("Serial") && ds.Tables["Serial"].Rows.Count > 0)//查询Serial信息 { foreach (DataRow drSerial in ds.Tables["Serial"].Rows) { int brandID = int.Parse(drSerial["Brand_ID"].ToString().Trim()); int csMasterBrandID = -1; if (ds.Tables.Contains("Brand") && ds.Tables["Brand"].Rows.Count > 0) { ds.Tables["Brand"].DefaultView.RowFilter = "Brand_ID=" + brandID; DataTable dtCarMasterAndSerial = ds.Tables["Brand"].DefaultView.ToTable(); if (dtCarMasterAndSerial != null && dtCarMasterAndSerial.Rows.Count > 0) { brandID = int.Parse(dtCarMasterAndSerial.Rows[0]["ID"].ToString()); ds.Tables["MasterBrand"].DefaultView.RowFilter = "MasterBrand_ID=" + int.Parse(dtCarMasterAndSerial.Rows[0]["MasterBrand_ID"].ToString().Trim()); DataTable dtCarMaster = ds.Tables["MasterBrand"].DefaultView.ToTable(); if (dtCarMaster != null && dtCarMaster.Rows.Count > 0) { csMasterBrandID = int.Parse(dtCarMaster.Rows[0]["ID"].ToString().Trim()); } } } if (csMasterBrandID > 0) { Entities.CarSerial csm = new Entities.CarSerial(); csm.CSID = int.Parse(drSerial["ID"].ToString()); csm.Name = drSerial["Name"].ToString().Trim(); csm.OldCbID = drSerial["OldCbID"].ToString(); csm.CsLevel = drSerial["CsLevel"].ToString().Trim(); csm.MultiPriceRange = drSerial["MultiPriceRange"].ToString().Trim(); csm.CsSaleState = drSerial["CsSaleState"].ToString().Trim(); csm.AllSpell = drSerial["AllSpell"].ToString().Trim(); csm.CsMultiChar = drSerial["CsMultiChar"].ToString().Trim(); csm.MasterBrandID = csMasterBrandID; csm.CreateTime = DateTime.Now; csm.BrandID = brandID; BLL.CarSerial.Instance.Insert(csm); } else { BLL.Loger.Log4Net.Info("同步车型(主品牌、系列)数据到表CarMasterBrand和CarSerial中——同步到表CarSerial时,根据BrandID:" + brandID + "没有找到MasterBrandID"); } } } } else { string msg = "同步车型(主品牌、系列)数据到表CarMasterBrand和CarSerial中——获取接口中表MasterBrand不存在或没有数据"; BLL.Loger.Log4Net.Info(msg); throw new Exception(msg); } }
/// <summary> /// 增加一条数据 /// </summary> public void Insert(Entities.CarBrand model) { Dal.CarBrand.Instance.Insert(model); }