Пример #1
0
        /// <summary>
        /// Handles the Click event of the btnLatest control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void btnLatest_Click(object sender, EventArgs e)
        {
            DateTime currentTime = DateTime.Now;

            rsDate = string.Format("{0:MM/dd/yyyy}", currentTime);
            rsTime = string.Format("{0:T}", currentTime);

            SqlCommand cmd_StoreCreditID = new SqlCommand("Get_Latest_StoreCreditID", parentForm.conn);

            cmd_StoreCreditID.CommandType = CommandType.StoredProcedure;
            cmd_StoreCreditID.Parameters.Add("@RegisterNum", SqlDbType.NVarChar).Value = parentForm.cashRegisterNum;
            SqlParameter Latest_Param = cmd_StoreCreditID.Parameters.Add("@StoreCreditID", SqlDbType.BigInt);

            Latest_Param.Direction = ParameterDirection.Output;

            parentForm.conn.Open();
            cmd_StoreCreditID.ExecuteNonQuery();
            parentForm.conn.Close();

            if (cmd_StoreCreditID.Parameters["@StoreCreditID"].Value == DBNull.Value)
            {
                MyMessageBox.ShowBox("NO DATA", "ERROR");
                txtStoreCreditID.Select();
                txtStoreCreditID.Focus();
            }
            else
            {
                rrStoreCreditID = Convert.ToInt64(cmd_StoreCreditID.Parameters["@StoreCreditID"].Value);

                SqlCommand cmd_StoreCreditInfo = new SqlCommand("Get_StoreCredit_Info2", parentForm.conn);
                cmd_StoreCreditInfo.CommandType = CommandType.StoredProcedure;
                cmd_StoreCreditInfo.Parameters.Add("@StoreCreditID", SqlDbType.BigInt).Value = rrStoreCreditID;
                SqlParameter Amount_Param    = cmd_StoreCreditInfo.Parameters.Add("@Amount", SqlDbType.Money);
                SqlParameter Balance_Param   = cmd_StoreCreditInfo.Parameters.Add("@Balance", SqlDbType.Money);
                SqlParameter StartDate_Param = cmd_StoreCreditInfo.Parameters.Add("@StartDate", SqlDbType.NVarChar, 20);
                SqlParameter ExpDate_Param   = cmd_StoreCreditInfo.Parameters.Add("@ExpDate", SqlDbType.NVarChar, 20);
                Amount_Param.Direction    = ParameterDirection.Output;
                Balance_Param.Direction   = ParameterDirection.Output;
                StartDate_Param.Direction = ParameterDirection.Output;
                ExpDate_Param.Direction   = ParameterDirection.Output;

                parentForm.conn.Open();
                cmd_StoreCreditInfo.ExecuteNonQuery();
                parentForm.conn.Close();

                rrAmount    = Convert.ToDouble(cmd_StoreCreditInfo.Parameters["@Amount"].Value);
                rrBalance   = Convert.ToDouble(cmd_StoreCreditInfo.Parameters["@Balance"].Value);
                rrStartDate = cmd_StoreCreditInfo.Parameters["@StartDate"].Value.ToString();
                rrExpDate   = cmd_StoreCreditInfo.Parameters["@ExpDate"].Value.ToString();

                Int32  retVal;
                String errMsg;
                apiAlias.StatusMonitoring pMonitorCB = new apiAlias.StatusMonitoring(StatusMonitoring);

                pdPrint            = new PrintDocument();
                pdPrint.PrintPage += new PrintPageEventHandler(pdPrint_PrintPage);
                pdPrint.PrinterSettings.PrinterName = parentForm.PRINTER_NAME;

                try
                {
                    // Open Printer Monitor of Status API.
                    mpHandle = apiAlias.BiOpenMonPrinter(apiAlias.TYPE_PRINTER, parentForm.PRINTER_NAME);
                    if (mpHandle < 0)
                    {
                        MessageBox.Show("Failed to open printer status monitor.", "Printing error", MessageBoxButtons.OK);
                    }
                    else
                    {
                        isFinish  = false;
                        cancelErr = false;

                        // Set the callback function that will monitor printer status.
                        retVal = apiAlias.BiSetStatusBackFunction(mpHandle, pMonitorCB);

                        if (retVal != apiAlias.SUCCESS)
                        {
                            MessageBox.Show("Failed to set callback function.", "Printing error", MessageBoxButtons.OK);
                        }
                        else
                        {
                            // Wait until callback function will say that the task is done.
                            // When done, end the monitoring of printer status.
                            //do
                            //{
                            //    if (isFinish)
                            //        retVal = apiAlias.BiCancelStatusBack(mpHandle);
                            //} while (!isFinish);

                            // Display the status/error message.
                            //DisplayStatusMessage();

                            // If an error occurred, restore the recoverable error.
                            if (cancelErr)
                            {
                                retVal = apiAlias.BiCancelError(mpHandle);
                            }
                            else
                            {
                                pdPrint.Print();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    errMsg = ex.Message;
                    MessageBox.Show("Failed to open StatusAPI. Printing error.", errMsg, MessageBoxButtons.OK);
                }
                finally
                {
                    // Close Printer Monitor.
                    if (mpHandle > 0)
                    {
                        if (apiAlias.BiCloseMonPrinter(mpHandle) != apiAlias.SUCCESS)
                        {
                            MessageBox.Show("Failed to close printer status monitor.", "Printing error", MessageBoxButtons.OK);
                        }
                    }
                }

                txtStoreCreditID.Select();
                txtStoreCreditID.Focus();
            }
        }
Пример #2
0
        /// <summary>
        /// Handles the Load event of the CashWithdraw control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void CashWithdraw_Load(object sender, EventArgs e)
        {
            SqlDataReader dReader;
            SqlCommand    cmd = new SqlCommand("Get_User_Level", parentForm.conn);

            cmd.CommandType = CommandType.StoredProcedure;

            parentForm.conn.Open();
            dReader = cmd.ExecuteReader();
            if (dReader.HasRows == true)
            {
                while (dReader.Read())
                {
                    namesCollection.Add(dReader["empLoginID"].ToString());
                }
            }
            else
            {
                MyMessageBox.ShowBox("USER DATA NOT FOUND", "ERROR");
                //MessageBox.Show("Data not found");
            }

            dReader.Close();
            parentForm.conn.Close();

            txtManagerID.AutoCompleteMode         = AutoCompleteMode.SuggestAppend;
            txtManagerID.AutoCompleteSource       = AutoCompleteSource.CustomSource;
            txtManagerID.AutoCompleteCustomSource = namesCollection;

            Int32  retVal;
            String errMsg;

            apiAlias.StatusMonitoring pMonitorCB = new apiAlias.StatusMonitoring(StatusMonitoring);

            pdPrint = new PrintDocument();
            //pdPrint.PrintPage += new PrintPageEventHandler(pdPrint_PrintPage);
            pdPrint.PrinterSettings.PrinterName = parentForm.PRINTER_NAME;

            try
            {
                // Open Printer Monitor of Status API.
                mpHandle = apiAlias.BiOpenMonPrinter(apiAlias.TYPE_PRINTER, pdPrint.PrinterSettings.PrinterName);
                if (mpHandle < 0)
                {
                    MessageBox.Show("Failed to open printer status monitor.", "Printing error", MessageBoxButtons.OK);
                }
                else
                {
                    //isFinish = false;
                    cancelErr = false;

                    // Set the callback function that will monitor printer status.
                    retVal = apiAlias.BiSetStatusBackFunction(mpHandle, pMonitorCB);

                    if (retVal != apiAlias.SUCCESS)
                    {
                        MessageBox.Show("Failed to set callback function.", "Printing error", MessageBoxButtons.OK);
                    }
                    else
                    {
                        // Start printing.
                        //pdPrint.Print();

                        // Wait until callback function will say that the task is done.
                        // When done, end the monitoring of printer status.
                        //do
                        //{
                        //    if (isFinish)
                        //        retVal = apiAlias.BiCancelStatusBack(mpHandle);
                        //} while (!isFinish);

                        // Display the status/error message.
                        DisplayStatusMessage();

                        // If an error occurred, restore the recoverable error.
                        if (cancelErr)
                        {
                            retVal = apiAlias.BiCancelError(mpHandle);
                        }
                        else
                        {
                            // Call the function to open cash drawer.
                            OpenDrawer(pdPrint.PrinterSettings.PrinterName);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                MessageBox.Show("Failed to open StatusAPI.", "Printing error", MessageBoxButtons.OK);
            }
            finally
            {
                // Close Printer Monitor.
                if (mpHandle > 0)
                {
                    if (apiAlias.BiCloseMonPrinter(mpHandle) != apiAlias.SUCCESS)
                    {
                        MessageBox.Show("Failed to close printer status monitor.", "Printing error", MessageBoxButtons.OK);
                    }
                }
            }

            txtAmount.SelectAll();
            txtAmount.Focus();
        }
Пример #3
0
        /// <summary>
        /// Handles the Click event of the txtWithdraw control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void txtWithdraw_Click(object sender, EventArgs e)
        {
            if (txtManagerID.Text == "")
            {
                MyMessageBox.ShowBox("INPUT MANAGER ID", "ERROR");
                //MessageBox.Show("Input Manager ID", "Error");
                return;
            }

            if (txtPsw.Text == "")
            {
                MyMessageBox.ShowBox("INPUT PASSWORD", "ERROR");
                //MessageBox.Show("Input password", "Error");
                return;
            }

            managerID       = txtManagerID.Text.Trim().ToString().ToUpper();
            managerPassword = txtPsw.Text.Trim().ToString().ToUpper();
            SqlCommand cmd1 = new SqlCommand("Get_ManagerID", parentForm.conn);

            cmd1.CommandType = CommandType.StoredProcedure;
            cmd1.Parameters.Add("@LoginID", SqlDbType.NVarChar).Value  = managerID.ToUpper().ToString();
            cmd1.Parameters.Add("@Password", SqlDbType.NVarChar).Value = managerPassword;
            SqlParameter UserName_Param = cmd1.Parameters.Add("@FirstName", SqlDbType.NVarChar, 50);

            UserName_Param.Direction = ParameterDirection.Output;

            parentForm.conn.Open();
            cmd1.ExecuteNonQuery();
            parentForm.conn.Close();

            if (cmd1.Parameters["@FirstName"].Value == DBNull.Value)
            {
                MyMessageBox.ShowBox("AUTHENTICATION FAILED", "ERROR");
                return;
            }


            DateTime currentTime = DateTime.Now;

            string withDrawDate = string.Format("{0:MM/dd/yyyy}", currentTime);
            string withDrawTime = string.Format("{0:T}", currentTime);

            if (double.TryParse(txtAmount.Text, out amount))
            {
                SqlCommand cmd = new SqlCommand("Create_CashWithdraw", parentForm.conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@RegisterNum", SqlDbType.NVarChar).Value       = parentForm.cashRegisterNum;
                cmd.Parameters.Add("@TransactionStatus", SqlDbType.NVarChar).Value = "WITHDRAW";
                cmd.Parameters.Add("@RegWithdrawAmount", SqlDbType.Money).Value    = amount;
                cmd.Parameters.Add("@RegDate", SqlDbType.NVarChar).Value           = withDrawDate;
                cmd.Parameters.Add("@RegTime", SqlDbType.NVarChar).Value           = withDrawTime;
                cmd.Parameters.Add("@RegCashierID", SqlDbType.NVarChar).Value      = cashierID;
                cmd.Parameters.Add("@RegManagerID", SqlDbType.NVarChar).Value      = txtManagerID.Text.Trim().ToString().ToUpper();

                parentForm.conn.Open();
                cmd.ExecuteNonQuery();
                parentForm.conn.Close();

                SqlCommand cmd_TransactionID = new SqlCommand("Get_TransactionID", parentForm.conn);
                cmd_TransactionID.CommandType = CommandType.StoredProcedure;
                cmd_TransactionID.Parameters.Add("@RegisterNum", SqlDbType.NVarChar).Value       = parentForm.cashRegisterNum;
                cmd_TransactionID.Parameters.Add("@RegDate", SqlDbType.NVarChar).Value           = withDrawDate;
                cmd_TransactionID.Parameters.Add("@TransactionStatus", SqlDbType.NVarChar).Value = "WITHDRAW";
                SqlParameter TransactionID_Param = cmd_TransactionID.Parameters.Add("@TransactionID", SqlDbType.BigInt);
                TransactionID_Param.Direction = ParameterDirection.Output;
                parentForm.conn.Open();
                cmd_TransactionID.ExecuteNonQuery();
                parentForm.conn.Close();

                transactionID = Convert.ToInt64(cmd_TransactionID.Parameters["@TransactionID"].Value);

                Int32  retVal;
                String errMsg;
                apiAlias.StatusMonitoring pMonitorCB = new apiAlias.StatusMonitoring(StatusMonitoring);

                pdPrint            = new PrintDocument();
                pdPrint.PrintPage += new PrintPageEventHandler(pdPrint_PrintPage);
                pdPrint.PrinterSettings.PrinterName = parentForm.PRINTER_NAME;

                try
                {
                    // Open Printer Monitor of Status API.
                    mpHandle = apiAlias.BiOpenMonPrinter(apiAlias.TYPE_PRINTER, pdPrint.PrinterSettings.PrinterName);
                    if (mpHandle < 0)
                    {
                        MessageBox.Show("Failed to open printer status monitor.", "Printing error", MessageBoxButtons.OK);
                    }
                    else
                    {
                        isFinish  = false;
                        cancelErr = false;

                        // Set the callback function that will monitor printer status.
                        retVal = apiAlias.BiSetStatusBackFunction(mpHandle, pMonitorCB);

                        if (retVal != apiAlias.SUCCESS)
                        {
                            MessageBox.Show("Failed to set callback function.", "Printing error", MessageBoxButtons.OK);
                        }
                        else
                        {
                            // Start printing.
                            //pdPrint.Print();

                            // Wait until callback function will say that the task is done.
                            // When done, end the monitoring of printer status.
                            //do
                            //{
                            //    if (isFinish)
                            //        retVal = apiAlias.BiCancelStatusBack(mpHandle);
                            //} while (!isFinish);

                            // Display the status/error message.
                            //DisplayStatusMessage();

                            // If an error occurred, restore the recoverable error.
                            if (cancelErr)
                            {
                                retVal = apiAlias.BiCancelError(mpHandle);
                            }
                            else
                            {
                                pdPrint.Print();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    errMsg = ex.Message;
                    MessageBox.Show("Failed to open StatusAPI.", "Printing error", MessageBoxButtons.OK);
                }
                finally
                {
                    // Close Printer Monitor.
                    if (mpHandle > 0)
                    {
                        if (apiAlias.BiCloseMonPrinter(mpHandle) != apiAlias.SUCCESS)
                        {
                            MessageBox.Show("Failed to close printer status monitor.", "Printing error", MessageBoxButtons.OK);
                        }
                    }
                }

                MyMessageBox.ShowBox("SUCCESSFULLY WITHDRAWN", "INFORMATION");
                //MessageBox.Show("Successfully withdrawn", "Info");
                this.Close();
            }
            else
            {
                MyMessageBox.ShowBox("INVALID AMOUNT", "ERROR");
                //MessageBox.Show("Invalid amount", "Error");
                return;
            }
        }
Пример #4
0
        /// <summary>
        /// Handles the Click event of the btnOpenCashDrawer control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        public void btnOpenCashDrawer_Click(object sender, EventArgs e)
        {
            if (auth == true)
            {
                Int32  retVal;
                String errMsg;
                apiAlias.StatusMonitoring pMonitorCB = new apiAlias.StatusMonitoring(StatusMonitoring);

                pdPrint = new PrintDocument();
                //pdPrint.PrintPage += new PrintPageEventHandler(pdPrint_PrintPage);
                pdPrint.PrinterSettings.PrinterName = parentForm.PRINTER_NAME;

                try
                {
                    // Open Printer Monitor of Status API.
                    mpHandle = apiAlias.BiOpenMonPrinter(apiAlias.TYPE_PRINTER, pdPrint.PrinterSettings.PrinterName);
                    if (mpHandle < 0)
                    {
                        MessageBox.Show("Failed to open printer status monitor.", "Printing error", MessageBoxButtons.OK);
                    }
                    else
                    {
                        //isFinish = false;
                        cancelErr = false;

                        // Set the callback function that will monitor printer status.
                        retVal = apiAlias.BiSetStatusBackFunction(mpHandle, pMonitorCB);

                        if (retVal != apiAlias.SUCCESS)
                        {
                            MessageBox.Show("Failed to set callback function.", "Printing error", MessageBoxButtons.OK);
                        }
                        else
                        {
                            // Start printing.
                            //pdPrint.Print();

                            // Wait until callback function will say that the task is done.
                            // When done, end the monitoring of printer status.
                            //do
                            //{
                            //    if (isFinish)
                            //        retVal = apiAlias.BiCancelStatusBack(mpHandle);
                            //} while (!isFinish);

                            // Display the status/error message.
                            DisplayStatusMessage();

                            // If an error occurred, restore the recoverable error.
                            if (cancelErr)
                            {
                                retVal = apiAlias.BiCancelError(mpHandle);
                            }
                            else
                            {
                                // Call the function to open cash drawer.
                                OpenDrawer(pdPrint.PrinterSettings.PrinterName);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    errMsg = ex.Message;
                    MessageBox.Show("Failed to open StatusAPI.", "Printing error", MessageBoxButtons.OK);
                }
                finally
                {
                    // Close Printer Monitor.
                    if (mpHandle > 0)
                    {
                        if (apiAlias.BiCloseMonPrinter(mpHandle) != apiAlias.SUCCESS)
                        {
                            MessageBox.Show("Failed to close printer status monitor.", "Printing error", MessageBoxButtons.OK);
                        }
                    }
                }
            }
            else
            {
                Authentication authenticationForm = new Authentication(11);
                authenticationForm.parentForm1 = this.parentForm;
                authenticationForm.parentForm2 = this;
                authenticationForm.ShowDialog();
            }
        }
Пример #5
0
        /// <summary>
        /// Handles the Click event of the btnWig20 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void btnWig20_Click(object sender, EventArgs e)
        {
            cpPrintingOpt = 9;

            DateTime currentTime = DateTime.Now;

            cpDate = string.Format("{0:MM/dd/yyyy}", currentTime);
            cpTime = string.Format("{0:T}", currentTime);
            seed   = parentForm.storeCode.ToUpper() + "WP20";

            cmd             = new SqlCommand("Get_Latest_CouponNum", parentForm.conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Clear();
            cmd.Parameters.Add("@Seed", SqlDbType.NVarChar).Value = seed + "%";
            SqlParameter LatestCouponNum_Param = cmd.Parameters.Add("@LatestCouponNum", SqlDbType.NVarChar, 15);

            LatestCouponNum_Param.Direction = ParameterDirection.Output;

            parentForm.conn.Open();
            cmd.ExecuteNonQuery();
            parentForm.conn.Close();

            if (cmd.Parameters["@LatestCouponNum"].Value == DBNull.Value)
            {
                newCouponNum = 0;
            }
            else
            {
                newCouponNum = Convert.ToInt64((cmd.Parameters["@LatestCouponNum"].Value.ToString().Substring(6))) + 1;
            }
            newCouponNumLen = Convert.ToString(newCouponNum).Length;

            switch (newCouponNumLen)
            {
            case 1:
                newCouponNumToString = seed + "00000" + Convert.ToString(newCouponNum);
                newCouponNumLen      = 0;
                break;

            case 2:
                newCouponNumToString = seed + "0000" + Convert.ToString(newCouponNum);
                newCouponNumLen      = 0;
                break;

            case 3:
                newCouponNumToString = seed + "000" + Convert.ToString(newCouponNum);
                newCouponNumLen      = 0;
                break;

            case 4:
                newCouponNumToString = seed + "00" + Convert.ToString(newCouponNum);
                newCouponNumLen      = 0;
                break;

            case 5:
                newCouponNumToString = seed + "0" + Convert.ToString(newCouponNum);
                newCouponNumLen      = 0;
                break;

            case 6:
                newCouponNumToString = seed + Convert.ToString(newCouponNum);
                newCouponNumLen      = 0;
                break;

            default:
                newCouponNumToString = Convert.ToString(newCouponNum);
                newCouponNumLen      = 0;
                break;
            }

            cmd.CommandText = "Create_Coupon";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Clear();
            cmd.Parameters.Add("@CpStoreCode", SqlDbType.NVarChar).Value = parentForm.storeCode.ToUpper();
            cmd.Parameters.Add("@CpIssuer", SqlDbType.NVarChar).Value    = Issuer;
            cmd.Parameters.Add("@CpNum", SqlDbType.NVarChar).Value       = newCouponNumToString;
            cmd.Parameters.Add("@CpType", SqlDbType.Int).Value           = 1;
            cmd.Parameters.Add("@CpAmt", SqlDbType.Money).Value          = 20;
            cmd.Parameters.Add("@CpIssDate", SqlDbType.NVarChar).Value   = cpDate;
            cmd.Parameters.Add("@CpIsstime", SqlDbType.NVarChar).Value   = cpTime;
            cmd.Parameters.Add("@CpExpDate", SqlDbType.NVarChar).Value   = string.Format("{0:MM/dd/yyyy}", DateTime.Today.AddYears(1));

            parentForm.conn.Open();
            cmd.ExecuteNonQuery();
            parentForm.conn.Close();

            Int32  retVal;
            String errMsg;

            apiAlias.StatusMonitoring pMonitorCB = new apiAlias.StatusMonitoring(StatusMonitoring);

            pdPrint            = new PrintDocument();
            pdPrint.PrintPage += new PrintPageEventHandler(pdPrint_PrintPage);
            pdPrint.PrinterSettings.PrinterName = parentForm.PRINTER_NAME;

            try
            {
                // Open Printer Monitor of Status API.
                mpHandle = apiAlias.BiOpenMonPrinter(apiAlias.TYPE_PRINTER, parentForm.PRINTER_NAME);
                if (mpHandle < 0)
                {
                    MessageBox.Show("Failed to open printer status monitor.", "", MessageBoxButtons.OK);
                }
                else
                {
                    isFinish  = false;
                    cancelErr = false;

                    // Set the callback function that will monitor printer status.
                    retVal = apiAlias.BiSetStatusBackFunction(mpHandle, pMonitorCB);

                    if (retVal != apiAlias.SUCCESS)
                    {
                        MessageBox.Show("Failed to set callback function.", "", MessageBoxButtons.OK);
                    }
                    else
                    {
                        // Wait until callback function will say that the task is done.
                        // When done, end the monitoring of printer status.
                        //do
                        //{
                        //    if (isFinish)
                        //        retVal = apiAlias.BiCancelStatusBack(mpHandle);
                        //} while (!isFinish);

                        // Display the status/error message.
                        //DisplayStatusMessage();

                        // If an error occurred, restore the recoverable error.
                        if (cancelErr)
                        {
                            retVal = apiAlias.BiCancelError(mpHandle);
                        }
                        else
                        {
                            pdPrint.Print();
                            cpPrintingOpt = 0;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                MessageBox.Show("Failed to open StatusAPI.", errMsg, MessageBoxButtons.OK);
                cpPrintingOpt = 0;
            }
            finally
            {
                // Close Printer Monitor.
                if (mpHandle > 0)
                {
                    if (apiAlias.BiCloseMonPrinter(mpHandle) != apiAlias.SUCCESS)
                    {
                        MessageBox.Show("Failed to close printer status monitor.", "", MessageBoxButtons.OK);
                    }
                }

                cpPrintingOpt = 0;
            }
        }
Пример #6
0
        /// <summary>
        /// Handles the Click event of the btnPrintClosingRegister control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void btnPrintClosingRegister_Click(object sender, EventArgs e)
        {
            if (txtDate.Text == "")
            {
                MyMessageBox.ShowBox("INPUT DATE", "ERROR");
                txtDate.Select();
                txtDate.Focus();
                return;
            }
            else
            {
                if (DateTime.TryParse(txtDate.Text.Trim(), out d))
                {
                    cmd             = new SqlCommand("Get_ClosingRegister_Information", parentForm.conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Clear();
                    cmd.Parameters.Add("@RegisterNum", SqlDbType.NVarChar).Value = parentForm.cashRegisterNum.ToUpper();
                    cmd.Parameters.Add("@RegDate", SqlDbType.NVarChar).Value     = string.Format("{0:MM/dd/yyyy}", d);
                    SqlParameter CheckNum_Param           = cmd.Parameters.Add("@CheckNum", SqlDbType.TinyInt);
                    SqlParameter TransactionID_Param      = cmd.Parameters.Add("@TransactionID", SqlDbType.BigInt);
                    SqlParameter RegStartAmount_Param     = cmd.Parameters.Add("@RegStartAmount", SqlDbType.Money);
                    SqlParameter RegCashSalesAmount_Param = cmd.Parameters.Add("@RegCashSalesAmount", SqlDbType.Money);
                    SqlParameter RegCashRealAmount_Param  = cmd.Parameters.Add("@RegCashRealAmount", SqlDbType.Money);
                    SqlParameter RegWithdrawAmount_Param  = cmd.Parameters.Add("@RegWithdrawAmount", SqlDbType.Money);
                    SqlParameter RegShortageAmount_Param  = cmd.Parameters.Add("@RegShortageAmount", SqlDbType.Money);
                    SqlParameter RegTime_Param            = cmd.Parameters.Add("@RegTime", SqlDbType.NVarChar, 50);
                    SqlParameter RegCashierID_Param       = cmd.Parameters.Add("@RegCashierID", SqlDbType.NVarChar, 50);
                    SqlParameter RegManagerID_Param       = cmd.Parameters.Add("@RegManagerID", SqlDbType.NVarChar, 50);
                    CheckNum_Param.Direction           = ParameterDirection.Output;
                    TransactionID_Param.Direction      = ParameterDirection.Output;
                    RegStartAmount_Param.Direction     = ParameterDirection.Output;
                    RegCashSalesAmount_Param.Direction = ParameterDirection.Output;
                    RegCashRealAmount_Param.Direction  = ParameterDirection.Output;
                    RegWithdrawAmount_Param.Direction  = ParameterDirection.Output;
                    RegShortageAmount_Param.Direction  = ParameterDirection.Output;
                    RegTime_Param.Direction            = ParameterDirection.Output;
                    RegCashierID_Param.Direction       = ParameterDirection.Output;
                    RegManagerID_Param.Direction       = ParameterDirection.Output;

                    parentForm.conn.Open();
                    cmd.ExecuteNonQuery();
                    parentForm.conn.Close();

                    if (Convert.ToInt16(cmd.Parameters["@CheckNum"].Value) != 0)
                    {
                        TransactionID      = Convert.ToInt64(cmd.Parameters["@TransactionID"].Value);
                        regStartAmount     = Convert.ToDouble(cmd.Parameters["@RegStartAmount"].Value);
                        regCashSalesAmount = Convert.ToDouble(cmd.Parameters["@RegCashSalesAmount"].Value);
                        regCashRealAmount  = Convert.ToDouble(cmd.Parameters["@RegCashRealAmount"].Value);
                        regWithdrawAmount  = Convert.ToDouble(cmd.Parameters["@RegWithdrawAmount"].Value);
                        regShortageAmount  = Convert.ToDouble(cmd.Parameters["@RegShortageAmount"].Value);
                        regDate            = string.Format("{0:MM/dd/yyyy}", d);
                        regTime            = Convert.ToString(cmd.Parameters["@RegTime"].Value);
                        regCashierID       = Convert.ToString(cmd.Parameters["@RegCashierID"].Value);
                        regManagerID       = Convert.ToString(cmd.Parameters["@RegManagerID"].Value);

                        Int32  retVal;
                        String errMsg;
                        apiAlias.StatusMonitoring pMonitorCB = new apiAlias.StatusMonitoring(StatusMonitoring);

                        pdPrint            = new PrintDocument();
                        pdPrint.PrintPage += new PrintPageEventHandler(pdPrint_PrintPage);
                        pdPrint.PrinterSettings.PrinterName = parentForm.PRINTER_NAME;

                        try
                        {
                            // Open Printer Monitor of Status API.
                            mpHandle = apiAlias.BiOpenMonPrinter(apiAlias.TYPE_PRINTER, pdPrint.PrinterSettings.PrinterName);
                            if (mpHandle < 0)
                            {
                                MessageBox.Show("Failed to open printer status monitor.", "", MessageBoxButtons.OK);
                            }
                            else
                            {
                                isFinish  = false;
                                cancelErr = false;

                                // Set the callback function that will monitor printer status.
                                retVal = apiAlias.BiSetStatusBackFunction(mpHandle, pMonitorCB);

                                if (retVal != apiAlias.SUCCESS)
                                {
                                    MessageBox.Show("Failed to set callback function.", "", MessageBoxButtons.OK);
                                }
                                else
                                {
                                    // Start printing.
                                    //pdPrint1.Print();
                                    //pdPrint2.Print();

                                    // Wait until callback function will say that the task is done.
                                    // When done, end the monitoring of printer status.
                                    //do
                                    //{
                                    //    if (isFinish)
                                    //        retVal = apiAlias.BiCancelStatusBack(mpHandle);
                                    //} while (!isFinish);

                                    // Display the status/error message.
                                    //DisplayStatusMessage();

                                    // If an error occurred, restore the recoverable error.
                                    if (cancelErr)
                                    {
                                        retVal = apiAlias.BiCancelError(mpHandle);
                                    }
                                    else
                                    {
                                        pdPrint.Print();
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            errMsg = ex.Message;
                            MessageBox.Show("Failed to open StatusAPI.", "", MessageBoxButtons.OK);
                        }
                        finally
                        {
                            // Close Printer Monitor.
                            if (mpHandle > 0)
                            {
                                if (apiAlias.BiCloseMonPrinter(mpHandle) != apiAlias.SUCCESS)
                                {
                                    MessageBox.Show("Failed to close printer status monitor.", "", MessageBoxButtons.OK);
                                }
                            }
                        }
                    }
                    else
                    {
                        MyMessageBox.ShowBox("NOT YET CLOSED", "ERROR");
                        txtDate.SelectAll();
                        txtDate.Focus();
                        return;
                    }
                }
                else
                {
                    MyMessageBox.ShowBox("INVALID DATE", "ERROR");
                    txtDate.SelectAll();
                    txtDate.Focus();
                    return;
                }
            }
        }