public void SaveDishes(StoreInfoEntity storeInfoEntity, StoreInfo siteStoreInfo)
 {
     var dishTypeBll = new Maticsoft.BLL.DishesTyep();
     var dishesEntityBll = new Maticsoft.BLL.DishesBll();
     var storePictureBll = new Maticsoft.BLL.StorePicture();
     DoProgress(30);
     dishesEntityBll.Remove(string.Format("BusinessID = '{0}'", storeInfoEntity.BizID));
     dishTypeBll.Remove(string.Format("BusinessID = '{0}'", storeInfoEntity.BizID));
     foreach (var dishType in siteStoreInfo.DishTypeList)
     {
         dishType.BusinessID = storeInfoEntity.BizID;
         dishTypeBll.Add(dishType);
         foreach (var dishesEntity in dishType.DishesList)
         {
             dishesEntity.BusinessID = storeInfoEntity.BizID;
             dishesEntityBll.Add(dishesEntity);
             if (!string.IsNullOrEmpty(dishesEntity.PictureHref) && !string.IsNullOrWhiteSpace(dishesEntity.PictureHref))
             {
                 var storePicture = new Maticsoft.Model.StorePicture();
                 storePicture.PID = Guid.NewGuid().ToString();
                 storePicture.PictureName = string.Format("{0}.jpg", storePicture.PID);
                 storePicture.PicType = "Food";
                 storePicture.PicturePath = dishesEntity.PictureHref;
                 storePicture.StoreId = storeInfoEntity.BizID;
                 storePictureBll.Add(storePicture);
             }
         }
     }
     DoProgress();
 }
 public void SaveCityLocalTagEntity(StoreInfoEntity storeInfoEntity, IEnumerable<CityLocalTagEntity> cityLocalTagEntityList)
 {
     var storeLocalTagBll = new Maticsoft.BLL.StoreLocalTag();
     storeLocalTagBll.Remove(string.Format("bizid = '{0}'", storeInfoEntity.BizID));
     DoProgress(30);
     foreach (var cityLocalTag in cityLocalTagEntityList)
     {
         var storeLocalTag = new Maticsoft.Model.StoreLocalTag();
         storeLocalTag.BizID = storeInfoEntity.BizID;
         storeLocalTag.BizType = 10;
         storeLocalTag.DistrictID = storeInfoEntity.DistrictID;
         storeLocalTag.KeyID = Guid.NewGuid().ToString();
         storeLocalTag.LocalTagID = cityLocalTag.LocalTagID;
         storeLocalTag.LocalTagName = cityLocalTag.TagName;
         storeLocalTagBll.Add(storeLocalTag);
     }
     DoProgress();
 }
 public void SaveCookingStyles(StoreInfoEntity storeInfoEntity, IEnumerable<CookingStyles> cookingStylesList)
 {
     var storeCookingStylesBll = new Maticsoft.BLL.StoreCookingStyles();
     storeCookingStylesBll.Remove(string.Format("bizid = '{0}'", storeInfoEntity.BizID));
     DoProgress(20);
     foreach (var specialTag in cookingStylesList)
     {
         if (specialTag != null)
         {
             var storeCookingStyles = new Maticsoft.Model.StoreCookingStyles();
             storeCookingStyles.BizID = storeInfoEntity.BizID;
             storeCookingStyles.CookingStyleID = specialTag.CookingStyleID;
             storeCookingStyles.CookingStyleName = specialTag.CookingStyleName;
             storeCookingStyles.KeyID = Guid.NewGuid().ToString();
             storeCookingStylesBll.Add(storeCookingStyles);
         }
     }
     DoProgress();
 }
 public void SaveStorePictures(StoreInfoEntity storeInfoEntity, StoreInfo siteStoreInfo)
 {
     var storePicturesBll = new Maticsoft.BLL.StorePictures();
     storePicturesBll.Remove(string.Format("BusinessID ='{0}'", storeInfoEntity.BizID));
     var busPhotoAlbumBll = new Maticsoft.BLL.BusPhotoAlbum();
     busPhotoAlbumBll.Remove(string.Format("BusinessID = '{0}'", storeInfoEntity.BizID));
     var storePictureBll = new Maticsoft.BLL.StorePicture();
     DoProgress(30);
     foreach (var busPhotoAlbum in siteStoreInfo.BusPhotoAlbumTableList)
     {
         busPhotoAlbum.BusinessID = storeInfoEntity.BizID;
         busPhotoAlbumBll.Add(busPhotoAlbum);
         var pcituresList = busPhotoAlbum.StorePicturesList;
         foreach (var storePicture in pcituresList)
         {
             storePicture.StoreId = storeInfoEntity.BizID;
             storePictureBll.Add(storePicture);
             var storePictures = new Maticsoft.Model.StorePictures
             {
                 StorePicturesID = Guid.NewGuid().ToString(),
                 BusPhotoAlbumID = busPhotoAlbum.BusPhotoAlbumID,
                 BusinessID = busPhotoAlbum.BusinessID,
                 PictureAddress = storePicture.PictureName,
                 PicState = 2,
                 UploadTime = DateTime.Now
             };
             storePicturesBll.Add(storePictures);
         }
     }
     DoProgress();
 }
 public void SaveStoreSpecialTag(StoreInfoEntity storeInfoEntity, List<SpecialTag> specialTagList)
 {
     var storeSpecialBll = new Maticsoft.BLL.StoreSpecialTag();
     storeSpecialBll.Remove(string.Format("bizid = '{0}'", storeInfoEntity.BizID));
     DoProgress();
     foreach (var specialTag in specialTagList)
     {
         if (specialTag != null)
         {
             var storeSpecial = new Maticsoft.Model.StoreSpecialTag();
             storeSpecial.BizID = storeInfoEntity.BizID;
             storeSpecial.SpecialTagID = specialTag.SpecialTagID;
             storeSpecial.TagName = specialTag.TagName;
             storeSpecial.StoreSpecialTagID = Guid.NewGuid().ToString();
             storeSpecialBll.Add(storeSpecial);
         }
     }
     DoProgress();
 }
 private StoreInfoEntity GetStoreInfoEntity(Catalogue catalogueInfo, StoreInfoEntity oldStoreInfo, StoreInfo siteStoreInfo)
 {
     if (oldStoreInfo == null)
     {
         oldStoreInfo = new Maticsoft.Model.StoreInfoEntity();
         oldStoreInfo.BizID = catalogueInfo.StoreId;
     }
     if (siteStoreInfo == null)
     {
         return null;
     }
     oldStoreInfo.Box = chbbox.Checked;
     oldStoreInfo.StoreName = txtStoreNameSite.Text.Trim();
     oldStoreInfo.Bus = txtBusSite.Text.Trim();
     oldStoreInfo.BusinessAddTime = DateTime.Now;
     oldStoreInfo.BasicIntroduction = txtBasicSite.Text.Trim();
     oldStoreInfo.BusinessState = 40;
     oldStoreInfo.BusinessTypeID = "2";
     oldStoreInfo.CarPark = chbCarPark.Checked;
     oldStoreInfo.ChildrenChair = chbChildrenChair.Checked;
     oldStoreInfo.CityID = ((Maticsoft.Model.City)cbBoxCity.SelectedItem).CityID;
     oldStoreInfo.Cod = chbCod.Checked;
     oldStoreInfo.DistrictID = ((Maticsoft.Model.District)cbbDistrict.SelectedItem).DistrictID;
     oldStoreInfo.IsCitySend = chbIsCitySend.Checked;
     oldStoreInfo.IsCoupon = chbIsCoupon.Checked;
     oldStoreInfo.IsSend = chbIsSend.Checked ? 1 : 0;
     oldStoreInfo.KCVIP = chbKCVIP.Checked;
     oldStoreInfo.NoSmoke = chbNoSmoke.Checked;
     oldStoreInfo.OnlinePay = chbOnlinePay.Checked;
     oldStoreInfo.Onlineorder = chbOnlineorder.Checked ? 1 : 0;
     oldStoreInfo.PayCar = chbPayCar.Checked;
     oldStoreInfo.PayCar = chbPayCar.Checked;
     oldStoreInfo.StoreAddress = txtStoreAddressSite.Text.Trim();
     oldStoreInfo.StoreHours = txtStoreHoursSite.Text.Trim();
     oldStoreInfo.StoreName = txtStoreNameSite.Text.Trim();
     oldStoreInfo.StorePhone = txtStorePhoneSite.Text.Trim();
     oldStoreInfo.WIFI = chbWIFI.Checked;
     decimal maxPrice = 0;
     if (decimal.TryParse(txtMaxPriceSite.Text, out maxPrice))
     {
         oldStoreInfo.MaxPrice = maxPrice;
     }
     decimal minPrice = 0;
     if (decimal.TryParse(txtMinPriceSite.Text, out minPrice))
     {
         oldStoreInfo.MinPrice = minPrice;
     }
     oldStoreInfo.BranchName = txtDoubleName.Text.Trim();
     oldStoreInfo.StorePhoto = string.Format("{0}.jpg", oldStoreInfo.BizID);
     return oldStoreInfo;
 }
 private void ClearStoreEntityText(StoreInfoEntity storeInfoEntity)
 {
     chbCarPark.UpdateCheckedState(storeInfoEntity.CarPark);
     chbChildrenChair.UpdateCheckedState(storeInfoEntity.ChildrenChair);
     chbCod.UpdateCheckedState(storeInfoEntity.Cod);
     chbIsCitySend.UpdateCheckedState(storeInfoEntity.IsCitySend);
     chbIsCoupon.UpdateCheckedState(storeInfoEntity.IsCoupon);
     chbIsSend.UpdateCheckedState(storeInfoEntity.IsSend != 0);
     chbKCVIP.UpdateCheckedState(storeInfoEntity.KCVIP);
     chbNoSmoke.UpdateCheckedState(storeInfoEntity.NoSmoke);
     chbOnlinePay.UpdateCheckedState(storeInfoEntity.OnlinePay);
     chbOnlineorder.UpdateCheckedState(storeInfoEntity.Onlineorder != 0);
     chbPayCar.UpdateCheckedState(storeInfoEntity.PayCar);
     chbPayCar.UpdateCheckedState(storeInfoEntity.PayCar);
     chbWIFI.UpdateCheckedState(storeInfoEntity.WIFI);
     chbbox.UpdateCheckedState(storeInfoEntity.Box);
     txtBasicSite.SetTextBoxText(storeInfoEntity.BasicIntroduction);
     txtDoubleName.SetTextBoxText(storeInfoEntity.BranchName);
     txtBusSite.SetTextBoxText(storeInfoEntity.Bus);
     txtMaxPriceSite.SetTextBoxText(storeInfoEntity.MaxPrice.ToString());
     txtMinPriceSite.SetTextBoxText(storeInfoEntity.MinPrice.ToString());
     txtStoreAddressSite.SetTextBoxText(storeInfoEntity.StoreAddress);
     txtStoreHoursSite.SetTextBoxText(string.IsNullOrWhiteSpace(storeInfoEntity.StoreHours) ? "10:00-22:00" : storeInfoEntity.StoreHours);
     txtStoreNameSite.SetTextBoxText(storeInfoEntity.StoreName);
     txtStorePhoneSite.SetTextBoxText(storeInfoEntity.StorePhone);
 }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (catalogueListBox.SelectedIndex < 0)
                {
                    return;
                }
                var catalogueInfo = catalogueListBox.SelectedItem as Maticsoft.Model.Catalogue;
                if (catalogueInfo == null)
                {
                    return;
                }

                var stopwatch = new Stopwatch();
                stopwatch.Start();
                var storeInfoEntity = new Maticsoft.Model.StoreInfoEntity();
                var storeBll = new StoreInfoBll();
                storeInfoEntity.BizID = catalogueInfo.StoreId;
                storeInfoEntity.BasicIntroduction = txtBasic.Text.Trim();
                storeInfoEntity.StoreAddress = txtStoreAddress.Text.Trim();
                storeInfoEntity.StoreHours = txtStoreHours.Text.Trim();
                storeInfoEntity.StoreName = txtStoreName.Text.Trim();
                storeInfoEntity.Box = chbbox.Checked;
                storeInfoEntity.Bus = txtBus.Text.Trim();
                storeInfoEntity.CarPark = !string.IsNullOrEmpty(txtCarPark.Text.Trim());
                storeInfoEntity.PayCar = chbPayCar.Checked;
                storeInfoEntity.WIFI = chbWIFI.Checked;
                storeInfoEntity.KCVIP = chbKCVIP.Checked;
                storeInfoEntity.ChildrenChair = chbChildrenChair.Checked;
                storeInfoEntity.PayCar = chbPayCar.Checked;
                storeInfoEntity.NoSmoke = chbNoSmoke.Checked;
                storeInfoEntity.IsCoupon = chbIsCoupon.Checked;
                storeInfoEntity.IsCitySend = chbIsCitySend.Checked;
                storeInfoEntity.OnlinePay = chbOnlinePay.Checked;
                storeInfoEntity.IsSend = chbIsSend.Checked ? 1 : 0;
                storeInfoEntity.Cod = chbCod.Checked;
                storeInfoEntity.Onlineorder = chbOnlineorder.Checked ? 1 : 0;
                var maxPrice = 0;
                if (int.TryParse(txtMaxPrice.Text, out maxPrice))
                {
                    storeInfoEntity.MaxPrice = maxPrice;
                }
                var minPrice = 0;
                if (int.TryParse(txtMinPrice.Text, out minPrice))
                {
                    storeInfoEntity.MinPrice = minPrice;
                }
                storeInfoEntity.CityID = ((Maticsoft.Model.City)cbBoxCity.SelectedItem).CityID;
                storeInfoEntity.BusinessTypeID = "2";
                if (!string.IsNullOrEmpty(txtDoubleName.Text))
                {
                    storeInfoEntity.BranchName = txtDoubleName.Text.Trim();
                }
                storeInfoEntity.StorePhone = txtStorePhone.Text.Trim();
                storeInfoEntity.BusinessState = 40;
                storeInfoEntity.BusinessAddTime = DateTime.Now;
                if (!string.IsNullOrEmpty(txtImageName.Text.Trim()))
                {
                    storeInfoEntity.StorePhoto = txtImageName.Text;
                }
                storeInfoEntity.DistrictID = ((Maticsoft.Model.District)cbbDistrict.SelectedItem).DistrictID;
                var isExists = false;
                isExists = storeBll.Exists(storeInfoEntity.BizID);

                var storeSpecialBll = new Maticsoft.BLL.StoreSpecialTag();
                if (isExists)
                {
                    storeBll.Update(storeInfoEntity);
                }
                else
                {
                    var storeList = storeBll.GetModelList(string.Empty);
                    var maxShortID = storeList.Max(x =>
                    {
                        var shortId = string.IsNullOrEmpty(x.ShortID) ? "0" : x.ShortID;
                        return int.Parse(shortId);
                    });
                    storeInfoEntity.ShortID = (maxShortID + 1).ToString();
                    storeBll.Add(storeInfoEntity);
                }
                var oldSpecialTagList = storeSpecialBll.GetModelList(string.Format("bizid = '{0}'", storeInfoEntity.BizID));
                foreach (var specialTag in oldSpecialTagList)
                {
                    storeSpecialBll.Delete(specialTag.StoreSpecialTagID);
                }
                foreach (var checkedItem in chlBoxSpecialTag.CheckedItems)
                {
                    var specialTag = checkedItem as SpecialTag;
                    if (specialTag != null)
                    {
                        var storeSpecial = new Maticsoft.Model.StoreSpecialTag();
                        storeSpecial.BizID = storeInfoEntity.BizID;
                        storeSpecial.SpecialTagID = specialTag.SpecialTagID;
                        storeSpecial.TagName = specialTag.TagName;
                        storeSpecial.StoreSpecialTagID = Guid.NewGuid().ToString();
                        storeSpecialBll.Add(storeSpecial);
                    }
                }
                var storeCookingStylesBll = new Maticsoft.BLL.StoreCookingStyles();
                var oldStoreCookingStylesList = storeCookingStylesBll.GetModelList(string.Format("bizid = '{0}'", storeInfoEntity.BizID));
                foreach (var storeCookingStylese in oldStoreCookingStylesList)
                {
                    storeCookingStylesBll.Delete(storeCookingStylese.KeyID);
                }
                foreach (var checkedItem in chbCookingStyles.CheckedItems)
                {
                    var specialTag = checkedItem as Maticsoft.Model.CookingStyles;
                    if (specialTag != null)
                    {
                        var storeCookingStyles = new Maticsoft.Model.StoreCookingStyles();
                        storeCookingStyles.BizID = storeInfoEntity.BizID;
                        storeCookingStyles.CookingStyleID = specialTag.CookingStyleID;
                        storeCookingStyles.CookingStyleName = specialTag.CookingStyleName;
                        storeCookingStyles.KeyID = Guid.NewGuid().ToString();
                        storeCookingStylesBll.Add(storeCookingStyles);
                    }
                }
                var dishesBll = new Maticsoft.BLL.Dishes();
                if (chbDish.Checked)
                {
                    var dishList = dishesBll.GetModelList(string.Format("storeId = '{0}'", storeInfoEntity.BizID));
                    var dishesEntityBll = new Maticsoft.BLL.DishesBll();
                    var dishesEntityList = dishesEntityBll.GetModelList(string.Format("BusinessID = '{0}'", storeInfoEntity.BizID));
                    foreach (var dishesEntity in dishesEntityList)
                    {
                        dishesEntityBll.Delete(dishesEntity.DishesID);
                    }
                    foreach (var dishese in dishList)
                    {
                        var dishesEntity = new DishesEntity();
                        dishesEntity.BusinessID = dishese.StoreId;
                        dishesEntity.DishesName = dishese.DishesName;
                        dishesEntity.CreateDate = DateTime.Now;
                        dishesEntity.DishesID = dishese.DishesID;
                        dishesEntity.ImageUrl = dishese.PictureName;
                        dishesEntity.State = 1;
                        dishesEntity.DishesTypeID = dishese.dishTypeID;
                        if (string.IsNullOrEmpty(dishese.DishesUnit))
                        {
                            dishesEntity.DishesUnit = "份";
                        }
                        else
                        {
                            dishesEntity.DishesUnit = dishese.DishesUnit;
                        }
                        dishesEntity.DishesMoney = decimal.Parse(string.IsNullOrEmpty(dishese.DishesMoney) ? "0" : dishese.DishesMoney.Replace("¥", string.Empty));
                        dishesEntity.IsCurrentPrice = dishesEntity.DishesMoney == 0;
                        dishesEntityBll.Add(dishesEntity);
                    }
                    var dishesTyepTableBll = new Maticsoft.BLL.DishesTyepTable();
                    var dishTypeBll = new Maticsoft.BLL.DishesTyep();
                    var dishTypeList = dishTypeBll.GetModelList(string.Format("BusinessID = '{0}'", storeInfoEntity.BizID));
                    foreach (var dishesTyep in dishTypeList)
                    {
                        dishTypeBll.Delete(dishesTyep.DishesTypeID);
                    }
                    var dishesTypeTableList = dishesTyepTableBll.GetModelList(string.Format("BusinessID = '{0}'", storeInfoEntity.BizID));
                    foreach (var disheseTypeTable in dishesTypeTableList)
                    {
                        var dishesTyep = new Maticsoft.Model.DishesTyep();
                        dishesTyep.BusinessID = disheseTypeTable.BusinessID;
                        dishesTyep.CreateDate = DateTime.Now;
                        dishesTyep.DishesTypeName = disheseTypeTable.DishesTypeName;
                        dishesTyep.DishesTypeID = disheseTypeTable.DishesTypeID;
                        dishTypeBll.Add(dishesTyep);
                    }
                }

                if (chbPic.Checked)
                {
                    var storePicturesTableBll = new StorePicturesTable();
                    var storePicturesBll = new StorePictures();
                    var picList = storePicturesBll.GetModelList(string.Format("BusinessID ='{0}'", storeInfoEntity.BizID));
                    foreach (var storePicturese in picList)
                    {
                        storePicturesBll.Delete(storePicturese.StorePicturesID);
                    }
                    var pcituresList =
                        storePicturesTableBll.GetModelList(string.Format("BusinessID = '{0}'", storeInfoEntity.BizID));
                    foreach (var picturesTable in pcituresList)
                    {
                        var storePicturesTable = new Maticsoft.Model.StorePictures();
                        storePicturesTable.StorePicturesID = picturesTable.StorePicturesID;
                        storePicturesTable.BusPhotoAlbumID = picturesTable.BusPhotoAlbumID;
                        storePicturesTable.BusinessID = picturesTable.BusinessID;
                        storePicturesTable.PictureAddress = picturesTable.PictureAddress;
                        storePicturesTable.PicName = picturesTable.PicName;
                        storePicturesTable.PicState = picturesTable.PicState;
                        storePicturesTable.UploadTime = DateTime.Now;
                        storePicturesBll.Add(storePicturesTable);
                    }

                    var busPhotoAlbumBll = new Maticsoft.BLL.BusPhotoAlbum();
                    var oldBusPhotoAlbumList = busPhotoAlbumBll.GetModelList(string.Format("BusinessID = '{0}'", storeInfoEntity.BizID));
                    foreach (var busPhotoAlbum in oldBusPhotoAlbumList)
                    {
                        busPhotoAlbumBll.Delete(busPhotoAlbum.BusPhotoAlbumID);
                    }
                    var busPhotoAlbumTableBll = new Maticsoft.BLL.BusPhotoAlbumTable();
                    if (!isExists)
                    {
                        var busPhotoAlbumList =
                            busPhotoAlbumTableBll.GetModelList(string.Format("BusinessID = '{0}'", storeInfoEntity.BizID));
                        foreach (var busPhotoAlbumTable in busPhotoAlbumList)
                        {
                            var busPhotoAlbum = new Maticsoft.Model.BusPhotoAlbum();
                            busPhotoAlbum.BusinessID = busPhotoAlbumTable.BusinessID;
                            busPhotoAlbum.BusPhotoAlbumID = busPhotoAlbumTable.BusPhotoAlbumID;
                            busPhotoAlbum.AlbumName = busPhotoAlbumTable.AlbumName;
                            busPhotoAlbum.IsDefault = busPhotoAlbumTable.IsDefault;
                            busPhotoAlbumBll.Add(busPhotoAlbum);
                        }
                    }
                }

                var storeLocalTagBll = new Maticsoft.BLL.StoreLocalTag();
                var oldStoreLocalTagList = storeLocalTagBll.GetModelList(string.Format("bizid = '{0}'", storeInfoEntity.BizID));
                foreach (var storeLocalTag in oldStoreLocalTagList)
                {
                    storeLocalTagBll.Delete(storeLocalTag.KeyID);
                }
                foreach (var selectedItem in clbStoreTag.CheckedItems)
                {
                    var cityLocalTag = ((Maticsoft.Model.CityLocalTagEntity)selectedItem);
                    var storeLocalTag = new Maticsoft.Model.StoreLocalTag();
                    storeLocalTag.BizID = storeInfoEntity.BizID;
                    storeLocalTag.BizType = 10;
                    storeLocalTag.DistrictID = storeInfoEntity.DistrictID;
                    storeLocalTag.KeyID = Guid.NewGuid().ToString();
                    storeLocalTag.LocalTagID = cityLocalTag.LocalTagID;
                    storeLocalTag.LocalTagName = cityLocalTag.TagName;
                    storeLocalTagBll.Add(storeLocalTag);
                }

                var storeInfoBll = new Maticsoft.BLL.StoreInfo();
                var storeInfo = storeInfoList.Find(x => x.storeId == storeInfoEntity.BizID);
                if (storeInfo != null)
                {
                    if (isExists)
                    {
                        storeInfoBll.Update(storeInfo);
                    }
                    else
                    {
                        storeInfoBll.Add(storeInfo);
                    }
                }

                foreach (var selectedIndex in clbStoreTag.CheckedIndices)
                {
                    clbStoreTag.SetItemCheckState((int)selectedIndex, CheckState.Unchecked);
                }
                foreach (var selectedIndex in chlBoxSpecialTag.CheckedIndices)
                {
                    chlBoxSpecialTag.SetItemCheckState((int)selectedIndex, CheckState.Unchecked);
                }
                foreach (var selectedIndex in chbCookingStyles.CheckedIndices)
                {
                    chbCookingStyles.SetItemCheckState((int)selectedIndex, CheckState.Unchecked);
                }
                stopwatch.Stop();
                MessageBox.Show(string.Format(@"{0}保存成功,耗时{1}", storeInfoEntity.StoreName, stopwatch.ElapsedMilliseconds));
                catalogueListBox.SetItemCheckState(catalogueListBox.SelectedIndex, CheckState.Checked);
                if (catalogueListBox.SelectedIndex < catalogueListBox.Items.Count - 1)
                {
                    catalogueListBox.SelectedIndex += 1;
                }
                SetCatalogueListBox();

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {

                if (catalogueListBox.SelectedIndex < 0)
                {
                    return;
                }
                var catalogueInfo = catalogueListBox.SelectedItem as Maticsoft.Model.Catalogue;
                if (catalogueInfo == null)
                {
                    return;
                }
                //var collection = new Collection();
                //var storeInfo = collection.CollectionStore(catalogueInfo.href, catalogueInfo);
                //if (storeInfo == null)
                //{
                //    return;
                //}
                var storeInfoEntity = new Maticsoft.Model.StoreInfoEntity();
                var storeBll = new StoreInfoBll();
                storeInfoEntity.BizID = catalogueInfo.StoreId;
                storeInfoEntity.BasicIntroduction = txtBasic.Text.Trim();
                storeInfoEntity.StoreAddress = txtStoreAddress.Text.Trim();
                storeInfoEntity.StoreHours = txtStoreHours.Text.Trim();
                storeInfoEntity.StoreName = txtStoreName.Text.Trim();
                storeInfoEntity.Box = chbbox.Checked;
                storeInfoEntity.Bus = txtBus.Text.Trim();
                storeInfoEntity.CarPark = !string.IsNullOrEmpty(txtCarPark.Text.Trim());
                storeInfoEntity.PayCar = chbPayCar.Checked;
                storeInfoEntity.WIFI = chbWIFI.Checked;
                storeInfoEntity.KCVIP = chbKCVIP.Checked;
                storeInfoEntity.ChildrenChair = chbChildrenChair.Checked;
                storeInfoEntity.PayCar = chbPayCar.Checked;
                storeInfoEntity.NoSmoke = chbNoSmoke.Checked;
                storeInfoEntity.IsCoupon = chbIsCoupon.Checked;
                storeInfoEntity.IsCitySend = chbIsCitySend.Checked;
                storeInfoEntity.OnlinePay = chbOnlinePay.Checked;
                storeInfoEntity.IsSend = chbIsSend.Checked ? 1 : 0;
                storeInfoEntity.Cod = chbCod.Checked;
                storeInfoEntity.Onlineorder = chbOnlineorder.Checked ? 1 : 0;
                var maxPrice = 0;
                if (int.TryParse(txtMaxPrice.Text, out maxPrice))
                {
                    storeInfoEntity.MaxPrice = maxPrice;
                }
                var minPrice = 0;
                if (int.TryParse(txtMinPrice.Text, out minPrice))
                {
                    storeInfoEntity.MinPrice = minPrice;
                }
                storeInfoEntity.CityID = ((Maticsoft.Model.City)cbBoxCity.SelectedItem).CityID;
                storeInfoEntity.BusinessTypeID = "2";
                if (!string.IsNullOrEmpty(txtDoubleName.Text))
                {
                    storeInfoEntity.BranchName = txtDoubleName.Text.Trim();
                }
                storeInfoEntity.StorePhone = txtStorePhone.Text.Trim();
                storeInfoEntity.BusinessState = 40;
                storeInfoEntity.BusinessAddTime = DateTime.Now;
                if (!string.IsNullOrEmpty(txtImageName.Text.Trim()))
                {
                    storeInfoEntity.StorePhoto = txtImageName.Text;
                }
                storeInfoEntity.DistrictID = ((Maticsoft.Model.District)cbbDistrict.SelectedItem).DistrictID;
                var isExists = false;
                isExists = storeBll.Exists(storeInfoEntity.BizID);

                var storeSpecialBll = new Maticsoft.BLL.StoreSpecialTag();
                if (isExists)
                {
                    storeBll.Update(storeInfoEntity);
                }
                else
                {
                    var storeList = storeBll.GetModelList(string.Empty);
                    var maxShortID = storeList.Max(x =>
                    {
                        var shortId = string.IsNullOrEmpty(x.ShortID) ? "0" : x.ShortID;
                        return int.Parse(shortId);
                    });
                    storeInfoEntity.ShortID = (maxShortID + 1).ToString();
                    storeBll.Add(storeInfoEntity);
                }
                foreach (var checkedItem in chlBoxSpecialTag.CheckedItems)
                {
                    var specialTag = checkedItem as SpecialTag;
                    if (specialTag != null)
                    {
                        var storeSpecial = new Maticsoft.Model.StoreSpecialTag();
                        storeSpecial.BizID = storeInfoEntity.BizID;
                        storeSpecial.SpecialTagID = specialTag.SpecialTagID;
                        storeSpecial.TagName = specialTag.TagName;
                        storeSpecial.StoreSpecialTagID = Guid.NewGuid().ToString();
                        storeSpecialBll.Add(storeSpecial);
                    }
                }
                var storeCookingStylesBll = new Maticsoft.BLL.StoreCookingStyles();
                foreach (var checkedItem in chbCookingStyles.CheckedItems)
                {
                    var specialTag = checkedItem as Maticsoft.Model.CookingStyles;
                    if (specialTag != null)
                    {
                        var storeCookingStyles = new Maticsoft.Model.StoreCookingStyles();
                        storeCookingStyles.BizID = storeInfoEntity.BizID;
                        storeCookingStyles.CookingStyleID = specialTag.CookingStyleID;
                        storeCookingStyles.CookingStyleName = specialTag.CookingStyleName;
                        storeCookingStyles.KeyID = Guid.NewGuid().ToString();
                        storeCookingStylesBll.Add(storeCookingStyles);
                    }
                }
                var dishesBll = new Maticsoft.BLL.Dishes();
                if (chbDish.Checked)
                {
                    var dishList = dishesBll.GetModelList(string.Format("storeId = '{0}'", storeInfoEntity.BizID));
                    var dishesEntityBll = new Maticsoft.BLL.DishesBll();
                    var dishesEntityList = dishesEntityBll.GetModelList(string.Format("BusinessID = '{0}'", storeInfoEntity.BizID));
                    foreach (var dishesEntity in dishesEntityList)
                    {
                        dishesEntityBll.Delete(dishesEntity.DishesID);
                    }
                    foreach (var dishese in dishList)
                    {
                        var dishesEntity = new DishesEntity();
                        dishesEntity.BusinessID = dishese.StoreId;
                        dishesEntity.DishesName = dishese.DishesName;
                        dishesEntity.CreateDate = DateTime.Now;
                        dishesEntity.DishesID = dishese.DishesID;
                        dishesEntity.ImageUrl = dishese.PictureName;
                        dishesEntity.State = 1;
                        dishesEntity.DishesTypeID = dishese.dishTypeID;
                        dishesEntity.DishesUnit = "份";
                        dishesEntity.DishesMoney = decimal.Parse(dishese.DishesMoney.Replace("¥", string.Empty));
                        dishesEntityBll.Add(dishesEntity);
                    }
                    var dishesTyepTableBll = new Maticsoft.BLL.DishesTyepTable();
                    var dishTypeBll = new Maticsoft.BLL.DishesTyep();
                    var dishTypeList = dishTypeBll.GetModelList(string.Format("BusinessID = '{0}'", storeInfoEntity.BizID));
                    foreach (var dishesTyep in dishTypeList)
                    {
                        dishTypeBll.Delete(dishesTyep.DishesTypeID);
                    }
                    var dishesTypeTableList = dishesTyepTableBll.GetModelList(string.Format("BusinessID = '{0}'", storeInfoEntity.BizID));
                    foreach (var disheseTypeTable in dishesTypeTableList)
                    {
                        var dishesTyep = new Maticsoft.Model.DishesTyep();
                        dishesTyep.BusinessID = disheseTypeTable.BusinessID;
                        dishesTyep.CreateDate = DateTime.Now;
                        dishesTyep.DishesTypeName = disheseTypeTable.DishesTypeName;
                        dishesTyep.DishesTypeID = disheseTypeTable.DishesTypeID;
                        dishTypeBll.Add(dishesTyep);
                    }
                }

                if (chbPic.Checked)
                {
                    var storePicturesTableBll = new StorePicturesTable();
                    var storePicturesBll = new StorePictures();
                    var picList = storePicturesBll.GetModelList(string.Format("BusinessID ='{0}'", storeInfoEntity.BizID));
                    foreach (var storePicturese in picList)
                    {
                        storePicturesBll.Delete(storePicturese.StorePicturesID);
                    }
                    var pcituresList =
                        storePicturesTableBll.GetModelList(string.Format("BusinessID = '{0}'", storeInfoEntity.BizID));
                    foreach (var picturesTable in pcituresList)
                    {
                        var storePicturesTable = new Maticsoft.Model.StorePictures();
                        storePicturesTable.StorePicturesID = picturesTable.StorePicturesID;
                        storePicturesTable.BusPhotoAlbumID = picturesTable.BusPhotoAlbumID;
                        storePicturesTable.BusinessID = picturesTable.BusinessID;
                        storePicturesTable.PictureAddress = picturesTable.PictureAddress;
                        storePicturesTable.PicName = picturesTable.PicName;
                        storePicturesTable.PicState = picturesTable.PicState;
                        storePicturesTable.UploadTime = DateTime.Now;
                        storePicturesBll.Add(storePicturesTable);
                    }

                    var busPhotoAlbumBll = new Maticsoft.BLL.BusPhotoAlbum();
                    var oldBusPhotoAlbumList = busPhotoAlbumBll.GetModelList(string.Format("BusinessID = '{0}'", storeInfoEntity.BizID));
                    foreach (var busPhotoAlbum in oldBusPhotoAlbumList)
                    {
                        busPhotoAlbumBll.Delete(busPhotoAlbum.BusPhotoAlbumID);
                    }
                    var busPhotoAlbumTableBll = new Maticsoft.BLL.BusPhotoAlbumTable();
                    if (!isExists)
                    {
                        var busPhotoAlbumList =
                            busPhotoAlbumTableBll.GetModelList(string.Format("BusinessID = '{0}'", storeInfoEntity.BizID));
                        foreach (var busPhotoAlbumTable in busPhotoAlbumList)
                        {
                            var busPhotoAlbum = new Maticsoft.Model.BusPhotoAlbum();
                            busPhotoAlbum.BusinessID = busPhotoAlbumTable.BusinessID;
                            busPhotoAlbum.BusPhotoAlbumID = busPhotoAlbumTable.BusPhotoAlbumID;
                            busPhotoAlbum.AlbumName = busPhotoAlbumTable.AlbumName;
                            busPhotoAlbum.IsDefault = busPhotoAlbumTable.IsDefault;
                            busPhotoAlbumBll.Add(busPhotoAlbum);
                        }
                    }
                }

                var storeLocalTagBll = new Maticsoft.BLL.StoreLocalTag();
                foreach (var selectedItem in clbStoreTag.SelectedItems)
                {
                    var cityLocalTag = ((Maticsoft.Model.CityLocalTagEntity)selectedItem);
                    var storeLocalTag = new Maticsoft.Model.StoreLocalTag();
                    storeLocalTag.BizID = storeInfoEntity.BizID;
                    storeLocalTag.BizType = 10;
                    storeLocalTag.DistrictID = storeInfoEntity.DistrictID;
                    storeLocalTag.KeyID = Guid.NewGuid().ToString();
                    storeLocalTag.LocalTagID = cityLocalTag.LocalTagID;
                    storeLocalTag.LocalTagName = cityLocalTag.TagName;
                    storeLocalTagBll.Add(storeLocalTag);
                }

                var storeInfoBll = new Maticsoft.BLL.StoreInfo();
                var storeInfo = storeInfoList.Find(x => x.storeId == storeInfoEntity.BizID);
                if (storeInfo != null)
                {
                    if (isExists)
                    {
                        storeInfoBll.Update(storeInfo);
                    }
                    else
                    {
                        storeInfoBll.Add(storeInfo);
                    }
                }

                foreach (var selectedIndex in clbStoreTag.CheckedIndices)
                {
                    clbStoreTag.SetItemCheckState((int)selectedIndex, CheckState.Unchecked);
                }
                foreach (var selectedIndex in chlBoxSpecialTag.CheckedIndices)
                {
                    chlBoxSpecialTag.SetItemCheckState((int)selectedIndex, CheckState.Unchecked);
                }
                foreach (var selectedIndex in chbCookingStyles.CheckedIndices)
                {
                    chbCookingStyles.SetItemCheckState((int)selectedIndex, CheckState.Unchecked);
                }
                //try
                //{
                //    if (!string.IsNullOrEmpty(storeInfoEntity.StorePhoto))
                //    {
                //        var fileName = file.FileName;
                //        string newPath = string.Format("./imagefiles/shop/"); //大图添加水印保存路径
                //        string newThumbnail = string.Format("./imagefiles/Thumbnail//shop/");
                //        //缩略图添加水印保存路径

                //        if (!Directory.Exists(newPath))
                //        {
                //            Directory.CreateDirectory(newPath);
                //        }
                //        if (!Directory.Exists(newThumbnail))
                //        {
                //            Directory.CreateDirectory(newThumbnail);
                //        }
                //        var initImage = new Bitmap(fileName);
                //        db.ZoomAuto(fileName, newPath + storeInfoEntity.StorePhoto, initImage.Width, initImage.Height);
                //        //生成缩略图
                //        db.ZoomAuto(fileName, newThumbnail + storeInfoEntity.StorePhoto, 350,
                //            260);
                //        //生成缩略图
                //        db.ZoomAuto(fileName, string.Format(newThumbnail + "350_260_" + storeInfoEntity.StorePhoto), 350,
                //            260); //生成缩略图
                //        db.ZoomAuto(fileName, string.Format(newThumbnail + "160_120_" + storeInfoEntity.StorePhoto), 160,
                //            120); //生成缩略图

                //    }

                //}
                //catch (Exception)
                //{

                //    throw;
                //}
                MessageBox.Show(string.Format(@"{0}保存成功", storeInfoEntity.StoreName));
                if (catalogueListBox.SelectedIndex < catalogueListBox.Items.Count - 1)
                {
                    catalogueListBox.SelectedIndex += 1;
                }
                SetCatalogueListBox();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }