示例#1
0
        /// <summary>
        /// Xử lý sự kiện nhấn vào bàn
        /// </summary>
        /// <param name="sender"></param>
        private void HandlerTableMapping(object sender)
        {
            UctTableMapping uctTableMapping = (UctTableMapping)sender;

            if (uctTableMapping.TableStatus == EnumTableStatus.Booking)
            {
                ShowBooking(uctTableMapping);
            }
            else if (uctTableMapping.TableStatus == EnumTableStatus.Using)
            {
                ShowOrder(uctTableMapping);
            }
            else
            {
                MessageBoxCommon.ShowMessage("Bàn chưa được sử dụng");
            }
        }
        private void BtnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (oBLSAInvoice.InsertUpdate(dsDictionary, 0))
                {
                    var updateOrder = oBLOrder.ChangeOrderStatus(SAInvoiceRow.OrderID, (int)EnumOrderStatus.Done);
                    if (updateOrder)
                    {
                        MessageBoxCommon.ShowMessage("Lập hóa đơn thành công");
                        DialogResult = DialogResult.OK;
                    }
                }
                try
                {
                    string   token                  = null;
                    IInvoice invoiceObject          = null;
                    var      authen                 = MeInvoiceFactory.CreatUserClass();
                    GetTokenOperationResult oResult = authen.GetToken("8C3B3E41F3D34F639CEAF489FD62AD33", "0101243150-999", "*****@*****.**", "12345678a");
                    if (oResult.Success && !string.IsNullOrWhiteSpace(oResult.Token))
                    {
                        token = oResult.Token;
                    }
                    OriginalInvoiceData        invoiceData = BuildOriginalInvoiceData(dsDictionary);
                    List <OriginalInvoiceData> lstData     = new List <OriginalInvoiceData>();
                    lstData.Add(invoiceData);
                    //Tạo dữ liệu hóa đơn định dạng XML
                    invoiceObject = MeInvoiceFactory.CreatInvoiceClass(token);
                    CreateInvoiceOperationResult result = invoiceObject.CreateEInvoice(lstData);
                    if (result.Success && result.EInvoiceResultDataList != null && result.EInvoiceResultDataList.Count > 0)
                    {
                        XmlDocument invoiceXML = new XmlDocument();
                        invoiceXML.LoadXml(result.EInvoiceResultDataList[0].InvoiceData);
                        MISA.MeInvoice.DataContract.SDKResult.SignedXmlResult CertFile = SignerUtils.SignByFile(invoiceXML.InnerXml, @"D:\MST0101243150-999-V2.p12", "12345678");
                        List <PublishInvoiceData> signedInvoice = new List <PublishInvoiceData>();
                        PublishInvoiceData        pubInvData    = new PublishInvoiceData();
                        pubInvData.RefID         = invoiceData.RefID;
                        pubInvData.TransactionID = result.EInvoiceResultDataList[0].TransactionID;
                        pubInvData.InvoiceData   = CertFile.SignedXmlContent;
                        signedInvoice.Add(pubInvData);
                        PublishInvoiceOperationResult oPubResult = invoiceObject.PublishInvoice(signedInvoice);
                        if (oPubResult.Success)
                        {
                            List <PublishInvoiceResult> pubResult = oPubResult.PublishInvoiceResultList;
                            if (pubResult != null && pubResult.Count > 0)
                            {
                                BLSAInvoice bLSAInvoice = new BLSAInvoice();

                                bLSAInvoice.UpdateInvoiceNumber(Guid.Parse(dsDictionary.SAInvoice.Rows[0]["RefID"].ToString()), pubResult[0].InvoiceNumber, pubInvData.TransactionID);
                                btnPrint.Visible = true;
                                WebClient client = new WebClient();
                                string    reply  = client.DownloadString("https://meinvoice.vn/tra-cuu/GetRequestTimeEnCode");
                                var       link   = String.Format("http://meinvoice.vn/tra-cuu/downloadhandler.ashx?type=pdf&code={0}&viewer=1&ext={1}", pubInvData.TransactionID, reply.ToString().Substring(55, 8));
                                Process.Start(link);
                            }
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
            catch (Exception ex)
            {
                MessageBoxCommon.ShowException(ex);
            }
        }