예제 #1
0
        public void newInvoce(string _invoNo, DateTime _date, string _seller, decimal _subTotal, decimal tax, decimal _total, int _noOfQty, decimal _cash, decimal _change)
        {
            SqlCommand cmd = new SqlCommand(@"INSERT INTO tblInvoice VALUES('" + _invoNo + "','" + _date + "','" + _seller + "','" + _subTotal + "','" + tax + "','" + _total + "','" + _noOfQty + "','" + _cash + "','" + _change + "')", ConnectionDB.connection());

            cmd.ExecuteNonQuery();
        }
예제 #2
0
        public string invoNo_AutoNo()
        {
            SqlCommand    com = new SqlCommand("SELECT MAX(invoiceNo) FROM tblInvoice", ConnectionDB.connection());
            SqlDataReader dr  = com.ExecuteReader();

            while (dr.Read() == true)
            {
                tblInvo = dr[0].ToString();
            }
            return(tblInvo);
        }
예제 #3
0
        public SqlDataReader select_to_Qntity(string _itemNo)
        {
            SqlCommand    com = new SqlCommand("SELECT noOfQty FROM tbl_Item WHERE itemNo='" + _itemNo + "'", ConnectionDB.connection());
            SqlDataReader dr  = com.ExecuteReader();

            return(dr);
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtNoOfQuantity.Text != "" && cbxItemNo.Text != "")
                {
                    if (int.Parse(txtNoOfQuantity.Text) != 0)
                    {
                        //ITEM LOAD GRIDVIEW START
                        txtNoOfQuantity.SelectAll();
                        item_No = objInvo.itemMaxNo();
                        if (int.Parse(cbxItemNo.Text) <= int.Parse(item_No))
                        {
                            //item price and other details get
                            string        OneQtSellPrice1;
                            SqlCommand    cmd = new SqlCommand("SELECT description,OneQtySellPrice FROM tbl_Item WHERE itemNo='" + cbxItemNo.Text + "'", ConnectionDB.connection());
                            SqlDataReader dr1 = cmd.ExecuteReader();
                            while (dr1.Read() == true)
                            {
                                description         = dr1["description"].ToString();// This one can use only 0 inedex -->  dr[0].ToString()
                                OneQtSellPrice1     = dr1["OneQtySellPrice"].ToString();
                                OneQtSellPrice      = Convert.ToDecimal(OneQtSellPrice1);
                                txtDescription.Text = description;
                            }
                        }
                        else
                        {
                            DialogResult result = MessageBox.Show("This item not exist!.", "ITEM DETAILS", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            if (result == DialogResult.OK)
                            {
                                cbxItemNo.Focus();
                            }
                        }
                        //ITEM LOAD GRIDVIEW END


                        epNoOfQty.Clear();
                        epItemNo.Clear();

                        int intVal = 0;
                        //Add item for invoice

                        //item exist checking
                        SqlDataReader dr = objInvo.checkExistItem(cbxItemNo.Text);
                        if (!dr.Read())
                        {
                            //Stock quantity check and add it for invoice table
                            SqlDataReader drm = objInvo.select_to_Qntity(cbxItemNo.Text);
                            if (drm.Read())
                            {
                                if (int.TryParse(txtNoOfQuantity.Text, out intVal))
                                {
                                    int qty = int.Parse(drm["noOfQty"].ToString());
                                    if (int.Parse(txtNoOfQuantity.Text) <= qty)
                                    {
                                        objInvo.newInvoItemAdd(lblInvoiceNo.Text, cbxItemNo.Text, description, int.Parse(txtNoOfQuantity.Text), OneQtSellPrice);
                                    }
                                    else
                                    {
                                        MessageBox.Show("Not enought Quantity in the stock!. Available Quantity are " + qty.ToString(), "STOCK LEVEL", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                    }
                                }
                            }
                            else
                            {
                                MessageBox.Show("Does not exist this item!.", "ITEM EXIST", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                        else
                        {
                            MessageBox.Show("This item is exist!.", "ITEM EXIST", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        cbxItemNo.Focus();


                        //Datagridview refresh
                        dgvRefresh();

                        //calculate subtotaltotal price
                        subTotCal();

                        //Calculate total price
                        totalPriceCalculate();


                        cbxItemNo.Items.Clear();
                        cbxItemNo.Text = "";
                        txtNoOfQuantity.Clear();
                        txtDescription.Clear();
                    }
                    else
                    {
                        epNoOfQty.SetError(txtNoOfQuantity, "Can not be Zero!");
                    }
                }
                else
                {
                    if (cbxItemNo.Text == "")
                    {
                        epItemNo.SetError(cbxItemNo, "Enter the correct item number!");
                    }
                    if (txtNoOfQuantity.Text == "")
                    {
                        epNoOfQty.SetError(txtNoOfQuantity, "Enter the no of quantity!");
                    }
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); cbxItemNo.Focus(); }
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                if (dgvInvoiceItem.Rows.Count != 0)
                {
                    //Delete item in invoice item table
                    SqlCommand cmd = new SqlCommand("DELETE FROM tblInvoiceItems WHERE ItmNo='" + dgvInvoiceItem.CurrentRow.Cells["ItmNo"].Value.ToString() + "'", ConnectionDB.connection());
                    cmd.ExecuteNonQuery();
                }
                else
                {
                    MessageBox.Show("Items are empty!. Please add items.", "SELL ITEMS DETAILS", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                //Datagridview refresh
                dgvRefresh();

                //calculate subtotaltotal price
                subTotCal();

                //Calculate total price
                totalPriceCalculate();

                cbxItemNo.Items.Clear();
                cbxItemNo.Text = "";
                txtNoOfQuantity.Clear();
                txtDescription.Clear();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }
예제 #6
0
        //New Item add method.
        public void newItemAdd(string _itemNo, string descrip, int _noOfQty, decimal _1QtySellPrice)
        {
            SqlCommand cmd = new SqlCommand(@"INSERT INTO tbl_Item VALUES('" + _itemNo + "','" + descrip + "','" + _noOfQty + "','" + _1QtySellPrice + "')", ConnectionDB.connection());

            cmd.ExecuteNonQuery();
        }
예제 #7
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtAnswer.Text != "" && txtPassword.Text != "" && cbxSecQue.Text != "")
                {
                    SqlCommand cmd = new SqlCommand("UPDATE tblUsers SET password='******', secQu='" + cbxSecQue.Text + "', answer='" + txtAnswer.Text + "' WHERE username='******'", ConnectionDB.connection());
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("Update completed!", "USER UPDATE", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM tblUsers", ConnectionDB.connection());
                    DataTable      dt = new DataTable();
                    da.Fill(dt);
                    dgvUser.DataSource = dt;

                    txtAnswer.Clear();
                    txtPassword.Clear();
                    txtUsername.Clear();
                    cbxSecQue.Text = "";
                }
                else
                {
                    MessageBox.Show("Please enter details", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }
        //BILL PRINT TABLE VVALUE ADD
        public void billPrint()
        {
            try
            {
                //clear table
                string     sqlTrunc1 = "TRUNCATE TABLE " + "tblBIllPrintItem";
                SqlCommand cmd22     = new SqlCommand(sqlTrunc1, ConnectionDB.connection());
                cmd22.ExecuteNonQuery();
                //clear table
                string     sqlTrunc2 = "TRUNCATE TABLE " + "tblBillPrintPrice";
                SqlCommand cmd33     = new SqlCommand(sqlTrunc2, ConnectionDB.connection());
                cmd33.ExecuteNonQuery();



                //BILL PRINT ITEM DETAIL
                String         sql = "SELECT * FROM tblInvoiceItems";
                SqlDataAdapter get = new SqlDataAdapter(sql, ConnectionDB.connection());
                DataTable      ns  = new DataTable();
                get.Fill(ns);
                for (int i = 0; i < ns.Rows.Count; i++)
                {
                    string     itemNo          = ns.Rows[i]["ItmNo"].ToString();
                    string     itemDescrip     = ns.Rows[i]["itemDescrip"].ToString();
                    int        noOfQty         = int.Parse(ns.Rows[i]["noOfQty"].ToString());
                    decimal    OneQtySellPrice = Convert.ToDecimal(ns.Rows[i]["OneQtySellPrice"].ToString());
                    SqlCommand cmd112          = new SqlCommand(@"INSERT INTO tblBIllPrintItem VALUES('" + itemNo + "','" + itemDescrip + "','" + noOfQty + "','" + OneQtySellPrice + "')", ConnectionDB.connection());
                    cmd112.ExecuteNonQuery();
                }
                //BILL PRINT PRICE DETAIL
                String        _sq1l = "SELECT * FROM tblInvoice WHERE invoiceNo='" + lblInvoiceNo.Text + "'";
                SqlCommand    cmd   = new SqlCommand(_sq1l, ConnectionDB.connection());
                SqlDataReader dr    = cmd.ExecuteReader();
                while (dr.Read() == true)
                {
                    string  seller   = dr["seller"].ToString();                      //06
                    decimal subTotal = Convert.ToDecimal(dr["subTotal"].ToString()); //07
                    decimal tax      = Convert.ToDecimal(dr["tax"].ToString());      //08
                    decimal toatal   = Convert.ToDecimal(dr["toatal"].ToString());   //09
                    int     noOfQty  = int.Parse(dr["noOfQty"].ToString());          //10
                    decimal cash     = Convert.ToDecimal(dr["cash"].ToString());     //11
                    decimal change   = decimal.Parse(dr["change"].ToString());       //12

                    SqlCommand cmdo = new SqlCommand(@"INSERT INTO tblBillPrintPrice VALUES('" + lblInvoiceNo.Text + "','" + subTotal + "','" + tax + "','" + toatal + "','" + noOfQty + "','" + cash + "','" + change + "','" + seller + "')", ConnectionDB.connection());
                    cmdo.ExecuteNonQuery();
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }
        private void btnSell_Click(object sender, EventArgs e)
        {
            try
            {
                noOfAllQty = 0;//All Quantity Start Zero

                epCash.Clear();
                epSubTotal.Clear();
                epTotal.Clear();

                if (txtCash.Text != "0.00" && txtTotal.Text != "0.00" && txtSubTotal.Text != "0.00")
                {
                    if (decimal.Parse(txtCash.Text) >= decimal.Parse(txtTotal.Text))
                    {
                        SqlDataReader dr = objInvo.checkExistInvoice(lblInvoiceNo.Text);
                        if (!dr.Read())
                        {
                            //COPY tblInvoiceItems VALUE TO tblInvoBillItem
                            String     copyData = "INSERT INTO tblInvoBillItem SELECT * FROM tblInvoiceItems";
                            SqlCommand cmd      = new SqlCommand(copyData, ConnectionDB.connection());
                            cmd.ExecuteNonQuery();


                            //TOTAL ALL QUANTITY CALCULATE
                            String         sql = "SELECT noOfQty FROM tblInvoiceItems";
                            SqlDataAdapter get = new SqlDataAdapter(sql, ConnectionDB.connection());
                            DataTable      ns  = new DataTable();
                            get.Fill(ns);
                            for (int i = 0; i < ns.Rows.Count; i++)
                            {
                                string qty = ns.Rows[i]["noOfQty"].ToString();
                                noOfAllQty += int.Parse(qty);
                            }


                            //INSERT INVOICE DETAILS
                            objInvo.newInvoce(
                                lblInvoiceNo.Text,
                                DateTime.Today,
                                lblSel.Text,
                                decimal.Parse(txtSubTotal.Text),
                                decimal.Parse(txtTax.Text),
                                decimal.Parse(txtTotal.Text),
                                noOfAllQty,
                                decimal.Parse(txtCash.Text),
                                decimal.Parse(txtChange.Text)
                                );


                            //SELL ITEM REMOVE STOCK
                            String         isql = "SELECT * FROM tblInvoiceItems";
                            SqlDataAdapter iget = new SqlDataAdapter(isql, ConnectionDB.connection());
                            DataTable      idt  = new DataTable();
                            iget.Fill(idt);
                            for (int i = 0; i < idt.Rows.Count; i++)
                            {
                                int nowAllQty = 0;
                                //decimal subtotal = 0.0M;

                                string item_no      = idt.Rows[i]["ItmNo"].ToString();
                                int    noOfQuantity = int.Parse(idt.Rows[i]["noOfQty"].ToString());

                                string        csql = "SELECT * FROM tbl_Item WHERE itemNo='" + item_no + "'";
                                SqlCommand    cmdi = new SqlCommand(csql, ConnectionDB.connection());
                                SqlDataReader dr1  = cmdi.ExecuteReader();
                                while (dr1.Read() == true)
                                {
                                    int     stock_noOfQty       = int.Parse(dr1["noOfQty"].ToString());
                                    decimal old_OneQtySellPrice = decimal.Parse(dr1["OneQtySellPrice"].ToString());

                                    //now stock item
                                    nowAllQty = stock_noOfQty - noOfQuantity;

                                    //stock update
                                    objInvo.update_Quntity(item_no, nowAllQty);

                                    //success
                                    picBxSucc.Visible    = true;
                                    lblSucc.Visible      = true;
                                    picBxNotSucc.Visible = false;
                                    lblNotSucc.Visible   = false;

                                    //reset();
                                }
                            }
                        }
                        billPrint();
                        btnSell.Enabled = false;


                        //frmFinalBill frmBill = new frmFinalBill();
                        //frmBill.ShowDialog();


                        CrystalReport1_Bill objCrystal = new CrystalReport1_Bill();
                        objCrystal.PrintToPrinter(1, false, 0, 0);


                        btnSell.Enabled = true;
                        reset();
                    }
                    else
                    {
                        MessageBox.Show("Please fully payement!", "BILL ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    if (txtCash.Text == "0.00")
                    {
                        epCash.SetError(txtCash, "Can not be null.");
                    }
                    if (txtTotal.Text == "0.00")
                    {
                        epSubTotal.SetError(txtSubTotal, "Can not be null.");
                    }
                    if (txtSubTotal.Text == "0.00")
                    {
                        epTotal.SetError(txtTotal, "Can not be null.");
                    }
                    picBxSucc.Visible    = false;
                    lblSucc.Visible      = false;
                    picBxNotSucc.Visible = true;
                    lblNotSucc.Visible   = true;
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }
 private void txtNoOfQuantity_Click(object sender, EventArgs e)
 {
     try {
         txtNoOfQuantity.SelectAll();
         item_No = objInvo.itemMaxNo();
         if (int.Parse(cbxItemNo.Text) <= int.Parse(item_No))
         {
             //item price and other details get
             string        OneQtSellPrice1;
             SqlCommand    cmd = new SqlCommand("SELECT description,OneQtySellPrice FROM tbl_Item WHERE itemNo='" + cbxItemNo.Text + "'", ConnectionDB.connection());
             SqlDataReader dr  = cmd.ExecuteReader();
             while (dr.Read() == true)
             {
                 description         = dr["description"].ToString();// This one can use only 0 inedex -->  dr[0].ToString()
                 OneQtSellPrice1     = dr["OneQtySellPrice"].ToString();
                 OneQtSellPrice      = Convert.ToDecimal(OneQtSellPrice1);
                 txtDescription.Text = description;
             }
         }
         else
         {
             DialogResult result = MessageBox.Show("This item not exist!.", "ITEM DETAILS", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             if (result == DialogResult.OK)
             {
                 cbxItemNo.Focus();
             }
         }
     }
     catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); }
 }
 private void cbxItemNo_KeyDown(object sender, KeyEventArgs e)
 {
     try {
         if (cbxItemNo.Text != "")
         {
             if (e.KeyCode == Keys.Enter)
             {
                 //item description get txt box
                 item_No = objInvo.itemMaxNo();
                 if (int.Parse(cbxItemNo.Text) <= int.Parse(item_No))
                 {
                     SqlCommand    cmd = new SqlCommand("SELECT description FROM tbl_Item WHERE itemNo='" + cbxItemNo.Text + "'", ConnectionDB.connection());
                     SqlDataReader dr  = cmd.ExecuteReader();
                     while (dr.Read() == true)
                     {
                         txtDescription.Text = dr["description"].ToString();
                     }
                     txtNoOfQuantity.Focus();
                     txtNoOfQuantity.SelectAll();
                 }
                 else
                 {
                     DialogResult result = MessageBox.Show("This item not exist!.", "ITEM DETAILS", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                     if (result == DialogResult.OK)
                     {
                         cbxItemNo.Focus();
                     }
                 }
             }
         }
     }
     catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); }
 }
예제 #12
0
        public SqlDataReader userLogin(string _userName, string _password)
        {
            SqlCommand    com = new SqlCommand("SELECT * FROM tblUsers WHERE username='******' AND password='******'", ConnectionDB.connection());
            SqlDataReader dr  = com.ExecuteReader();

            return(dr);
        }
예제 #13
0
        public void userRegister(string _un, string _pass, string _secQu, string _ans)
        {
            SqlCommand cmd = new SqlCommand(@"INSERT INTO tblUsers VALUES('" + _un + "','" + _pass + "','" + _secQu + "','" + _ans + "')", ConnectionDB.connection());

            cmd.ExecuteNonQuery();
        }
예제 #14
0
 private void btnRecover_Click(object sender, EventArgs e)
 {
     try {
         if (txtAnswer.Text != "" && txtUserName.Text != "" && cbxSecQue.Text != "")
         {
             SqlCommand    com = new SqlCommand("SELECT password FROM tblUsers WHERE username='******' AND secQu='" + cbxSecQue.Text + "' AND answer='" + txtAnswer.Text + "'", ConnectionDB.connection());
             SqlDataReader dr  = com.ExecuteReader();
             if (dr.Read())
             {
                 MessageBox.Show("Your password is \n \"" + dr["password"].ToString() + "\"", "PASSWORD RECOVERY", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 this.Close();
             }
             else
             {
                 MessageBox.Show("Please enter corrrect details.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         else
         {
             MessageBox.Show("Please enter detail", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); }
 }
예제 #15
0
        public SqlDataReader checkExistInvoice(string invoiceNo)
        {
            SqlCommand    com = new SqlCommand("SELECT invoiceNo FROM tblInvoice WHERE invoiceNo='" + invoiceNo + "'", ConnectionDB.connection());
            SqlDataReader dr  = com.ExecuteReader();

            return(dr);
        }
        public void dgvRefresh()
        {
            try {
                //Datagridview refresh
                //SqlDataAdapter da = new SqlDataAdapter("SELECT ItmNo,itemDescrip,noOfQty,OneQtySellPrice FROM tblInvoiceItems", ConnectionDB.connection());
                //DataTable dt = new DataTable();
                //da.Fill(dt);
                //BindingSource bnsue = new BindingSource();
                //bnsue.DataSource = dt;
                //dgvInvoiceItem.DataSource = bnsue;
                //da.Update(dt);



                SqlDataAdapter da = new SqlDataAdapter("SELECT ItmNo,itemDescrip,noOfQty,OneQtySellPrice FROM tblInvoiceItems", ConnectionDB.connection());
                DataTable      dt = new DataTable();
                da.Fill(dt);
                dgvInvoiceItem.DataSource = dt;


                dgvInvoiceItem.Columns["ItmNo"].HeaderText           = "Item No";
                dgvInvoiceItem.Columns["itemDescrip"].HeaderText     = "Descreption";
                dgvInvoiceItem.Columns["noOfQty"].HeaderText         = "No. Of Quantity";
                dgvInvoiceItem.Columns["OneQtySellPrice"].HeaderText = "One Qty Sell Price";


                this.dgvInvoiceItem.Columns["ItmNo"].AutoSizeMode           = DataGridViewAutoSizeColumnMode.DisplayedCells;
                this.dgvInvoiceItem.Columns["itemDescrip"].AutoSizeMode     = DataGridViewAutoSizeColumnMode.Fill;
                this.dgvInvoiceItem.Columns["noOfQty"].AutoSizeMode         = DataGridViewAutoSizeColumnMode.DisplayedCells;
                this.dgvInvoiceItem.Columns["OneQtySellPrice"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
            }
            catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }
 private void btnRegister_Click(object sender, EventArgs e)
 {
     try
     {
         if (txtUserNam.Text != "" && txtPassw.Text != "" && txtConfirmPas.Text != "" && cbxSecQues.Text != "" && txtAnsw.Text != "")
         {
             SqlCommand    com = new SqlCommand("SELECT username FROM tblUsers WHERE username='******'", ConnectionDB.connection());
             SqlDataReader dr  = com.ExecuteReader();
             if (!dr.Read() == true)
             {
                 if (txtPassw.Text == txtConfirmPas.Text)
                 {
                     ObjUser.userRegister(txtUserNam.Text, txtPassw.Text, cbxSecQues.Text, txtAnsw.Text);
                     MessageBox.Show("User register successfully.", "REGISTER SUCCESSFULLY", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     this.Close();
                 }
                 else
                 {
                     MessageBox.Show("Please enter same password!.", "PASSWORD ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             else
             {
                 MessageBox.Show("This user exisiting!. Please change Username", "PASSWORD ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); txtUserNam.Clear();
             }
         }
         else
         {
             MessageBox.Show("Can not be empty!.", "DETAILS ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     catch (Exception ex) { MessageBox.Show(ex.Message); }
 }
        public void reset()
        {
            try {
                //clear table
                string     sqlTrunc = "TRUNCATE TABLE " + "tblInvoiceItems";
                SqlCommand cmd      = new SqlCommand(sqlTrunc, ConnectionDB.connection());
                cmd.ExecuteNonQuery();

                //Item Number Auto Increese display the label.
                string rNo = objInvo.invoNo_AutoNo();
                if (rNo.Equals("") || rNo == null)
                {
                    iNo = 00001;
                }
                else
                {
                    iNo = int.Parse(rNo);
                    iNo++;
                }
                if (iNo < 10)
                {
                    lblInvoiceNo.Text = "00000" + Convert.ToString(iNo);
                }
                else if (10 <= iNo && iNo < 100)
                {
                    lblInvoiceNo.Text = "0000" + Convert.ToString(iNo);
                }
                else if (100 <= iNo && iNo < 1000)
                {
                    lblInvoiceNo.Text = "000" + Convert.ToString(iNo);
                }
                else if (1000 <= iNo && iNo < 10000)
                {
                    lblInvoiceNo.Text = "00" + Convert.ToString(iNo);
                }
                else if (10000 <= iNo && iNo < 100000)
                {
                    lblInvoiceNo.Text = "0" + Convert.ToString(iNo);
                }
                else
                {
                    lblInvoiceNo.Text = Convert.ToString(iNo);
                }

                picBxSucc.Visible    = false;
                lblSucc.Visible      = false;
                picBxNotSucc.Visible = false;
                lblNotSucc.Visible   = false;

                txtCash.Text     = "0.00";
                txtTotal.Text    = "0.00";
                txtSubTotal.Text = "0.00";;
                txtTax.Text      = "0.00";
                txtChange.Text   = "0.00";

                dgvRefresh();

                epNoOfQty.Clear();
                epItemNo.Clear();
                epCash.Clear();
                epSubTotal.Clear();
                epTotal.Clear();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }
예제 #19
0
        //item update
        public void updateItem(string _itemNo, string _descrip, int _noOfItem, decimal _1QtySellPri)
        {
            SqlCommand cmd = new SqlCommand("UPDATE tbl_Item SET description='" + _descrip + "', noOfQty='" + _noOfItem + "', oneQtySellPrice='" + _1QtySellPri + "' WHERE itemNo='" + _itemNo + "'", ConnectionDB.connection());

            cmd.ExecuteNonQuery();
        }
예제 #20
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            #region New item add code section
            try
            {
                //++++++++++++++++ New Item Add  ++++++++++++++++
                //Error provider set default point.
                errorProviderSetClear();

                if (txtDescription.Text == "" || txtNoOfQuantity.Text == "" || txt1QtySellPrice.Text == "" || txt1QtySellPrice.Text == "")
                {
                    if (txtDescription.Text == "")
                    {
                        epDescription.SetError(txtDescription, "Please enter item description.");
                    }
                    if (txtNoOfQuantity.Text == "")
                    {
                        epNoOfQuantity.SetError(txtNoOfQuantity, "Please enter no of Quantity.");
                    }
                    if (txt1QtySellPrice.Text == "")
                    {
                        ep1QtySellPrice.SetError(txt1QtySellPrice, "Please enter one quantity sales price.");
                    }

                    lblNotSucc.Visible   = true;
                    picBxNotSucc.Visible = true;
                    //MessageBox.Show("Item added not successfuly!.", "ERROR MESSAGE", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    if ((int.Parse(txtNoOfQuantity.Text) != 0) && (decimal.Parse(txt1QtySellPrice.Text) != 0.00M))
                    {
                        if (btnAdd.Text == "Add")
                        {
                            objItem.newItemAdd(lblItemNo.Text, txtDescription.Text, int.Parse(txtNoOfQuantity.Text), decimal.Parse(txt1QtySellPrice.Text));//Here update method call, but date patameter for database item table date column datatype not use "datetime". Therefore we can use "date" datatype.
                            lblSucc.Visible   = true;
                            picBxSucc.Visible = true;
                            DialogResult result = MessageBox.Show("Item added successfuly!.", "COMPLETE MESSAGE", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            if (result == DialogResult.OK)
                            {
                                lblNotSucc.Visible   = false;
                                picBxNotSucc.Visible = false;

                                lblSucc.Visible   = false;
                                picBxSucc.Visible = false;

                                //Datagridview for items load method call.
                                loadItemDataForDgv();
                                //allways display datagridview last row.
                                dgvItems.CurrentCell = dgvItems.Rows[dgvItems.RowCount - 1].Cells[0];

                                //Clear all textbox function call.
                                ClearAllText(this);

                                //Item Number Auto Increese display the label.
                                string rNo = objItem.Item_AutoNo().ToString();
                                if (rNo.Equals("") || rNo == null)
                                {
                                    iNo = 00001;
                                }
                                else
                                {
                                    iNo = int.Parse(rNo);
                                    iNo++;
                                }
                                if (iNo < 10)
                                {
                                    lblItemNo.Text = "0000" + Convert.ToString(iNo);
                                }
                                else if (10 <= iNo && iNo < 100)
                                {
                                    lblItemNo.Text = "000" + Convert.ToString(iNo);
                                }
                                else if (100 <= iNo && iNo < 1000)
                                {
                                    lblItemNo.Text = "00" + Convert.ToString(iNo);
                                }
                                else if (1000 <= iNo && iNo < 10000)
                                {
                                    lblItemNo.Text = "0" + Convert.ToString(iNo);
                                }
                                else
                                {
                                    lblItemNo.Text = Convert.ToString(iNo);
                                }

                                //error provider set default.
                                errorProviderSetClear();

                                // to focus curser
                                txtDescription.Focus();
                            }
                        }
                        else if (btnAdd.Text == "Update")
                        {
                            //UPDATE ITEM LEVEL
                            int           oldQty = 0;
                            SqlCommand    com    = new SqlCommand("SELECT noOfQty FROM tbl_Item WHERE itemNo='" + lblItemNo.Text + "'", ConnectionDB.connection());
                            SqlDataReader dr     = com.ExecuteReader();
                            if (dr.Read() == true)
                            {
                                oldQty  = int.Parse(dr["noOfQty"].ToString());
                                oldQty += int.Parse(txtNoOfQuantity.Text);
                            }

                            objItem.updateItem(lblItemNo.Text, txtDescription.Text, oldQty, Convert.ToDecimal(txt1QtySellPrice.Text));
                            lblSucc.Visible   = true;
                            lblSucc.Text      = "Item updated successfully";
                            lblSucc.ForeColor = Color.LimeGreen;
                            picBxSucc.Visible = true;
                            DialogResult result = MessageBox.Show("Item updated successfuly!.", "UPDATE MESSAGE", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            if (result == DialogResult.OK)
                            {
                                lblNotSucc.Visible   = false;
                                picBxNotSucc.Visible = false;

                                lblSucc.Visible   = false;
                                picBxSucc.Visible = false;

                                //Datagridview for items load method call.
                                loadItemDataForDgv();

                                //Clear all textbox function call.
                                ClearAllText(this);

                                //Item Number Auto Increese display the label.
                                string rNo = objItem.Item_AutoNo().ToString();
                                if (rNo.Equals("") || rNo == null)
                                {
                                    iNo = 00001;
                                }
                                else
                                {
                                    iNo = int.Parse(rNo);
                                    iNo++;
                                }
                                if (iNo < 10)
                                {
                                    lblItemNo.Text = "0000" + Convert.ToString(iNo);
                                }
                                else if (10 <= iNo && iNo < 100)
                                {
                                    lblItemNo.Text = "000" + Convert.ToString(iNo);
                                }
                                else if (100 <= iNo && iNo < 1000)
                                {
                                    lblItemNo.Text = "00" + Convert.ToString(iNo);
                                }
                                else if (1000 <= iNo && iNo < 10000)
                                {
                                    lblItemNo.Text = "0" + Convert.ToString(iNo);
                                }
                                else
                                {
                                    lblItemNo.Text = Convert.ToString(iNo);
                                }

                                //Reset Add button
                                btnAdd.Text      = "Add";
                                btnAdd.TextAlign = ContentAlignment.MiddleCenter;
                                btnAdd.Image     = Properties.Resources.add;

                                //error provider set default.
                                errorProviderSetClear();

                                // to focus curser
                                txtDescription.Focus();
                            }
                        }
                        else
                        {
                            MessageBox.Show("Error");
                        }
                    }
                    else
                    {
                        if (int.Parse(txtNoOfQuantity.Text) == 0)
                        {
                            toolTip_NoOfQuantity.Show("Can not be zero.", txtNoOfQuantity, 0, -75, 2500);
                        }
                        if (decimal.Parse(txt1QtySellPrice.Text) == 0)
                        {
                            toolTip_1QtySellPrice.Show("Can not be zero.", txt1QtySellPrice, 0, -75, 2500);
                        }
                    }
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR MESSAGE", MessageBoxButtons.OK, MessageBoxIcon.Error); }
            #endregion
        }