Esempio n. 1
0
        private void SendNotification(string emailSubject, string emailBody, string sendToEmail, List <int?> UserIDs)
        {
            try
            {
                List <string> emailAddress = new List <string>();

                using (QCReportEntities context = CreateContext())
                {
                    //string sendToEmail = "*****@*****.**";

                    //int userID = 142;

                    // add to NotificationMessage table
                    if (UserIDs.Count > 0)
                    {
                        foreach (var userID in UserIDs)
                        {
                            if (userID != null)
                            {
                                NotificationMessage notification = new NotificationMessage();
                                notification.UserID = userID;
                                notification.NotificationMessageTag     = Module.Framework.ConstantIdentifier.MOBILE_APP_MESSAGE_TAG_QAQC;
                                notification.NotificationMessageTitle   = emailSubject;
                                notification.NotificationMessageContent = emailBody;
                                context.NotificationMessage.Add(notification);
                            }
                        }
                    }

                    EmailNotificationMessage dbEmail = new EmailNotificationMessage();
                    dbEmail.EmailBody    = emailBody;
                    dbEmail.EmailSubject = emailSubject;
                    dbEmail.SendTo       = sendToEmail;
                    context.EmailNotificationMessage.Add(dbEmail);
                    context.SaveChanges();
                }
            }
            catch { }
        }
Esempio n. 2
0
        public bool Update(int userId, int id, ref object dto, out Notification notification)
        {
            DTO.QCReportDTO dtoItem = ((Newtonsoft.Json.Linq.JObject)dto).ToObject <DTO.QCReportDTO>();
            notification = new Notification()
            {
                Type = NotificationType.Success
            };
            try
            {
                using (QCReportEntities context = CreateContext())
                {
                    QCReport dbItem = null;
                    if (id > 0)
                    {
                        dbItem = context.QCReport.FirstOrDefault(s => s.QCReportID == id);

                        if (dbItem == null)
                        {
                            notification = new Notification()
                            {
                                Type = NotificationType.Error, Message = "Can not find data"
                            };
                            return(false);
                        }
                    }
                    else
                    {
                        dbItem = new QCReport();
                        context.QCReport.Add(dbItem);
                    }

                    // add QCReportImage
                    foreach (var item in dtoItem.QCReportImageDTOs)
                    {
                        if (item.ScanHasChange)
                        {
                            if (string.IsNullOrEmpty(item.ScanNewFile))
                            {
                                fwFactory.RemoveFile(item.FileUD);
                            }
                            else
                            {
                                item.FileUD = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", item.ScanNewFile, item.FileUD);
                            }
                        }
                    }

                    converter.DTO2DB_QCReport(dtoItem, ref dbItem);
                    // product image
                    if (dtoItem.ScanHasChange)
                    {
                        dbItem.ProductImage = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoItem.ScanNewFile, dtoItem.ProductImage);
                    }

                    if (dtoItem.ReportScanHasChange)
                    {
                        dbItem.ReportFile = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoItem.ReportScanNewFile, dtoItem.ReportFile);
                    }

                    dbItem.UpdatedBy   = userId;
                    dbItem.UpdatedDate = DateTime.Now;
                    context.QCReportSummary.Local.Where(o => o.QCReport == null).ToList().ForEach(s => context.QCReportSummary.Remove(s));
                    context.QCReportDetail.Local.Where(o => o.QCReport == null).ToList().ForEach(s => context.QCReportDetail.Remove(s));
                    context.QCReportDefect.Local.Where(o => o.QCReport == null).ToList().ForEach(s => context.QCReportDefect.Remove(s));
                    context.QCReportImage.Local.Where(o => o.QCReport == null).ToList().ForEach(s => context.QCReportImage.Remove(s));
                    context.QCReportTestEnvironment.Local.Where(o => o.QCReport == null).ToList().ForEach(s => context.QCReportTestEnvironment.Remove(s));
                    context.QCReportFactoryOrderDetail.Local.Where(o => o.QCReport == null).ToList().ForEach(s => context.QCReportFactoryOrderDetail.Remove(s));
                    context.SaveChanges();

                    //Create code of id
                    dbItem.QCReportUD = "QC" + dbItem.QCReportID.ToString("D8");
                    context.SaveChanges();

                    if (id == 0)
                    {
                        string emailSubject = "";
                        string emailBody    = "";
                        string url          = "";
                        url           = this.frontendURL + "QCReportMng/Edit/" + dbItem.QCReportID.ToString();
                        emailSubject += "New QC report - " + "[" + dtoItem.ClientUD + "]" + " / " + "[" + dtoItem.FactoryUD + "]" + " - " + dtoItem.ArticleCode + " - " + dtoItem.Description;
                        emailBody    += "New QC Report:";
                        emailBody    += Environment.NewLine + "Click <a href='" + url + "'>here</a> to link to QC Report:" + url;

                        var QCReportMenber = context.QCReportMng_QCReportGroupMember_View.ToList();
                        var ClientManager  = context.QCReportMng_ClientManager_View.Where(o => o.ClientID == dtoItem.ClientID).FirstOrDefault();

                        List <int?> UserIDs = new List <int?>();
                        UserIDs.Add(ClientManager.AccManagerID);
                        UserIDs.Add(ClientManager.AccManagerAssitantID);
                        UserIDs.Add(ClientManager.VNMerchandiserID);
                        UserIDs.Add(ClientManager.VNMerchandiserAssitantID);

                        string sendToEmail = "";
                        if (QCReportMenber.Count() > 0)
                        {
                            foreach (var item in QCReportMenber)
                            {
                                if (sendToEmail != "")
                                {
                                    sendToEmail += ";" + item.Email;
                                }
                                else
                                {
                                    sendToEmail = item.Email;
                                }

                                UserIDs.Add(item.UserID);
                            }
                        }
                        if (ClientManager.AccManagerEmail != "")
                        {
                            if (sendToEmail != "")
                            {
                                sendToEmail += ";" + ClientManager.AccManagerEmail;
                            }
                            else
                            {
                                sendToEmail = ClientManager.AccManagerEmail;
                            }
                        }
                        if (ClientManager.AccManagerAssitantEmail != "")
                        {
                            if (sendToEmail != "")
                            {
                                sendToEmail += ";" + ClientManager.AccManagerAssitantEmail;
                            }
                            else
                            {
                                sendToEmail = ClientManager.AccManagerAssitantEmail;
                            }
                        }
                        if (ClientManager.VNMerchandiserEmail != "")
                        {
                            if (sendToEmail != "")
                            {
                                sendToEmail += ";" + ClientManager.VNMerchandiserEmail;
                            }
                            else
                            {
                                sendToEmail = ClientManager.VNMerchandiserEmail;
                            }
                        }
                        if (ClientManager.VNMerchandiserAssitantEmail != "")
                        {
                            if (sendToEmail != "")
                            {
                                sendToEmail += ";" + ClientManager.VNMerchandiserAssitantEmail;
                            }
                            else
                            {
                                sendToEmail = ClientManager.VNMerchandiserAssitantEmail;
                            }
                        }

                        SendNotification(emailSubject, emailBody, sendToEmail, UserIDs);
                    }


                    dto = GetData(dbItem.QCReportID, dbItem.SaleOrderDetailID, dbItem.FactoryID, null, null, null, out notification).Data;
                }
                return(true);
            }
            catch (Exception ex)
            {
                notification = new Notification()
                {
                    Type = NotificationType.Error, Message = ex.Message
                };
                return(false);
            }
        }
Esempio n. 3
0
        public DTO.SearchForm GetDataWithFilter(int userId, Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification)
        {
            DTO.SearchForm searchForm = new DTO.SearchForm();
            searchForm.Factories = new List <Support.DTO.Factory>();
            notification         = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            totalRows = 0;
            try
            {
                string qcReportUD        = null;
                int?   factoryID         = null;
                string clientUD          = null;
                string articleCode       = null;
                string proformaInvoiceNo = null;
                string updatedDate       = null;

                if (filters.ContainsKey("QCReportUD") && !string.IsNullOrEmpty(filters["QCReportUD"].ToString()))
                {
                    qcReportUD = filters["QCReportUD"].ToString().Replace("'", "''");
                }

                if (filters.ContainsKey("FactoryID") && filters["FactoryID"] != null && !string.IsNullOrEmpty(filters["FactoryID"].ToString()))
                {
                    factoryID = Convert.ToInt32(filters["FactoryID"]);
                }

                if (filters.ContainsKey("ArticleCode") && !string.IsNullOrEmpty(filters["ArticleCode"].ToString()))
                {
                    articleCode = filters["ArticleCode"].ToString().Replace("'", "''");
                }
                if (filters.ContainsKey("ProformaInvoiceNo") && !string.IsNullOrEmpty(filters["ProformaInvoiceNo"].ToString()))
                {
                    proformaInvoiceNo = filters["ProformaInvoiceNo"].ToString().Replace("'", "''");
                }
                if (filters.ContainsKey("UpdatedDate") && !string.IsNullOrEmpty(filters["UpdatedDate"].ToString()))
                {
                    updatedDate = filters["UpdatedDate"].ToString().Replace("'", "''");
                }
                if (filters.ContainsKey("ClientUD") && !string.IsNullOrEmpty(filters["ClientUD"].ToString()))
                {
                    clientUD = filters["ClientUD"].ToString().Replace("'", "''");
                }

                //if (filters.ContainsKey("TestDate") && !string.IsNullOrEmpty(filters["TestDate"].ToString()))
                //{
                //    testDate = filters["TestDate"].ToString().Replace("'", "''");
                //}
                DateTime?valTestDate = updatedDate.ConvertStringToDateTime();

                using (QCReportEntities context = CreateContext())
                {
                    totalRows = context.QCReportMng_function_SearchQCReportMng(qcReportUD, factoryID, clientUD, articleCode, proformaInvoiceNo, valTestDate, orderBy, orderDirection).Count();
                    var result = context.QCReportMng_function_SearchQCReportMng(qcReportUD, factoryID, clientUD, articleCode, proformaInvoiceNo, valTestDate, orderBy, orderDirection);
                    searchForm.Data = converter.DB2DTO_SearchQCReport(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                }
                searchForm.Factories = supportFactory.GetFactory().ToList();
                return(searchForm);
            }
            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(searchForm);
            }
        }