コード例 #1
0
        public override bool DeleteData(int userId, int id, out Notification notification)
        {
            notification = new Library.DTO.Notification {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (FactorySaleInvoiceEntities context = CreateContext())
                {
                    var dbItem = context.FactorySaleInvoice.Where(o => o.FactorySaleInvoiceID == id).FirstOrDefault();
                    context.FactorySaleInvoice.Remove(dbItem);

                    context.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                notification.DetailMessage.Add(ex.Message);
                if (ex.GetBaseException() != null)
                {
                    notification.DetailMessage.Add(ex.GetBaseException().Message);
                }
                return(false);
            }
        }
コード例 #2
0
        //Status
        public int SetFactorySaleInvoiceStatus(int userId, int factorySaleInvoiceID, int factorySaleInvoiceStatusID, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            int?oldFactorySaleInvoiceStatusID = null;

            try
            {
                using (FactorySaleInvoiceEntities context = CreateContext())
                {
                    var purchaseInvoiceStatuses   = context.SupportMng_FactorySaleInvoiceStatus_View.ToList();
                    var currentFactorySaleInvoice = context.FactorySaleInvoice.Where(o => o.FactorySaleInvoiceID == factorySaleInvoiceID).FirstOrDefault();
                    oldFactorySaleInvoiceStatusID = currentFactorySaleInvoice.FactorySaleInvoiceStatusID;
                    Hashtable input = new Hashtable();
                    DTO.FactorySaleInvoiceDTO dtoItem = GetData(userId, currentFactorySaleInvoice.FactorySaleInvoiceID, input, out notification).Data;


                    //check valid status
                    int?oldDisplayOrder = purchaseInvoiceStatuses.Where(o => o.FactorySaleInvoiceStatusID == oldFactorySaleInvoiceStatusID).FirstOrDefault().DisplayOrder;
                    int?newDisplayOrder = purchaseInvoiceStatuses.Where(o => o.FactorySaleInvoiceStatusID == factorySaleInvoiceStatusID).FirstOrDefault().DisplayOrder;

                    if (newDisplayOrder <= oldDisplayOrder)
                    {
                        var checkinvoice = context.ReceiptNoteSaleInvoice.Where(o => o.FactorySaleInvoiceID == factorySaleInvoiceID).Count();
                        if (newDisplayOrder == 1 && oldDisplayOrder == 2 && checkinvoice == 0)
                        {
                            notification.Message = purchaseInvoiceStatuses.Where(o => o.FactorySaleInvoiceStatusID == factorySaleInvoiceStatusID).FirstOrDefault().FactorySaleInvoiceStatusNM + " success !!!";
                            currentFactorySaleInvoice.FactorySaleInvoiceStatusID = factorySaleInvoiceStatusID;
                            currentFactorySaleInvoice.UpdatedBy   = userId;
                            currentFactorySaleInvoice.UpdatedDate = DateTime.Now;
                            context.SaveChanges();
                        }
                        else
                        {
                            string currentStatusName = purchaseInvoiceStatuses.Where(o => o.FactorySaleInvoiceStatusID == oldFactorySaleInvoiceStatusID).FirstOrDefault().FactorySaleInvoiceStatusNM;
                            string newStatusName     = purchaseInvoiceStatuses.Where(o => o.FactorySaleInvoiceStatusID == factorySaleInvoiceStatusID).FirstOrDefault().FactorySaleInvoiceStatusNM;
                            if (checkinvoice > 0)
                            {
                                throw new Exception("Invoice has been created Receipt Note .Can not set status from " + currentStatusName + " to " + newStatusName);
                            }
                            else
                            {
                                throw new Exception("Can not set status from " + currentStatusName + " to " + newStatusName);
                            }
                        }
                    }
                    else
                    {
                        if (newDisplayOrder == 2)
                        {
                            notification.Message = purchaseInvoiceStatuses.Where(o => o.FactorySaleInvoiceStatusID == factorySaleInvoiceStatusID).FirstOrDefault().FactorySaleInvoiceStatusNM + " success !!!";
                            currentFactorySaleInvoice.FactorySaleInvoiceStatusID = factorySaleInvoiceStatusID;
                            //currentFactorySaleInvoice.SetStatusBy = userId;
                            //currentFactorySaleInvoice.SetStatusDate = DateTime.Now;
                            currentFactorySaleInvoice.UpdatedBy   = userId;
                            currentFactorySaleInvoice.UpdatedDate = DateTime.Now;
                            context.SaveChanges();
                        }
                        else
                        {
                            if (newDisplayOrder == 3)
                            {
                                notification.Message = purchaseInvoiceStatuses.Where(o => o.FactorySaleInvoiceStatusID == factorySaleInvoiceStatusID).FirstOrDefault().FactorySaleInvoiceStatusNM + " success !!!";
                                currentFactorySaleInvoice.FactorySaleInvoiceStatusID = factorySaleInvoiceStatusID;
                                //currentFactorySaleInvoice.SetStatusBy = userId;
                                //currentFactorySaleInvoice.SetStatusDate = DateTime.Now;
                                //currentFactorySaleInvoice.FinishDate = DateTime.Now;
                                currentFactorySaleInvoice.UpdatedBy   = userId;
                                currentFactorySaleInvoice.UpdatedDate = DateTime.Now;
                                context.SaveChanges();
                            }
                            else
                            {
                                notification.Message = purchaseInvoiceStatuses.Where(o => o.FactorySaleInvoiceStatusID == factorySaleInvoiceStatusID).FirstOrDefault().FactorySaleInvoiceStatusNM + " success !!!";
                                currentFactorySaleInvoice.FactorySaleInvoiceStatusID = factorySaleInvoiceStatusID;
                                //currentFactorySaleInvoice.SetStatusBy = userId;
                                //currentFactorySaleInvoice.SetStatusDate = DateTime.Now;
                                currentFactorySaleInvoice.UpdatedBy   = userId;
                                currentFactorySaleInvoice.UpdatedDate = DateTime.Now;
                                context.SaveChanges();
                            }
                        }
                    }
                    return(factorySaleInvoiceStatusID);
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.GetInnerException(ex).Message;
                return(oldFactorySaleInvoiceStatusID.Value);
            }
        }
コード例 #3
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.FactorySaleInvoiceDTO dtoFactorySaleInvoice = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.FactorySaleInvoiceDTO>();
            try
            {
                using (FactorySaleInvoiceEntities context = CreateContext())
                {
                    FactorySaleInvoice dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new FactorySaleInvoice();
                        context.FactorySaleInvoice.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.FactorySaleInvoice.Where(o => o.FactorySaleInvoiceID == id).FirstOrDefault();
                    }
                    if (dbItem == null)
                    {
                        notification.Message = "data not found!";
                        return(false);
                    }
                    else
                    {
                        //upload file
                        Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory();
                        string tempFolder = FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\";
                        if (dtoFactorySaleInvoice.File_HasChange.HasValue && dtoFactorySaleInvoice.File_HasChange.Value)
                        {
                            dtoFactorySaleInvoice.AttachedFile = fwFactory.CreateFilePointer(tempFolder, dtoFactorySaleInvoice.File_NewFile, dtoFactorySaleInvoice.AttachedFile, dtoFactorySaleInvoice.FriendlyName);
                        }

                        //convert dto to db
                        converter.DTO2DB_FactorySaleInvoice(dtoFactorySaleInvoice, ref dbItem, userId);

                        if (id == 0)
                        {
                            dbItem.FactorySaleInvoiceStatusID = 1;
                            //dbItem.SetStatusBy = userId;
                            //dbItem.SetStatusDate = DateTime.Now;
                        }
                        //remove orphan
                        context.FactorySaleInvoiceDetail.Local.Where(o => o.FactorySaleInvoice == null).ToList().ForEach(o => context.FactorySaleInvoiceDetail.Remove(o));

                        //save data
                        context.SaveChanges();

                        //generate purchase invoice code
                        if (string.IsNullOrEmpty(dbItem.DocCode))
                        {
                            context.FactorySaleInvoice_function_GenerateFactorySaleInvoiceUD(dbItem.FactorySaleInvoiceID, dbItem.InvoiceDate.Value.Year, dbItem.InvoiceDate.Value.Month);
                        }

                        //get return data
                        dtoItem = GetData(userId, dbItem.FactorySaleInvoiceID, null, out notification).Data;
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.GetInnerException(ex).Message;
                return(false);
            }
        }