public static void LoadList(string proc, ComboBox cb, string valueMember, string displayMember)
        {
            try
            {
                var sql = new SqlConnection(MainClass.connection());

                var cmd = new SqlCommand(proc, sql);

                cmd.CommandType = CommandType.StoredProcedure;

                var da = new SqlDataAdapter(cmd);

                var dt = new DataTable();

                da.Fill(dt);

                cb.DisplayMember = displayMember;

                cb.ValueMember = valueMember;

                cb.DataSource = dt;

                cb.SelectedIndex = -1;
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");
            }
        }
        //Generic load data:
        public static void load_data(string proc, DataGridView dv, ListBox lb)
        {
            try
            {
                SqlConnection sql_con = new SqlConnection(MainClass.connection());

                SqlCommand command = new SqlCommand(proc, sql_con);

                command.CommandType = CommandType.StoredProcedure;

                SqlDataAdapter adapter = new SqlDataAdapter(command);

                DataTable dat = new DataTable();

                adapter.Fill(dat);

                for (int i = 0; i < lb.Items.Count; i++)
                {
                    string colName1 = ((DataGridViewColumn)lb.Items[i]).Name;

                    dv.Columns[colName1].DataPropertyName = dat.Columns[i].ToString();
                }

                dv.DataSource = dat;
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");
            }
        }
        public int insertPurchaseinvoicedetails(Int64 purchID, int prodID, int quan, float price)
        {
            SqlConnection sql_con = new SqlConnection(MainClass.connection());

            try
            {
                SqlCommand cmd = new SqlCommand("st_insertPURCHASEINVOICEDETAILS", sql_con);

                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@purchaseID", purchID);

                cmd.Parameters.AddWithValue("@prodID", prodID);

                cmd.Parameters.AddWithValue("@quant", quan);

                cmd.Parameters.AddWithValue("@total", price);

                sql_con.Open();

                PIDcount = cmd.ExecuteNonQuery();

                sql_con.Close();
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");

                sql_con.Close();
            }

            return(PIDcount);
        }
        public static int insert_update_delete(string proc, Hashtable ht)
        {
            int res = 0;

            try
            {
                SqlConnection sql_con = new SqlConnection(MainClass.connection());

                SqlCommand cmd = new SqlCommand(proc, sql_con);

                cmd.CommandType = CommandType.StoredProcedure;

                foreach (DictionaryEntry item in ht)
                {
                    cmd.Parameters.AddWithValue(item.Key.ToString(), item.Value);
                }
                sql_con.Open();

                //returns an integer which indicates how many rows have been affected
                res = cmd.ExecuteNonQuery();

                sql_con.Close();
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");
            }

            return(res);
        }
        public override void edit_button_Click(object sender, EventArgs e)
        {
            if (name_textBox.Text == "" || phone_number_textBox.Text == "" || email_textBox.Text == "" || password_textBox.Text == "")
            {
                MainClass.ShowMsg("Please enter a record to edit.", "error");

                MainClass.disbale_reset(left_panel_sample2);

                enable_crude_buttons();
            }
            else
            {
                edit = 1;

                temp_name = name_textBox.Text;

                temp_phone = phone_number_textBox.Text;

                temp_password = password_textBox.Text;

                temp_mail = email_textBox.Text;

                temp_status = status_comboBox.Text;

                save_button.Enabled = true;

                add_button.Enabled = false;

                MainClass.enable(left_panel_sample2);
            }
        }
        private void send_code_button_Click(object sender, EventArgs e)
        {
            if (email_address_textBox.Text == "" || current_username_textBox_forgot_password.Text == "")
            {
                MainClass.ShowMsg("Please enter email address.", "error");
            }
            else
            {
                try
                {
                    Random r = new Random();

                    x = r.Next(1, 1000000); //Generating 6-digit verification code

                    SmtpClient cl = new SmtpClient("smtp.gmail.com");

                    cl.Port = 587;

                    cl.Credentials = new System.Net.NetworkCredential("*****@*****.**", "syedkamranali90.");

                    cl.EnableSsl = true;

                    MailMessage mail = new MailMessage("*****@*****.**", email_address_textBox.Text, "VERIFICATION CODE", "Your confirmation code is " + x.ToString() + ".");

                    cl.Send(mail);

                    MessageBox.Show("A code is sent to " + "' " + email_address_textBox.Text + " ' " + ".Enter code to verify it.");
                }
                catch (Exception ex)
                {
                    MainClass.ShowMsg(ex.Message, "Error");
                }
            }
        }
Пример #7
0
        private void usersToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (LoginCodeClass.IsLogged == false)
                {
                    throw new Exception("Login first.");
                }
                else
                {
                    if (LoginCodeClass.isAdmin == true)
                    {
                        users us = new users();

                        MainClass.ShowWindow(us, MDI.ActiveForm);
                    }
                    else
                    {
                        MainClass.ShowMsg("You do not have permission to view users.", "Error");
                    }
                }
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");
            }
        }
        public override void edit_button_Click(object sender, EventArgs e)
        {
            if (supplier_comboBox.SelectedIndex == -1 || product_barcode_textBox_purchase_invoice.Text == "" || product_quantity_textBox.Text == "")
            {
                MainClass.ShowMsg("Please enter/select a record to edit.", "error");

                MainClass.disbale_reset(left_panel_sample2);

                enable_crude_buttons();
            }
            else
            {
                supplier_comboBox.Enabled = false; product_barcode_textBox_purchase_invoice.Enabled = false;

                product_name_textBox_purchase_invoice.Enabled = false;

                delete_button.Enabled = true;

                save_button.Enabled = true;

                add_button.Enabled = false; edit = true;

                per_unit_price_textBox.Enabled = true; product_quantity_textBox.Enabled = true;
            }
        }
Пример #9
0
        private void stockToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (LoginCodeClass.IsLogged == false)
                {
                    throw new Exception("Login first.");
                }
                else
                {
                    if (LoginCodeClass.isAdmin == true)
                    {
                        var st = new STOCK();

                        MainClass.ShowWindow(st, MDI.ActiveForm);
                    }
                    else
                    {
                        MainClass.ShowMsg("You do not have permission to view Purchase Invoice window.", "Error");
                    }
                }
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");
            }
        }
Пример #10
0
        private void check_out_button_Click(object sender, EventArgs e)
        {
            try
            {
                if (sales_dataGridView.Rows.Count > 0)
                {
                    float disc = 0, gross = 0;

                    foreach (DataGridViewRow row in sales_dataGridView.Rows)
                    {
                        disc += Convert.ToSingle(row.Cells["discountGV"].Value);

                        gross += Convert.ToSingle(row.Cells["TotalAmountGV"].Value);
                    }

                    gross_textBox.Text = Math.Round(gross, 0).ToString();

                    discount_textBox.Text = disc.ToString();

                    payment_Type_comboBox.Enabled = true; amount_given_textBox.Enabled = true;
                }
                else
                {
                    gross_textBox.Text = ""; discount_textBox.Text = "";
                }
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");
            }
        }
Пример #11
0
        private string[] loadProductswrtBarcode(string proc, Hashtable ht)
        {
            SqlConnection sql_con = new SqlConnection(MainClass.connection());

            string[] productswrt = new string[6];

            try
            {
                SqlCommand command = new SqlCommand(proc, sql_con);

                command.CommandType = CommandType.StoredProcedure;

                foreach (DictionaryEntry item in ht)
                {
                    command.Parameters.AddWithValue(item.Key.ToString(), item.Value);
                }

                sql_con.Open();

                SqlDataReader dr = command.ExecuteReader();

                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        productswrt[0] = dr[0].ToString(); //prod ID

                        productswrt[1] = dr[1].ToString(); //product

                        productswrt[2] = dr[2].ToString(); //Barcode

                        productswrt[3] = dr[3].ToString(); //Per Unit Price

                        productswrt[4] = dr[4].ToString(); //Per Unit Discount

                        productswrt[5] = dr[5].ToString(); //Total Amount
                    }
                }
                else
                {
                    MainClass.ShowMsg("No products available....", "Error");

                    MainClass.disbale_reset(left_panel_sample2);

                    sql_con.Close();
                }

                sql_con.Close();
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");

                MainClass.disbale_reset(left_panel_sample2);

                sql_con.Close();
            }

            return(productswrt);
        }
        public static void ShowReportSaleReturn(CrystalReportViewer crv, string proc, string param = null, object val1 = null)
        {
            try
            {
                ReportDocument rd;

                SqlConnection sql_con = new SqlConnection(MainClass.connection());

                SqlCommand cmd = new SqlCommand(proc, sql_con);

                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue(param, val1);

                SqlDataAdapter adapter = new SqlDataAdapter(cmd);

                DataTable dat = new DataTable();

                adapter.Fill(dat);

                rd = new ReportDocument();

                rd.Load(Application.StartupPath + "\\Reports\\SalesReturnReport.rpt");

                rd.SetDataSource(dat);

                crv.ReportSource = rd;

                crv.RefreshReport();
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");
            }
        }
        public static object getLASTID(string proc)
        {
            object o = null;

            SqlConnection con = new SqlConnection(MainClass.connection());

            try
            {
                SqlCommand cmd = new SqlCommand(proc, con);

                cmd.CommandType = CommandType.StoredProcedure;

                con.Open();

                o = cmd.ExecuteScalar();

                con.Close();
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");

                con.Close();
            }

            return(o);
        }
Пример #14
0
        public static bool getlogindetails(string proc, Hashtable ht, bool admin)
        {
            bool check = false;

            try
            {
                var sql_con = new SqlConnection(MainClass.connection());

                var cmd = new SqlCommand(proc, sql_con);

                cmd.CommandType = CommandType.StoredProcedure;

                foreach (DictionaryEntry item in ht)
                {
                    cmd.Parameters.AddWithValue(item.Key.ToString(), item.Value);
                }

                sql_con.Open();

                SqlDataReader dr = cmd.ExecuteReader();

                if (dr.HasRows)
                {
                    check = true;

                    while (dr.Read())      //reading data
                    {
                        if (admin == true) //fetch admin username & password
                        {
                            usernameOFadmin = dr["email"].ToString();

                            passwordOFadmin = dr["password"].ToString();
                        }
                        else
                        {
                            USERID = Convert.ToInt32(dr[0].ToString());

                            NAME = dr[1].ToString();

                            USERROLE = dr[2].ToString();
                        }
                    }
                }
                else
                {
                    check = false;

                    MainClass.ShowMsg("Invalid username or password", "Error");
                }
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");

                check = false;
            }

            return(check);
        }
        private void purchaseinvoice_dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex != -1 && e.ColumnIndex != -1)
                {
                    add_button.Enabled = false;

                    if (edit == true) //updating member
                    {
                        save_button.Enabled = true;
                    }
                    else if (edit == false) //adding member
                    {
                        save_button.Enabled = false;
                    }

                    if (e.ColumnIndex == 8)
                    {
                        DataGridViewRow row = purchase_dataGridView.Rows[e.RowIndex];

                        gross_total -= Convert.ToSingle(row.Cells["totalGV"].Value.ToString());

                        gross_total_price_label.Text = gross_total.ToString();

                        purchase_dataGridView.Rows.Remove(row);

                        save_button.Enabled = true;

                        view_button.Enabled = false;
                    }
                    else
                    {
                        DataGridViewRow row = purchase_dataGridView.Rows[e.RowIndex];

                        supplier_comboBox.Text = row.Cells["suppliernameGV"].Value.ToString();

                        product_name_textBox_purchase_invoice.Text = row.Cells["productnameGV"].Value.ToString();

                        product_barcode_textBox_purchase_invoice.Text = row.Cells["productbarcodeGV"].Value.ToString();

                        per_unit_price_textBox.Text = row.Cells["perunitpriceGV"].Value.ToString();

                        product_quantity_textBox.Text = row.Cells["productquantityGV"].Value.ToString();

                        MainClass.disbale(left_panel_sample2);

                        delete_button.Enabled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");

                MainClass.disbale_reset(left_panel_sample2); enable_crude_buttons();
            }
        }
Пример #16
0
        private void login_button_Click(object sender, EventArgs e)
        {
            try
            {
                if (username_textBox.Text != "" && password_textBox.Text != "")
                {
                    Hashtable ht = new Hashtable();

                    ht.Add("@email", username_textBox.Text);

                    ht.Add("@password", password_textBox.Text);

                    if (other_radioButton.Checked == true)
                    {
                        if (LoginCodeClass.getlogindetails("st_getAuthenticationDetails", ht, false))
                        {
                            LoginCodeClass.isAdmin = false; //not admin, common user

                            LoginCodeClass.IsLogged = true;

                            var sal = new SALES();

                            MainClass.ShowWindow(sal, MDI.ActiveForm);
                        }
                    }
                    else if (admin_radioButton.Checked == true)
                    {
                        if (LoginCodeClass.getlogindetails("st_getAuthenticationDetailsFromAUTH", ht, true))
                        {
                            LoginCodeClass.isAdmin = true; //Admin,not common user

                            LoginCodeClass.IsLogged = true;

                            var cat = new CATEGORIES();

                            MainClass.ShowWindow(cat, MDI.ActiveForm);
                        }
                    }
                    else
                    {
                        MainClass.ShowMsg("Please select if you are admin or any other person.", "Error");

                        LoginCodeClass.IsLogged = false;
                    }
                }
                else
                {
                    MainClass.ShowMsg("Please fill all fields.", "Error"); LoginCodeClass.IsLogged = false;
                }
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");

                LoginCodeClass.IsLogged = false;
            }
        }
        private void load_button_Click(object sender, EventArgs e)
        {
            try
            {
                if (sale_ID_textBox.Text != "")
                {
                    if (rg.Match(sale_ID_textBox.Text).Success)
                    {
                        LoadSales();

                        dateTimePicker_sales_return.Value = Convert.ToDateTime(sales_return_dataGridView.Rows[0].Cells["DateGV"].Value);

                        user_textBox.Text = sales_return_dataGridView.Rows[0].Cells["UserIDGV"].Value.ToString();

                        paymentType_textBox.Text = sales_return_dataGridView.Rows[0].Cells["PaymentGV"].Value.ToString();

                        total_amount_label.Text = "Total Amount: " + sales_return_dataGridView.Rows[0].Cells["TotalAmountGV"].Value.ToString();

                        total_discount_label.Text = "Total Discount: " + sales_return_dataGridView.Rows[0].Cells["TotalDiscountGV"].Value.ToString();
                    }
                    else
                    {
                        sale_ID_textBox.Text = "";

                        sale_ID_textBox.Focus();

                        dateTimePicker_sales_return.Value = DateTime.Now;

                        user_textBox.Text = "";

                        paymentType_textBox.Text = "";

                        total_amount_label.Text = "Total Amount: 0";

                        total_discount_label.Text = "Total Discount: 0";
                    }
                }
                else
                {
                    MainClass.ShowMsg("Enter sale ID first.", "Error");

                    dateTimePicker_sales_return.Value = DateTime.Now;

                    user_textBox.Text = "";

                    paymentType_textBox.Text = "";

                    total_amount_label.Text = "Total Amount: 0";

                    total_discount_label.Text = "Total Discount: 0";
                }
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");
            }
        }
        private void save_new_details_button_Click(object sender, EventArgs e)
        {
            if (new_username_textBox.Text == "" || new_password_textBox.Text == "")
            {
                MainClass.ShowMsg("Please enter all details.", "error");
            }
            else
            {
                try
                {
                    sq.Open();

                    SqlCommand cmd = new SqlCommand();

                    cmd.Connection = sq;

                    cmd.CommandText = "st_deleteusers";

                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@id", LoginCodeClass.USERID);

                    cmd.ExecuteNonQuery();

                    cmd.Dispose();

                    SqlCommand newcom = new SqlCommand();

                    string query = "insert into users values(@username,@password)";

                    newcom.Parameters.AddWithValue("@username", new_username_textBox.Text);

                    newcom.Parameters.AddWithValue("@password", new_password_textBox.Text);

                    newcom.CommandText = query;

                    newcom.ExecuteNonQuery();

                    MainClass.ShowMsg("Username and password changed successfully.", "success");

                    sq.Close();

                    disable_clear();

                    newcom.Dispose();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "success", MessageBoxButtons.OK, MessageBoxIcon.Error);;

                    sq.Close();

                    disable_clear();
                }
            }
        }
        private void products_dataGridView_CellClick_1(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex != -1)
                {
                    add_button.Enabled = false;

                    if (edit == 1) //updating member
                    {
                        save_button.Enabled = true;
                    }
                    else if (edit == 0) //adding member
                    {
                        save_button.Enabled = false;
                    }

                    DataGridViewRow row = products_dataGridView.Rows[e.RowIndex];

                    productID = Convert.ToInt32(row.Cells["productidGV"].Value.ToString());

                    product_name_textBox.Text = row.Cells["ProductnameGV"].Value.ToString();

                    barcode_textBox.Text = row.Cells["ProductbarcodeGV"].Value.ToString();

                    if (row.Cells["ExpirydateGV"].FormattedValue.ToString() == "")
                    {
                        dateTimePicker_expiry_products.Value = DateTime.Now;
                    }
                    else
                    {
                        dateTimePicker_expiry_products.Value = Convert.ToDateTime(row.Cells["ExpirydateGV"].Value.ToString());
                    }

                    categories_comboBox.SelectedValue = row.Cells["categoryIDGV"].Value.ToString();

                    disable();

                    delete_button.Enabled = true;

                    edit_button.Enabled = true;

                    save_button.Enabled = false;

                    cancel_button.Enabled = true;

                    view_button.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");
            }
        }
        private void verify_code_button_Click(object sender, EventArgs e)
        {
            if (x.ToString() == verification_code_textBox.Text)
            {
                disabled_new_details_label.Text = "ENABLED";

                new_details_panel.Enabled = true;
            }
            else
            {
                MainClass.ShowMsg("Incorrect code.", "Error");
            }
        }
        private void users_dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex != -1)
                {
                    add_button.Enabled = false;

                    if (edit == 1) //updating member
                    {
                        save_button.Enabled = true;
                    }
                    else if (edit == 0) //adding member
                    {
                        save_button.Enabled = false;
                    }

                    DataGridViewRow row = users_dataGridView.Rows[e.RowIndex];

                    USERID = Convert.ToInt32(row.Cells["useridGV"].Value.ToString());

                    name_textBox.Text = row.Cells["nameGV"].Value.ToString();

                    email_textBox.Text = row.Cells["emailGV"].Value.ToString();

                    password_textBox.Text = row.Cells["passwordGV"].Value.ToString();

                    phone_number_textBox.Text = row.Cells["phonenumberGV"].Value.ToString();

                    status_comboBox.SelectedItem = row.Cells["statusGV"].Value.ToString();

                    role_textBox.Text = row.Cells["roleGV"].Value.ToString();

                    MainClass.disbale(left_panel_sample2);

                    delete_button.Enabled = true;

                    edit_button.Enabled = true;

                    save_button.Enabled = false;

                    cancel_button.Enabled = true;

                    view_button.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");
            }
        }
        private void product_quantity_textBox_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (product_quantity_textBox.Text != "")
                {
                    if (rg.Match(product_quantity_textBox.Text).Success)
                    {
                        float quan = 0, price = 0, total = 0;

                        if (product_quantity_textBox.Text == "" || per_unit_price_textBox.Text == "")
                        {
                            throw new Exception("No fields can be empty.Please enter details in an order");
                        }
                        else
                        {
                            quan = Convert.ToSingle(product_quantity_textBox.Text);

                            price = Convert.ToSingle(per_unit_price_textBox.Text);

                            total = quan * price;

                            total_amount_label.Text = total.ToString("############.##");
                        }
                    }
                    else
                    {
                        product_quantity_textBox.SelectAll();
                    }
                }
                else
                {
                    total_amount_label.Text = "0.00";
                }
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");

                product_barcode_textBox_purchase_invoice.Text = "";

                product_name_textBox_purchase_invoice.Text = "";

                per_unit_price_textBox.Text = ""; product_quantity_textBox.Text = "";
            }
        }
        public override void delete_button_Click(object sender, EventArgs e)
        {
            if (supplier_comboBox.SelectedIndex == -1 || product_barcode_textBox_purchase_invoice.Text == "" || product_quantity_textBox.Text == "")
            {
                MainClass.ShowMsg("Please enter/select a record to delete.", "error");

                MainClass.disbale_reset(left_panel_sample2);

                enable_crude_buttons();
            }
            else
            {
                try
                {
                    DialogResult ans = MessageBox.Show("Are you sure you want to delete current record.", "CONFIRM?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (ans == DialogResult.Yes)
                    {
                        purchase_dataGridView.Rows.Remove(purchase_dataGridView.CurrentRow);

                        MainClass.disbale_reset(left_panel_sample2);

                        gross_total = 0;

                        foreach (DataGridViewRow row in purchase_dataGridView.Rows)
                        {
                            gross_total += Convert.ToSingle(row.Cells["totalGV"].Value);

                            gross_total_price_label.Text = gross_total.ToString();
                        }

                        MainClass.disbale_reset(left_panel_sample2);

                        enable_crude_buttons();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);

                    MainClass.disbale_reset(left_panel_sample2);

                    enable_crude_buttons();
                }
            }
        }
        public Int64 InsertPurchaseinvoice(DateTime date, int doneBy, int suppID)
        {
            SqlConnection sql_con = new SqlConnection(MainClass.connection());

            try
            {
                using (TransactionScope sc = new TransactionScope())
                {
                    var cmd = new SqlCommand("st_insertPURCHASEINVOICE", sql_con);

                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@date", date);

                    cmd.Parameters.AddWithValue("@doneby", doneBy);

                    cmd.Parameters.AddWithValue("@suppID", suppID);

                    sql_con.Open();

                    cmd.ExecuteNonQuery();

                    sql_con.Close();

                    SqlCommand cmd1 = new SqlCommand("st_getLASTPURCHASEINVOICEID", sql_con);

                    cmd1.CommandType = CommandType.StoredProcedure;

                    sql_con.Open();

                    purchaseinvoiceIDSQLTASKS = Convert.ToInt64(cmd1.ExecuteScalar());

                    sql_con.Close();

                    sc.Complete();
                }
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");

                sql_con.Close();
            }

            return(purchaseinvoiceIDSQLTASKS);
        }
        private void product_barcode_textBox_purchase_invoice_Validating(object sender, CancelEventArgs e)
        {
            try
            {
                Hashtable ht = new Hashtable();

                ht.Add("@barcode", product_barcode_textBox_purchase_invoice.Text);

                string[] productswrt = new string[3];

                if (product_barcode_textBox_purchase_invoice.Text != "")
                {
                    productswrt = loadProductswrtBarcode("st_getPRODUCTbyBarcodeForPurchaseInvoice", ht);

                    productID = Convert.ToInt32(productswrt[0]);

                    productNAME = productswrt[1];

                    product_name_textBox_purchase_invoice.Text = productNAME;

                    productBARCODE = productswrt[2];

                    product_name_textBox_purchase_invoice.Enabled = false;

                    if (productBARCODE != null)
                    {
                        per_unit_price_textBox.Focus();
                    }
                }
                else
                {
                    productID = 0;

                    product_name_textBox_purchase_invoice.Text = "";

                    per_unit_price_textBox.Text = "";

                    Array.Clear(productswrt, 0, productswrt.Length);
                }
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");
            }
        }
Пример #26
0
 private void amount_given_textBox_TextChanged(object sender, EventArgs e)
 {
     try
     {
         if (amount_given_textBox.Text != "")
         {
             if (!rg.Match(amount_given_textBox.Text).Success)
             {
                 amount_given_textBox.Text = ""; amount_given_textBox.Focus();
             }
         }
         else
         {
             change_to_give_textBox.Text = "";
         }
     }
     catch (Exception ex) { MainClass.ShowMsg(ex.Message, "Error"); }
 }
Пример #27
0
        private void product_pricing_dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex != -1 && e.ColumnIndex != -1)
                {
                    DataGridViewRow row = product_pricing_dataGridView.Rows[e.RowIndex];

                    if (row.Cells["profitmarginGV"].Value != null && rg.Match(row.Cells["profitmarginGV"].Value.ToString()).Success)
                    {
                        float perunitPrice = (Convert.ToSingle(row.Cells["PerUnitPriceGV"].Value.ToString()));

                        float profitmargin = (Convert.ToSingle(row.Cells["profitmarginGV"].Value.ToString()) / 100);

                        float amountTOincrease = profitmargin * perunitPrice;

                        float finalsellingprice = perunitPrice + amountTOincrease;

                        float discount;

                        if (row.Cells["discountGV"].Value != null && rg.Match(row.Cells["discountGV"].Value.ToString()).Success)
                        {
                            discount = finalsellingprice * (Convert.ToSingle(row.Cells["discountGV"].Value.ToString()) / 100);
                        }
                        else
                        {
                            discount = 0;
                        }

                        row.Cells["finalpriceGV"].Value = finalsellingprice - discount;
                    }
                    else
                    {
                        row.Cells["finalpriceGV"].Value   = null;
                        row.Cells["profitmarginGV"].Value = null;
                        row.Cells["discountGV"].Value     = null;
                    }
                }
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");
            }
        }
        public static void LoadListModifiedHashTable(string proc, ComboBox cb, string valueMember, string displayMember, Hashtable ht)
        {
            try
            {
                cb.DataSource = null;

                cb.Items.Clear();

                SqlConnection sql = new SqlConnection(MainClass.connection());

                SqlCommand cmd = new SqlCommand(proc, sql);

                cmd.CommandType = CommandType.StoredProcedure;

                foreach (DictionaryEntry item in ht)
                {
                    cmd.Parameters.AddWithValue(item.Key.ToString(), item.Value);
                }

                SqlDataAdapter da = new SqlDataAdapter(cmd);

                DataTable dt = new DataTable();

                da.Fill(dt);

                DataRow dr = dt.NewRow();

                dr.ItemArray = new object[] { 0, "Select..." };

                dt.Rows.InsertAt(dr, 0);

                cb.DisplayMember = displayMember;

                cb.ValueMember = valueMember;

                cb.DataSource = dt;

                cb.SelectedIndex = -1;
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");
            }
        }
        public static double[] SaleInvoiceAmounts(string proc, Hashtable ht)
        {
            double[] arr = new double[3];

            try
            {
                SqlConnection sql_con = new SqlConnection(MainClass.connection());

                SqlCommand cmd = new SqlCommand(proc, sql_con);

                cmd.CommandType = CommandType.StoredProcedure;

                foreach (DictionaryEntry item in ht)
                {
                    cmd.Parameters.AddWithValue(item.Key.ToString(), item.Value);
                }

                sql_con.Open();

                SqlDataReader dr = cmd.ExecuteReader();

                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        arr[0] = Convert.ToDouble(dr["Total Amount"].ToString());

                        arr[1] = Convert.ToDouble(dr["Amount Paid"].ToString());

                        arr[2] = Convert.ToDouble(dr["Remaining Amount"].ToString());
                    }
                }

                sql_con.Close();
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");
            }

            return(arr);
        }
        public static double[] LoadLastBalance(string proc, Hashtable ht)
        {
            SqlConnection sql_con = new SqlConnection(MainClass.connection());

            double[] amounts = new double[2];

            try
            {
                SqlCommand cmd = new SqlCommand(proc, sql_con);

                cmd.CommandType = CommandType.StoredProcedure;

                foreach (DictionaryEntry item in ht)
                {
                    cmd.Parameters.AddWithValue(item.Key.ToString(), item.Value);
                }

                sql_con.Open();

                SqlDataReader dr = cmd.ExecuteReader();

                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        amounts[0] = Convert.ToDouble(dr[0].ToString());

                        amounts[1] = Convert.ToDouble(dr[1].ToString());
                    }
                }

                sql_con.Close();
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");

                sql_con.Close();
            }

            return(amounts);
        }