예제 #1
0
        private bool UpdateInvoice(Entities.Invoice invoice)
        {
            int clientID = 0;

            Facade.IInvoice         facInvoice         = new Facade.Invoice();
            Facade.IInvoiceOneLiner facInvoiceOneLiner = new Facade.Invoice();
            bool    retVal = false;
            DataSet dsClientID;

            string userName = ((Entities.CustomPrincipal)Page.User).UserName;

            //GetClientForOneLinerInvoiceId should work for most invoice types, where as GetClientInvoiceId only works for groupage invoices
            if (invoice.InvoiceType == eInvoiceType.Normal)
            {
                dsClientID = facInvoice.GetClientForInvoiceId(invoice.InvoiceId);
            }
            else
            {
                dsClientID = facInvoiceOneLiner.GetClientForOneLinerInvoiceId(invoice.InvoiceId);
            }


            int.TryParse(dsClientID.Tables[0].Rows[0]["ClientId"].ToString(), out clientID);

            retVal = facInvoice.Update(invoice, clientID, userName);

            return(retVal);
        }
        protected bool GenerateBatch()
        {
            bool success = true;

            NameValueCollection clients = new NameValueCollection();
            NameValueCollection batchNo = new NameValueCollection();

            foreach (DataListItem item in dlJob.Items)
            {
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    string batchId    = ((TextBox)item.FindControl("txtBatchNo")).Text;
                    string jobId      = ((LinkButton)item.FindControl("lnkJobId")).Text;
                    string identityId = ((HtmlInputHidden)item.FindControl("hidIdentityId")).Value;

                    if (batchId != String.Empty)
                    {
                        HtmlImage imgError   = (HtmlImage)item.FindControl("imgError");
                        TextBox   txtBatchNo = (TextBox)item.FindControl("txtBatchNo");

                        // Check whether this is a new batch and if
                        // so make sure the job added is from the same client
                        if (m_batches.Get(batchId) == null)
                        {
                            m_batches.Add(batchId, jobId);
                            clients.Add(batchId, identityId);
                            batchNo.Add(batchId, batchId);
                            imgError.Visible     = false;
                            txtBatchNo.BackColor = Color.White;
                            txtBatchNo.ToolTip   = string.Empty;
                        }
                        else
                        {
                            if (identityId == clients.Get(batchId))
                            {
                                m_batches.Set(batchId, m_batches.Get(batchId) + "," + jobId);
                                imgError.Visible     = false;
                                txtBatchNo.BackColor = Color.White;
                                txtBatchNo.ToolTip   = string.Empty;
                            }
                            else
                            {
                                txtBatchNo.BackColor = Color.Red;
                                txtBatchNo.ToolTip   = imgError.Alt;
                                imgError.Visible     = true;
                                success = false;
                            }
                        }
                    }
                }
            }

            if (!success)
            {
                return(success);
            }

            // Record batches that have been successful
            Facade.IInvoiceBatches facInv = new Facade.Invoice();
            bool   marker = false;
            string userId = ((Entities.CustomPrincipal)Page.User).UserName;

            for (int i = 0; i < m_batches.Count; i++)
            {
                int    batchId = Convert.ToInt32(batchNo[i].ToString());
                string jobIds  = m_batches[i].ToString();

                // Check whether these are OLD or NEW invoice batches either create or update
                bool exists = facInv.CheckBatchExists(batchId);

                if (exists)
                {
                    facInv.Update(batchId, jobIds, userId); // UPDATE If it has a Batch Id
                    marker = true;
                }
                else
                {
                    Entities.FacadeResult result = facInv.Create(batchId, jobIds, userId); // CREATE If it hasn't an Id

                    if (result.Success)
                    {
                        marker = true;
                    }
                    else
                    {
                        infringementDisplay.Infringements = result.Infringements;
                        infringementDisplay.DisplayInfringments();

                        marker = false;
                    }
                }
            }

            return(marker);
        }