Esempio n. 1
0
        public static bool ModifyReceiver(ReceiverEntity entity)
        {
            long result = 0;

            if (entity != null)
            {
                ReceiverRepository mr = new ReceiverRepository();

                ReceiverInfo ReceiverInfo = TranslateReceiverInfo(entity);

                ContactJsonEntity jsonlist = null;
                if (!string.IsNullOrEmpty(entity.ContactJson))
                {
                    try
                    {
                        jsonlist = (ContactJsonEntity)JsonHelper.FromJson(entity.ContactJson, typeof(ContactJsonEntity));
                    }
                    catch (Exception ex)
                    {
                        string str = ex.ToString();
                    }
                }

                if (entity.ReceiverID > 0)
                {
                    ReceiverInfo.ReceiverID = entity.ReceiverID;
                    ReceiverInfo.ChangeDate = DateTime.Now;
                    result = mr.ModifyReceiver(ReceiverInfo);
                }
                else
                {
                    ReceiverInfo.ChangeDate = DateTime.Now;
                    ReceiverInfo.CreateDate = DateTime.Now;
                    result = mr.CreateNew(ReceiverInfo);
                }

                #region 更新联系人信息
                if (jsonlist != null)
                {
                    List <ContactJson> list = jsonlist.listContact;
                    if (list != null && list.Count > 0)
                    {
                        foreach (ContactJson cc in list)
                        {
                            ContactRepository cr      = new ContactRepository();
                            ContactInfo       contact = new ContactInfo();
                            contact.ContactName = cc.ContactName;
                            contact.Mobile      = cc.Mobile;
                            contact.Telephone   = cc.Telephone;
                            contact.Email       = cc.Email;
                            contact.Remark      = cc.Remark;
                            contact.UnionType   = UnionType.Receiver.ToString();//客户
                            if (cc.ContactID > 0)
                            {
                                contact.ContactID  = cc.ContactID;
                                contact.UnionID    = entity.ReceiverID;
                                contact.ChangeDate = DateTime.Now;
                                cr.ModifyContact(contact);
                            }
                            else
                            {
                                contact.UnionID    = entity.ReceiverID > 0 ? entity.ReceiverID : result;
                                contact.CreateDate = DateTime.Now;
                                contact.ChangeDate = DateTime.Now;
                                cr.CreateNew(contact);
                            }
                        }
                    }
                }
                #endregion

                List <ReceiverInfo> miList = mr.GetAllReceiver();//刷新缓存
                Cache.Add("ReceiverALL", miList);

                Cache.Add("GetReceiverByCustomerID" + entity.CustomerID, miList);
            }
            return(result > 0);
        }
Esempio n. 2
0
        public static bool ModifyStorage(StorageEntity StorageEntity)
        {
            long result          = 0;
            StorageRepository mr = new StorageRepository();

            if (StorageEntity != null)
            {
                StorageInfo StorageInfo = TranslateStorageInfo(StorageEntity);

                ContactJsonEntity jsonlist = null;
                if (!string.IsNullOrEmpty(StorageEntity.ContactJson))
                {
                    try
                    {
                        jsonlist = (ContactJsonEntity)JsonHelper.FromJson(StorageEntity.ContactJson, typeof(ContactJsonEntity));
                    }
                    catch (Exception ex)
                    {
                        string str = ex.ToString();
                    }
                }

                if (StorageEntity.StorageID > 0)
                {
                    StorageInfo.ChangeDate = DateTime.Now;
                    result = mr.ModifyStorage(StorageInfo);
                }
                else
                {
                    StorageInfo.CreateDate = DateTime.Now;
                    StorageInfo.ChangeDate = DateTime.Now;
                    result = mr.CreateNew(StorageInfo);
                }

                #region 更新联系人信息
                if (jsonlist != null)
                {
                    List <ContactJson> list = jsonlist.listContact;
                    if (list != null && list.Count > 0)
                    {
                        foreach (ContactJson cc in list)
                        {
                            ContactRepository cr      = new ContactRepository();
                            ContactInfo       contact = new ContactInfo();
                            contact.ContactName = cc.ContactName;
                            contact.Mobile      = cc.Mobile;
                            contact.Telephone   = cc.Telephone;
                            contact.Email       = cc.Email;
                            contact.Remark      = cc.Remark;
                            contact.UnionType   = UnionType.Storage.ToString();//仓库
                            if (cc.ContactID > 0)
                            {
                                contact.ContactID  = cc.ContactID;
                                contact.UnionID    = StorageEntity.StorageID;
                                contact.ChangeDate = DateTime.Now;
                                cr.ModifyContact(contact);
                            }
                            else
                            {
                                contact.UnionID    = StorageEntity.StorageID > 0 ? StorageEntity.StorageID : result;
                                contact.CreateDate = DateTime.Now;
                                contact.ChangeDate = DateTime.Now;
                                cr.CreateNew(contact);
                            }
                        }
                    }
                }
                #endregion
            }
            List <StorageInfo> miList = mr.GetAllstorage();
            Cache.Add("StorageALL", miList);
            return(result > 0);
        }