Ejemplo n.º 1
0
        public bool SaveProcessedDate(int userID, int employeeID)
        {
            QueryOutput queryResult;
            var         query = String.Format("update Warranty set ProcessedDate = {0} where ID = {1}", ProcessedDate.DbValue(), ID);

            Execute(new DbQuery(userID, employeeID, DbAction.Warranty.Modify, query, true, ID), out queryResult);
            return(queryResult == QueryOutput.Success);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Emails the situation to everyone in the list.
        /// </summary>
        private async void EmailSituation()
        {
            // Clean the messages.
            InformationMessage = string.Empty;

            // Generate the email content based on the template
            var emailTemplate        = new EmailTemplate(ProcessedDate, Lines);
            var emailTemplateContent = emailTemplate.TransformText();

            // Send the mail via Outlook
            // Check that the email button is disable just after clicking it.
            IsSendingEmail = true;
            try
            {
                await Task.Run(() =>
                {
                    OutlookApp outlookApp = new OutlookApp();
                    MailItem mailItem     = outlookApp.CreateItem(OlItemType.olMailItem);

                    foreach (var line in Lines)
                    {
                        mailItem.Recipients.Add(line.Person.Email);
                    }
                    mailItem.Recipients.ResolveAll();

                    mailItem.Subject = String.Format("Soumission des CRA : rapport du {0}", ProcessedDate.ToString("d"));

                    // Images are attached to the mail with a contentId; that way, they will be accessible in the mail
                    // via the attribute "cid".
                    // For instance: <img src="cid:croissantEmpty" />
                    // In Outlook, this attribute is the property that has the schema name
                    // http://schemas.microsoft.com/mapi/proptag/0x3712001E.
                    var appPath = AppDomain.CurrentDomain.BaseDirectory;

                    Attachment croissantEmptyAttachment = mailItem.Attachments.Add(Path.Combine(appPath, "Assets/croissant_empty.png"));
                    croissantEmptyAttachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", "croissantEmpty");

                    Attachment croissantFilledAttachment = mailItem.Attachments.Add(Path.Combine(appPath, "Assets/croissant_filled.png"));
                    croissantFilledAttachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", "croissantFilled");

                    Attachment croissantGreyedAttachment = mailItem.Attachments.Add(Path.Combine(appPath, "Assets/croissant_greyed.png"));
                    croissantGreyedAttachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", "croissantGreyed");

                    mailItem.HTMLBody = emailTemplateContent;

                    mailItem.Display(false);
                });
            }
            catch (System.Exception)
            {
                InformationMessage = "Erreur lors de la préparation du message";
            }

            IsSendingEmail = false;

            Save();
        }
Ejemplo n.º 3
0
        public Warranty Save(ModelStateDictionary modelState, int userID, int employeeID, int bussinessID, string employeeName = null)
        {
            QueryOutput queryResult;

            if (!Validate(modelState))
            {
                Result = false;
                return(null);
            }
            var query  = "";
            var action = "";
            var id     = ID.ToString();

            if (ID > 0)
            {
                query = String.Format(
                    @"update Warranty 
                    set TransferDate = {1}, ReceivedDate = {2}, ProcessedDate = {3}, ReturnedDate = {4}, FinishDate = {5}, Service = N'{13}', 
                        ProductState = N'{6}', Fee = {7}, Discount = {8}, Other = N'{9}', Note = N'{10}', ContactName = N'{11}', ContactPhone = N'{12}'
                    where ID = {0}",
                    new object[] {
                    ID, TransferDate.DbValue(), ReceivedDate.DbValue(), ProcessedDate.DbValue(), ReturnedDate.DbValue(),
                    FinishDate.DbValue(), ProductState, Fee, Discount, Other, Note, ContactName, ContactPhone, Service
                });
                action = DbAction.Warranty.Modify;
            }
            else
            {
                Code         = NewUniqueCode(userID, employeeID, bussinessID, "Warranty");
                EmployeeID   = employeeID;
                BussinessID  = bussinessID;
                EmployeeName = employeeName;
                SubmitDate   = DateTime.Now;
                var clientID = "@ClientID";
                query = String.Format("declare {0} int = {1}", clientID, ClientID.DbValue());
                if ((!ClientID.HasValue || ClientID <= 0) && !String.IsNullOrEmpty(ClientName))
                {
                    query += String.Format(
                        @" declare @client table (ID int)
                        insert Client(BussinessID, Code, Name, Phone, Address, Point, Status)
                        output inserted.ID into @client
                        values ({0}, '{1}', N'{2}', '{3}', N'{4}', 0, 'active')
                        set {5} = (select top 1 ID from @client)",
                        bussinessID, String.IsNullOrEmpty(ClientCode) ? NewUniqueCode(userID, employeeID, bussinessID, "Client", 3, null) : ClientCode, ClientName, ClientPhone, ClientAddress, clientID);
                }
                query += String.Format(
                    @" declare @output table (ID int)
                    insert Warranty(BussinessID, EmployeeID, WarehouseID, ProductID, Code, SubmitDate, TransferDate, ReceivedDate, ProcessedDate, ReturnedDate, FinishDate, 
                        ProductState, Fee, Discount, Other, Note, Status, ClientID, OrderID, OrderCode, ContactName, ContactPhone, ReceiveWarehouseID, Service) 
                    output inserted.ID into @output
                    values ({0}, {1}, {2}, {3}, N'{4}', {5}, {6}, {7}, {8}, {9}, {10}, N'{11}', {12}, {13}, N'{14}', N'{15}', 'active', {16}, {17}, '{18}', N'{19}', N'{20}', {21}, N'{22}')",
                    new object[] {
                    BussinessID, EmployeeID, WarehouseID, ProductID, Code, SubmitDate.DbValue(), TransferDate.DbValue(), ReceivedDate.DbValue(),
                    ProcessedDate.DbValue(), ReturnedDate.DbValue(), FinishDate.DbValue(), ProductState, Fee, Discount, Other, Note,
                    clientID, OrderID.DbValue(), OrderCode, ContactName, ContactPhone, ReceiveWarehouseID, Service
                });
                id = "(select top 1 ID from @output)";
                if (Transactions != null)
                {
                    foreach (var tran in Transactions)
                    {
                        query += tran.AddTransactionQuery(employeeID, TransactionClass.Warranty, ref id);
                    }
                }
                action = DbAction.Warranty.Create;
            }
            query += String.Format(
                @" select top 1 w.ID, w.BussinessID, w.EmployeeID, w.WarehouseID, w.ProductID, w.ClientID, w.OrderID, w.Code, w.Service, 
	                w.SubmitDate, w.TransferDate, w.ReceivedDate, w.ProcessedDate, w.ReturnedDate, w.FinishDate, w.ProductState, w.Fee, w.Discount, w.Other, w.Note, 
                    rwh.Name as [ReceiveWarehouseName], wh.Name as [WarehouseName], w.ContactName, w.ContactPhone, e.Name as [EmployeeName], 
                    c.Name as [ClientName], c.Code as [ClientCode], c.Address as [ClientAddress], c.Phone as [ClientPhone], 
	                case when w.OrderID is not null then o.Code else w.OrderCode end as [OrderCode], isnull(sum(t.Amount), 0) as [Paid]
                from Warranty w 
                    join Warehouse wh on w.WarehouseID = wh.ID and w.Status = 'active' and ((select Username from Login where ID = {1}) = 'admin' or wh.ID in (select WarehouseID from LoginWarehouse where LoginID = {1}))
                    join Warehouse rwh on w.ReceiveWarehouseID = rwh.ID
                    join Employee e on w.EmployeeID = e.ID
                    join Product p on p.ID = w.ProductID
                    left join Client c on w.ClientID = c.ID
                    left join [Order] o on w.OrderID = o.ID
                    left join Transactions t on w.ID = t.WarrantyID
                where w.ID = {0} and w.Status = 'active'
                group by w.ID, w.BussinessID, w.EmployeeID, w.WarehouseID, w.ProductID, w.ClientID, w.OrderID, w.Code, w.ContactName, w.ContactPhone, 
                    w.SubmitDate, w.TransferDate, w.ReceivedDate, w.ProcessedDate, w.ReturnedDate, w.FinishDate, w.ProductState, w.Service, 
	                w.Fee, w.Discount, w.Other, w.Note, wh.Name, rwh.Name, e.Name, c.Name, c.Code, c.Address, c.Phone, o.Code, w.OrderCode"    , id, userID);
            var record = Query <Warranty>(new DbQuery(userID, employeeID, action, query, true, id), out queryResult).FirstOrDefault();

            if (Result = (queryResult == QueryOutput.Success))
            {
                Messages = new List <string>()
                {
                    "Lưu thông tin thành công"
                }
            }
            ;
            return(record);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Event handling for the event PenaltyAlreadyExistsAtThisDate.
 /// </summary>
 /// <param name="sender">Event sender.</param>
 /// <param name="e">Event arguments.</param>
 private void HandlePenaltyAlreadyExistsAtThisDate(object sender, EventArgs e)
 {
     InformationMessage = String.Format("{0} a déjà une pénalité en date du {1}.", (sender as Line).Person.FirstName, ProcessedDate.ToString("d", CultureInfo.CurrentCulture));
 }