Esempio n. 1
0
        private void savesmartPos()
        {
            try
            {
                if (string.IsNullOrEmpty(txtSAmount.Text) || dataGridView4.Rows.Count <= 0)
                {
                    FrmMessage.Show("You cannot Generate Bill without Items");
                }

                else
                {
                    sqlhelper = new SQLHelper();
                    bool result;

                    DataSet ds = new DataSet();
                    int     count;
                    ds = sqlhelper.ExecuteQueries("select TranNo from TransactionNo");
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        if (string.IsNullOrEmpty(ds.Tables[0].Rows[0]["TranNo"].ToString()))
                        {
                            count = 1;
                        }
                        else
                        {
                            count = int.Parse(ds.Tables[0].Rows[0]["TranNo"].ToString()) + 1;
                        }
                    }
                    else
                    {
                        count = 1;
                    }

                    string todaysDate = sqlhelper.ExecuteScalar("select format(date(),'ddmmyyyy')");
                    trnNo  = todaysDate + count;
                    result = sqlhelper.ExecuteNonQuery("insert into Payment(TransactionNo,TotalAmount,DiscountAmount,BillPaid,CreatedBy)" +
                                                       "values ('" + trnNo + "','" + txtSTotal.Text + "','" + txtSDiscount.Text + "', '" + txtSAmount.Text + "'," +
                                                       "" + GlobalData.UserID + ")");

                    result = sqlhelper.ExecuteNonQuery("insert into TaxHistory(TransactionNo,TotalAmount,DiscountAmount,BillPaid,VATAmount,Paid,CreatedBy)" +
                                                       "values ('" + trnNo + "','" + txtSTotal.Text + "','" + txtSDiscount.Text + "', '" + txtSAmount.Text + "', '" + SVatAmt.Text + "', '" + SDue.Text + "'," +
                                                       "" + GlobalData.UserID + ")");


                    if (result == true)
                    {
                        //string InitCode = "";
                        //int lengthofInitCode = 0;
                        //string MaxCode;

                        string PaymentId = sqlhelper.ExecuteScalar("select max(PaymentID) from Payment");

                        for (int i = 0; i < dataGridView4.Rows.Count - 1; i++)
                        {
                            //InitCode = sqlhelper.ExecuteScalar("select CategoryInitCode from Categories where CategoryID=" + dataGridView1.Rows[i].Cells[5].Value.ToString() + "");
                            //lengthofInitCode = InitCode.Split('-')[0].Length + 1;

                            //MaxCode = sqlhelper.ExecuteScalar("SELECT Max(val(Mid([CodeNo]," + (lengthofInitCode + 1) + "))) as MaxCode FROM Transactions where CategoryID =" + dataGridView1.Rows[i].Cells[5].Value.ToString() + "");
                            //if (string.IsNullOrEmpty(MaxCode))
                            //{
                            //    MaxCode = InitCode.Split('-')[1];
                            //}
                            //InitCode = InitCode.Split('-')[0] + "-";
                            //MaxCode = InitCode + (int.Parse(MaxCode) + 1).ToString();

                            result = sqlhelper.ExecuteNonQuery("insert into Transactions(PaymentID,Barcode,CategoryID,ItemID,SaleQty,VatPercent,ItemPrice,CreatedBy)" +
                                                               "values (" + PaymentId + ",'" + dataGridView4.Rows[i].Cells["Barcode"].Value.ToString() + "'," + dataGridView4.Rows[i].Cells["CategoryID"].Value.ToString() + "," +
                                                               "" + dataGridView4.Rows[i].Cells["ItemID"].Value.ToString() + "," + dataGridView4.Rows[i].Cells["Qty"].Value.ToString() + "," +
                                                               "" + dataGridView4.Rows[i].Cells["Vat(%)"].Value.ToString() + "," + dataGridView4.Rows[i].Cells["Price"].Value.ToString() + "," + GlobalData.UserID + ")");

                            result = sqlhelper.ExecuteNonQuery("Update Stock Set StockQuantity = (StockQuantity - " + dataGridView4.Rows[i].Cells["Qty"].Value.ToString() + ")" +
                                                               " where CategoryID= " + dataGridView4.Rows[i].Cells["CategoryID"].Value.ToString() + " and  " +
                                                               "ItemID=" + dataGridView4.Rows[i].Cells["ItemID"].Value.ToString() + " and Barcode='" + dataGridView4.Rows[i].Cells["Barcode"].Value.ToString() + "'");
                        }

                        if (result == true)
                        {
                            if (checkBox8.Checked == true)
                            {
                                if (string.IsNullOrEmpty(textBox64.Text))
                                {
                                }
                                else
                                {
                                    result = sqlhelper.ExecuteNonQuery("insert into DEALERCREDIT(DealerID,TransactionNo,TotalAmount,DiscountAmount,AfterDiscount,VATAmount,TOTALDUE,CreatedBy,STATUS)" +
                                                                       "values ('" + DEALERID + "','" + trnNo + "','" + txtSTotal.Text + "', '" + txtSDiscount.Text + "', '" + txtSAmount.Text + "', " + SVatAmt.Text + ", " + SDue.Text + ", " + GlobalData.UserID + ", 'CREDIT')");
                                    checkBox8.Checked = false;
                                    panel24.Visible   = false;
                                    textBox62.Text    = string.Empty;
                                    textBox63.Text    = string.Empty;
                                    textBox64.Text    = string.Empty;
                                }
                            }

                            if (checkBox7.Checked == true)
                            {
                                if (string.IsNullOrEmpty(textBox61.Text))
                                {
                                }
                                else
                                {
                                    result = sqlhelper.ExecuteNonQuery("insert into AGENTEARNEDCOMISSION(ANO,TransactionNo,COMISSIONEARNED,COMISSION)" +
                                                                       "values ('" + ANO + "','" + trnNo + "','" + textBox58.Text + "', '" + textBox59.Text + "')");
                                    checkBox7.Checked = false;
                                    panel23.Visible   = false;
                                    textBox58.Text    = string.Empty;
                                    textBox59.Text    = string.Empty;
                                    textBox60.Text    = string.Empty;
                                    textBox61.Text    = string.Empty;
                                }
                            }


                            BillPrintPreview.Document = printDocument3;
                            BillPrintPreview.PrintPreviewControl.Zoom = 1;
                            BillPrintPreview.ShowDialog();

                            // BillPrint.Print();
                        }
                    }


                    FrmMessage.Show("Transaction Successful");


                    Frm_POS form = new Frm_POS
                    {
                        MdiParent = this.MdiParent,
                        Anchor    = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                                                                           | System.Windows.Forms.AnchorStyles.Left)
                                                                          | System.Windows.Forms.AnchorStyles.Right))),
                        Dock = DockStyle.Fill
                    };

                    form.Show();

                    //cancelSmarttrans();
                    //textBox12.Text = string.Empty;
                    //textBox13.Text = string.Empty;
                    //textBox14.Text = string.Empty;
                    //textBox15.Text = string.Empty;
                    //SVatAmt.Text = "0";
                    ////textBox16.Text = "0";
                    //textBox18.Text = "0";
                    //txtSTotal.Text = "0";
                    //textBox19.Text = "PACNO";
                    //txtSAmount.Text = "0";


                    //button10.Visible = true;
                    //button8.Visible = false;
                }
            }
            catch (Exception ex)
            {
                FrmMessage.Show(ex.ToString());
            }
        }
Esempio n. 2
0
        private void savesmartPos1()
        {
            try
            {
                if (string.IsNullOrEmpty(txtSAmount.Text) || dataGridView4.Rows.Count <= 0)
                {
                    FrmMessage.Show("You cannot Generate Bill without Items");
                }
                else if (string.IsNullOrEmpty(textBox12.Text) || string.IsNullOrEmpty(textBox19.Text))
                {
                    FrmMessage.Show("Redeem Card No should be Entered or Cancel the Redeem");
                }
                else
                {
                    sqlhelper = new SQLHelper();
                    bool result;

                    //result = sqlhelper.ExecuteNonQuery("insert into Customers(CustName,Phone) values ('" + txtCustName.Text + "'," + txtCustPhnNo.Text + ")");
                    //if (result == true)
                    //{

                    DataSet ds = new DataSet();
                    int     count;
                    ds = sqlhelper.ExecuteQueries("select TranNo from TransactionNo");
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        if (string.IsNullOrEmpty(ds.Tables[0].Rows[0]["TranNo"].ToString()))
                        {
                            count = 1;
                        }
                        else
                        {
                            count = int.Parse(ds.Tables[0].Rows[0]["TranNo"].ToString()) + 1;
                        }
                    }
                    else
                    {
                        count = 1;
                    }

                    string todaysDate = sqlhelper.ExecuteScalar("select format(date(),'ddmmyyyy')");
                    trnNo  = todaysDate + count;
                    result = sqlhelper.ExecuteNonQuery("insert into Payment(TransactionNo,TotalAmount,DiscountAmount,BillPaid,CreatedBy)" +
                                                       "values ('" + trnNo + "','" + txtSTotal.Text + "','" + txtSDiscount.Text + "', '" + txtSAmount.Text + "'," +
                                                       "" + GlobalData.UserID + ")");

                    result = sqlhelper.ExecuteNonQuery("insert into TaxHistory(TransactionNo,TotalAmount,DiscountAmount,BillPaid,VATAmount,Paid,CreatedBy)" +
                                                       "values ('" + trnNo + "','" + txtSTotal.Text + "','" + txtSDiscount.Text + "', '" + txtSAmount.Text + "','" + SVatAmt.Text + "', '" + SDue.Text + "'," +
                                                       "" + GlobalData.UserID + ")");

                    if (result == true)
                    {
                        string PaymentId = sqlhelper.ExecuteScalar("select max(PaymentID) from Payment");

                        for (int i = 0; i < dataGridView4.Rows.Count; i++)
                        {
                            result = sqlhelper.ExecuteNonQuery("insert into Transactions(PaymentID,Barcode,CategoryID,ItemID,SaleQty,VatPercent,ItemPrice,CreatedBy)" +
                                                               "values (" + PaymentId + ",'" + dataGridView4.Rows[i].Cells["Barcode"].Value.ToString() + "'," + dataGridView4.Rows[i].Cells["CategoryID"].Value.ToString() + "," +
                                                               "" + dataGridView4.Rows[i].Cells["ItemID"].Value.ToString() + "," + dataGridView4.Rows[i].Cells["Qty"].Value.ToString() + "," +
                                                               "" + dataGridView4.Rows[i].Cells["Vat(%)"].Value.ToString() + "," + dataGridView4.Rows[i].Cells["Price"].Value.ToString() + "," + GlobalData.UserID + ")");

                            result = sqlhelper.ExecuteNonQuery("Update Stock Set StockQuantity = (StockQuantity - " + dataGridView4.Rows[i].Cells["Qty"].Value.ToString() + ")" +
                                                               " where CategoryID= " + dataGridView4.Rows[i].Cells["CategoryID"].Value.ToString() + " and  " +
                                                               "ItemID=" + dataGridView4.Rows[i].Cells["ItemID"].Value.ToString() + " and Barcode='" + dataGridView4.Rows[i].Cells["Barcode"].Value.ToString() + "'");
                        }


                        result = sqlhelper.ExecuteNonQuery("insert into RewardPoints(Points, PACNO)" +
                                                           "values (" + textBox15.Text + "," + textBox19.Text + ")");


                        if (redeemclick == true)
                        {
                            result = sqlhelper.ExecuteNonQuery("insert into RewardPointsUsed(TransactionNo, PACNO, POINTSUSED)" +
                                                               "values (" + trnNo + "," + textBox19.Text + "," + textBox18.Text + ")");

                            result = sqlhelper.ExecuteNonQuery("insert into RewardPoints(Points, PACNO)" +
                                                               "values (" + "-" + textBox18.Text + "," + textBox19.Text + ")");
                        }

                        if (result == true)
                        {
                            if (checkBox8.Checked == true)
                            {
                                if (string.IsNullOrEmpty(textBox64.Text))
                                {
                                }
                                else
                                {
                                    result = sqlhelper.ExecuteNonQuery("insert into DEALERCREDIT(DealerID,TransactionNo,TotalAmount,DiscountAmount,AfterDiscount,VATAmount,TOTALDUE,CreatedBy,STATUS)" +
                                                                       "values ('" + DEALERID + "','" + trnNo + "','" + txtSTotal.Text + "', '" + txtSDiscount.Text + "', '" + txtSAmount.Text + "', " + SVatAmt.Text + ", " + SDue.Text + ", " + GlobalData.UserID + ", 'CREDIT')");
                                    checkBox8.Checked = false;
                                    panel24.Visible   = false;
                                    textBox62.Text    = string.Empty;
                                    textBox63.Text    = string.Empty;
                                    textBox64.Text    = string.Empty;
                                }
                            }

                            if (checkBox7.Checked == true)
                            {
                                if (string.IsNullOrEmpty(textBox61.Text))
                                {
                                }
                                else
                                {
                                    result = sqlhelper.ExecuteNonQuery("insert into AGENTEARNEDCOMISSION(ANO,TransactionNo,COMISSIONEARNED,COMISSION)" +
                                                                       "values ('" + ANO + "','" + trnNo + "','" + textBox58.Text + "', '" + textBox59.Text + "')");
                                    checkBox7.Checked = false;
                                    panel23.Visible   = false;
                                    textBox58.Text    = string.Empty;
                                    textBox59.Text    = string.Empty;
                                    textBox60.Text    = string.Empty;
                                    textBox61.Text    = string.Empty;
                                }
                            }



                            BillPrintPreview.Document = printDocument3;
                            BillPrintPreview.PrintPreviewControl.Zoom = 1;
                            BillPrintPreview.ShowDialog();

                            // BillPrint.Print();
                        }
                    }


                    FrmMessage.Show("Transaction Successful");
                    Frm_POS form = new Frm_POS
                    {
                        MdiParent = this.MdiParent,
                        Anchor    = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                                                                           | System.Windows.Forms.AnchorStyles.Left)
                                                                          | System.Windows.Forms.AnchorStyles.Right))),
                        Dock = DockStyle.Fill
                    };

                    form.Show();
                }
            }
            catch (Exception ex)
            {
                FrmMessage.Show(ex.ToString());
            }
        }