예제 #1
0
        //更新信息
        public static StoreInfo StoreInfoUpload(StoreInfo storeInfo, ContactInfo contactInfo
                                                , StorePhoto storePhoto, StoreDesc storeDesc, out AlertMessage alertMessage)
        {
            //权限检查
            if (!AUTH.PermissionCheck(ModuleInfo, ActionInfos.Where(i => i.Name == (storeInfo.ID == 0 ? "Create" : "Modify")).FirstOrDefault(), out string Message))
            {
                alertMessage = new AlertMessage {
                    Message = Message, Type = AlertType.warning
                };
                return(null);
            }

            //表单检查
            if (string.IsNullOrWhiteSpace(storeInfo.Name))
            {
                alertMessage = new AlertMessage {
                    Message = "门店代码不能为空。", Type = AlertType.warning
                };
                return(null);
            }
            if (string.IsNullOrWhiteSpace(storeInfo.Title))
            {
                alertMessage = new AlertMessage {
                    Message = "门店名称不能为空。", Type = AlertType.warning
                };
                return(null);
            }

            using (var EF = new EF())
            {
                //修改是否存在?代码、名称唯一?
                StoreInfo store_exist       = null;
                StoreInfo store_name_exist  = null;
                StoreInfo store_title_exist = null;
                if (storeInfo.ID == 0)
                {
                    store_name_exist  = EF.StoreInfos.Where(i => i.Name == storeInfo.Name).FirstOrDefault();
                    store_title_exist = EF.StoreInfos.Where(i => i.Title == storeInfo.Title).FirstOrDefault();
                }
                else
                {
                    store_exist = EF.StoreInfos.Where(i => i.ID == storeInfo.ID).FirstOrDefault();
                    if (store_exist == null)
                    {
                        alertMessage = new AlertMessage {
                            Message = string.Format("门店编号[{0}]不存在。", storeInfo.ID), Type = AlertType.warning
                        };
                        return(null);
                    }
                    store_name_exist  = EF.StoreInfos.Where(i => i.ID != storeInfo.ID && i.Name == storeInfo.Name).FirstOrDefault();
                    store_title_exist = EF.StoreInfos.Where(i => i.ID != storeInfo.ID && i.Title == storeInfo.Title).FirstOrDefault();
                }
                if (store_name_exist != null && store_name_exist.ID > 0)
                {
                    alertMessage = new AlertMessage {
                        Message = string.Format("门店代码[{0}]已被ID[{1}]使用。", storeInfo.Name, store_name_exist.ID), Type = AlertType.warning
                    };
                    return(null);
                }
                if (store_title_exist != null && store_title_exist.ID > 0)
                {
                    alertMessage = new AlertMessage {
                        Message = string.Format("门店名称[{0}]已被ID[{1}]使用。", storeInfo.Title, store_title_exist.ID), Type = AlertType.warning
                    };
                    return(null);
                }

                //数据保存
                using (TransactionScope TS = new TransactionScope())
                {
                    //店名
                    if (storeInfo.ID == 0)
                    {
                        store_exist = EF.StoreInfos.Add(new StoreInfo {
                            Enabled = true,
                        });
                    }
                    store_exist.Name       = storeInfo.Name;
                    store_exist.Title      = storeInfo.Title;
                    store_exist.LogoFileID = storeInfo.LogoFileID;
                    EF.SaveChanges();
                    //联系信息
                    var contactInfo_exist = EF.ContactInfos.Where(i => i.EMail == contactInfo.EMail && i.Phone == contactInfo.Phone &&
                                                                  i.Address == contactInfo.Address &&
                                                                  i.Latitude == contactInfo.Latitude &&
                                                                  i.Longitude == contactInfo.Longitude).FirstOrDefault();
                    if (contactInfo_exist == null)
                    {
                        EF.ContactInfos.Add(contactInfo_exist = contactInfo);
                        EF.SaveChanges();
                    }
                    var storeContact_exist = EF.StoreContacts.Where(i => i.StoreID == store_exist.ID).FirstOrDefault();
                    if (storeContact_exist == null)
                    {
                        EF.StoreContacts.Add(storeContact_exist = new StoreContact
                        {
                            StoreID   = store_exist.ID,
                            ContactID = contactInfo_exist.ID,
                        });
                    }
                    else
                    {
                        storeContact_exist.ContactID = contactInfo_exist.ID;
                    }
                    //图文
                    var photo_exist = EF.StorePhotos.Where(i => i.StoreID == store_exist.ID).FirstOrDefault();
                    if (photo_exist == null)
                    {
                        EF.StorePhotos.Add(photo_exist = new StorePhoto {
                            StoreID = store_exist.ID,
                        });
                    }
                    photo_exist.FileIDs = storePhoto.FileIDs;
                    var desc_exist = EF.StoreDescs.Where(i => i.StoreID == store_exist.ID).FirstOrDefault();
                    if (desc_exist == null)
                    {
                        EF.StoreDescs.Add(desc_exist = new StoreDesc {
                            StoreID = store_exist.ID,
                        });
                    }
                    desc_exist.BusinessHours = storeDesc.BusinessHours;
                    desc_exist.Description   = storeDesc.Description;

                    //保存
                    EF.SaveChanges();
                    TS.Complete();
                }
                //更新完成
                alertMessage = null;
                return(store_exist);
            }
        }
예제 #2
0
        //信息表单保存按钮
        public void InfoFormSubmit_Click(object sender, EventArgs e)
        {
            var FileUploadInfos = new List <FileUploadInfo>();

            if (inpInfoFormLogo.PostedFile.ContentLength > 0)
            {
                var FileUploadInfo = Ziri.BLL.SYS.DOC.Upload(inpInfoFormLogo.PostedFile, MapPath("/DOC/upload/"), out string Message);
                if (Message != null)
                {
                    Page.ClientScript.RegisterStartupScript(Page.GetType(), "InfoFormSaveMessage"
                                                            , string.Format("<script> document.getElementById('btnListInfoFormModal').click(); swal('{0}', '', '{1}'); </script>", Message, AlertType.error));
                    return;
                }
                FileUploadInfos.Add(FileUploadInfo);
            }
            long hidLogoFileID = 0;

            try { hidLogoFileID = long.Parse(hidInfoFormLogoFileID.Value); } catch { }
            //店名
            var storeInfo = new Ziri.MDL.StoreInfo
            {
                ID         = long.Parse(hidInfoFormStoreID.Value),
                Name       = inpInfoFormStoreName.Text,
                Title      = inpInfoFormStoreTitle.Text,
                LogoFileID = FileUploadInfos.Count == 0 ? hidLogoFileID : FileUploadInfos[0].FileInfo.ID,
            };
            //联系信息
            var latitude = 0M;

            try { latitude = decimal.Parse(inpInfoFormLatitude.Text); } catch { }
            var longitude = 0M;

            try { longitude = decimal.Parse(inpInfoFormLongitude.Text); } catch { }
            var contactInfo = new ContactInfo
            {
                EMail     = inpInfoFormEmail.Value,
                Phone     = inpInfoFormPhone.Value,
                Address   = inpInfoFormAddress.Text,
                Latitude  = latitude,
                Longitude = longitude,
            };
            //图文
            var photoUploadInfos = JsonConvert.DeserializeObject <List <FileUploadInfo> >(hidInfoFormStorePhoto.Value);
            var storePhoto       = new StorePhoto
            {
                FileIDs = string.Join(",", photoUploadInfos.Select(i => i.FileInfo.ID)),
            };
            var storeDesc = new StoreDesc
            {
                BusinessHours = inpInfoFormBusinessHours.Text,
                Description   = HttpUtility.UrlDecode(hidInfoFormStoreDesc.Value)
            };

            //保存
            storeInfo = Ziri.BLL.RMS.Store.StoreInfoUpload(storeInfo, contactInfo, storePhoto, storeDesc, out AlertMessage alertMessage);
            if (alertMessage == null)
            {
                ListBind();
            }
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "InfoFormMessage", alertMessage == null
                ? string.Format("<script> swal('保存完成,门店编号[{0}]。', '', '{1}'); </script>", storeInfo.ID, AlertType.success)
                : string.Format("<script> document.getElementById('btnListInfoFormModal').click(); swal('{0}', '', '{1}'); </script>", alertMessage.Message, alertMessage.Type));
        }