Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            int    TotalCount = 0;
            string CashRegisterInitialValue = "0.00";

            if (!cf.CheckCashDrawerOfDay(BranchCode, ref CashRegisterInitialValue))
            {
                MessageBox.Show("Error: You have already set your cash drawer today.\nTo change it use administrative account.", "Cash Drawer Amount : " + CashRegisterInitialValue, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            DialogResult dr = MessageBox.Show("Are you sure you want to set this value to your cash drawer?", "Cash Drawer Value:" + lblTotalAmount.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (dr == DialogResult.Yes)
            {
                if ((lblTotalAmount.Text == "0.00") || (lblTotalAmount.Text == "0"))
                {
                    DialogResult dr2 = MessageBox.Show("Warning: Are you sure you want to save 0.00 amount?", "Zero Amount Defined", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dr2 == DialogResult.No)
                    {
                        return;
                    }
                }
                else
                {
                    bool ErrorSaved = false;
                    foreach (DataGridViewRow dgr in dataGridView1.Rows)
                    {
                        if (dgr.Cells["Count"].Value != "0")
                        {
                            TotalCount += dgr.Cells["Total"].Value.ToString() != "0.00" ? int.Parse(dgr.Cells["Total"].Value.ToString()):0;
                        }
                    }

                    if ((decimal.Parse(TotalCount.ToString()) == decimal.Parse(lblTotalAmount.Text)).ToString()
                        == ((decimal.Parse(textBox1.Text).ToString() == (decimal.Parse(lblTotalAmount.Text).ToString())).ToString()))
                    {
                        string PK = string.Empty;

                        if (cf.InsertCashDrawer(BranchCode, lblTotalAmount.Text, "In", ActiveUser, ref PK))
                        {
                            if (!string.IsNullOrEmpty(PK))
                            {
                                foreach (DataGridViewRow dgr in dataGridView1.Rows)
                                {
                                    if (dgr.Cells["Count"].Value.ToString() != "0")
                                    {
                                        int PK_ID      = int.Parse(cf.GetFieldsbyValues("tblMoneyEntry", "TOP 1 sysiD", " where POS_PK='" + PK + "'"));
                                        int MoneyValue = int.Parse(dgr.Cells["Amount"].Value.ToString());
                                        int Quantity   = int.Parse(dgr.Cells["Count"].Value.ToString());
                                        if (!cf.InsertDetailCashDrawer(BranchCode, PK_ID, MoneyValue, Quantity))
                                        {
                                            MessageBox.Show("Error: Cannot save cash drawer information. Please check your entry", "Cash Drawer Save Failed.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                            if (cf.DeleteCashDrawer(PK))
                                            {
                                                cf.DeleteDetailCashDrawer(PK_ID.ToString());
                                            }
                                            ErrorSaved = true;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        if (!ErrorSaved)
                        {
                            MessageBox.Show("Cash Drawer for today was successfully saved", "Cash Drawer", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            this.Close();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Error: Details amount is not tally with Total Amount.", "Please check", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }