Example #1
0
        private void datagridRefresh()
        {
            dataGridView1.Rows.Clear();
            dataGridView1.Refresh();

            SqlConnection conn    = LaundryServiceConn.GetConnection();
            SqlDataReader sqlRead = null;
            SqlCommand    scmd    = new SqlCommand(
                " SELECT * FROM clothes", conn);

            scmd.Parameters.Clear();
            conn.Open();
            sqlRead = scmd.ExecuteReader();
            dataGridView1.ReadOnly = true;
            while (sqlRead.Read())
            {
                dataGridView1.Rows.Add(
                    sqlRead["CL_ID"].ToString(),
                    sqlRead["CL_NAME"].ToString(),
                    sqlRead["TYPE_ID"].ToString(),
                    sqlRead["PRICE_ADD"].ToString()
                    );
            }
            conn.Close();
        }
Example #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            int count = 0;

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if (bool.Parse(row.Cells[6].Value.ToString()) == true)
                {
                    String orderId = dataGridView1.Rows[row.Index].Cells[0].Value.ToString();
                    using (SqlConnection conn = LaundryServiceConn.GetConnection())
                    {
                        SqlCommand scmd = new SqlCommand("UPDATE [order] SET [STATUS] = @status WHERE [ORDER_ID] = @orderId", conn);
                        conn.Open();
                        scmd.Parameters.AddWithValue("@status", 1);
                        scmd.Parameters.AddWithValue("@orderId", orderId);

                        scmd.ExecuteNonQuery();
                        conn.Close();
                    }

                    count++;
                }
            }

            showDataGridComplete();
            showDataGridNoComplete();
        }
Example #3
0
        // show data on data grid
        private void showDataGrid()
        {
            SqlConnection conn    = LaundryServiceConn.GetConnection();
            SqlDataReader sqlRead = null;
            SqlCommand    scmd    = new SqlCommand(
                " SELECT a.[PROMO_ID]" +
                " , a.[PROMO_NAME]" +
                " , a.[PROMO_DISCRIPTION]" +
                " , a.[PROMO_PRICE]" +
                " , a.[PROMO_QTY]" +
                " , a.[CL_ID]" +
                " , b.BALANCE" +
                " FROM[dbo].[promotion] a" +
                " RIGHT JOIN[dbo].[promotionCondition] b ON a.[PROMO_ID] = b.PROMO_ID" +
                " where b.CUS_ID = @cusId", conn);

            scmd.Parameters.Clear();
            scmd.Parameters.AddWithValue("@cusId", cusID);
            conn.Open();
            sqlRead = scmd.ExecuteReader();
            dataGPackCus.ReadOnly = true;
            while (sqlRead.Read())
            {
                dataGPackCus.Rows.Add(
                    sqlRead["PROMO_NAME"].ToString(),
                    sqlRead["BALANCE"].ToString()
                    );
            }
            conn.Close();
        }
Example #4
0
        private void frmAddType_Load(object sender, EventArgs e)
        {
            txtTypeID.Enabled   = false;
            txtTypeName.Enabled = false;

            dataGridView1.Rows.Clear();
            dataGridView1.Refresh();
            SqlConnection conn    = LaundryServiceConn.GetConnection();
            SqlDataReader sqlRead = null;
            SqlCommand    scmd    = new SqlCommand(
                " SELECT * FROM type", conn);

            scmd.Parameters.Clear();
            conn.Open();
            sqlRead = scmd.ExecuteReader();
            dataGridView1.ReadOnly = true;
            while (sqlRead.Read())
            {
                dataGridView1.Rows.Add(
                    sqlRead["TYPE_ID"].ToString(),
                    sqlRead["TYPE_NAME"].ToString()

                    );
            }
            conn.Close();
        }
Example #5
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            //DELETE

            DialogResult dialogResult = MessageBox.Show("Do you want to delete " + txtClothesName.Text, "Message", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                SqlConnection conn = LaundryServiceConn.GetConnection();
                SqlCommand    scmd = new SqlCommand("DELETE FROM clothes WHERE [CL_ID]=@clothesID ", conn);
                conn.Open();

                scmd.Parameters.AddWithValue("@clothesID", txtClothesID.Text);
                scmd.ExecuteNonQuery();
                conn.Close();
                MessageBox.Show("Delete successed");

                clear();
                datagridRefresh();
            }
            else if (dialogResult == DialogResult.No)
            {
                //do something else
            }
        }
Example #6
0
        private void showDataGrid()
        {
            dataGridView1.Rows.Clear();
            dataGridView1.Refresh();

            SqlConnection conn    = LaundryServiceConn.GetConnection();
            SqlDataReader sqlRead = null;
            SqlCommand    scmd    = new SqlCommand(
                " SELECT * FROM promotion", conn);

            scmd.Parameters.Clear();
            // scmd.Parameters.AddWithValue("@cusId", cusID);
            conn.Open();
            sqlRead = scmd.ExecuteReader();
            dataGridView1.ReadOnly = true;
            while (sqlRead.Read())
            {
                dataGridView1.Rows.Add(
                    sqlRead["PROMO_ID"].ToString(),
                    sqlRead["PROMO_NAME"].ToString(),
                    sqlRead["PROMO_QTY"].ToString(),
                    sqlRead["PROMO_PRICE"].ToString()
                    );
            }
            conn.Close();
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            
            if (txtPromoName.Text == "" ||
                 txtPromoDisc.Text == "" ||
                 txtPromoPrice.Text == "" ||
                 txtPromoQty.Text == "" ||
                 comboBox1.Text == "")
            {
                MessageBox.Show("Enter all data ,please.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                if(txtPromoID.Text == "")
                {
                    // SAVE
                    SqlConnection conn = LaundryServiceConn.GetConnection();
                    SqlCommand scmd = new SqlCommand("INSERT INTO promotion ([PROMO_NAME],[PROMO_DISCRIPTION],[PROMO_PRICE],[PROMO_QTY],[CL_ID] ) VALUES ( @promoName,@promoDesc,@promoPrice,@promoQty,@clothesID )", conn);
                    conn.Open();

                    scmd.Parameters.AddWithValue("@promoName", txtPromoName.Text);
                    scmd.Parameters.AddWithValue("@promoDesc", txtPromoDisc.Text);
                    scmd.Parameters.AddWithValue("@promoPrice", txtPromoPrice.Text);
                    scmd.Parameters.AddWithValue("@promoQty", txtPromoQty.Text);
                    scmd.Parameters.AddWithValue("@clothesID", comboBox1.SelectedIndex + 1);

                    scmd.ExecuteNonQuery();
                    conn.Close();
                    MessageBox.Show("Insert successed");
                    
                }
                else
                {
                    // UPDATE


                    SqlConnection conn = LaundryServiceConn.GetConnection();
                    SqlCommand scmd = new SqlCommand("UPDATE promotion SET  [PROMO_NAME] = @promoName ,[PROMO_DISCRIPTION]= @promoDesc ,[PROMO_PRICE] = @promoPrice ,[PROMO_QTY] = @promoQty ,[CL_ID]= @clothesID WHERE [PROMO_ID]= @promoID", conn);
                    conn.Open();

                    scmd.Parameters.AddWithValue("@promoID", txtPromoID.Text);
                    scmd.Parameters.AddWithValue("@promoName", txtPromoName.Text);
                    scmd.Parameters.AddWithValue("@promoDesc", txtPromoDisc.Text);
                    scmd.Parameters.AddWithValue("@promoPrice", txtPromoPrice.Text);
                    scmd.Parameters.AddWithValue("@promoQty", txtPromoQty.Text);
                    scmd.Parameters.AddWithValue("@clothesID", comboBox1.SelectedIndex + 1);

                    scmd.ExecuteNonQuery();
                    conn.Close();
                    MessageBox.Show("Update successed");
                }
                clear();
                datagridRefresh();

            }
            
        }
Example #8
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (Double.Parse(txtReceive.Text) < total || String.IsNullOrEmpty(txtReceive.Text))
            {
                MessageBox.Show("Sorry, not enough money.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtReceive.Text = "";
            }
            else
            {
                Double change = Double.Parse(txtReceive.Text) - total;
                txtChange.Text = change.ToString();


                SqlConnection conn = LaundryServiceConn.GetConnection();

                foreach (DataGridViewRow row in dataGridView2.Rows)
                {
                    // String cellProID = row.Cells[0].Value == null ? "" : row.Cells[0].Value.ToString();
                    Int32 cellProID  = row.Cells[0].Value == null ? 0 : Int32.Parse(row.Cells[0].Value.ToString());
                    Int32 cellProQty = row.Cells[2].Value == null ? 0 : Int32.Parse(row.Cells[2].Value.ToString());
                    //String cellProName = row.Cells[1].Value == null ? "" : row.Cells[1].Value.ToString();
                    //Double cellProPrice = row.Cells[2].Value == null ? 0 : Double.Parse(row.Cells[2].Value.ToString());
                    DateTime thisDay = DateTime.Today;



                    string scmd = "INSERT INTO promotionCondition ([PROMO_ID],[CUS_ID],[PRO_DATE_BUY],[QTY_ITEM] ,[BALANCE] ,[TOTAL]) VALUES ( @promoID, @cusID, @proDateBuy, @qty,@balance,@total)";
                    conn.Open();
                    using (SqlCommand cmd = new SqlCommand(scmd, conn))
                    {
                        if (conn.State != ConnectionState.Open)
                        {
                            conn.Open();
                        }

                        cmd.Parameters.AddWithValue("@promoID", cellProID);
                        cmd.Parameters.AddWithValue("@cusID", cusID);
                        cmd.Parameters.AddWithValue("@proDateBuy", thisDay);
                        cmd.Parameters.AddWithValue("@qty", cellProQty);
                        cmd.Parameters.AddWithValue("@balance", cellProQty);
                        cmd.Parameters.AddWithValue("@total", total);

                        cmd.ExecuteNonQuery();
                        conn.Close();
                    }
                }
                MessageBox.Show("successed, thanks.");

                dataGridView2.Rows.Clear();
                dataGridView2.Refresh();
                txtChange.Text  = "";
                txtReceive.Text = "";
                txtTotal.Text   = "";
            }
        }
        private void frmAddPromotion_Load(object sender, EventArgs e)
        {
            txtPromoID.Enabled = false;
            txtPromoName.Enabled = false;
            txtPromoDisc.Enabled = false;
            txtPromoPrice.Enabled = false;
            txtPromoQty.Enabled = false;
            comboBox1.Enabled = false;

            dataGridView1.Rows.Clear();
            dataGridView1.Refresh();

            SqlConnection conn = LaundryServiceConn.GetConnection();
            SqlDataReader sqlRead = null;
            SqlCommand scmd = new SqlCommand(
                " SELECT * FROM promotion", conn);
            scmd.Parameters.Clear();
            conn.Open();
            sqlRead = scmd.ExecuteReader();
            dataGridView1.ReadOnly = true;
            while (sqlRead.Read())
            {
                dataGridView1.Rows.Add(
                    sqlRead["PROMO_ID"].ToString(),
                    sqlRead["PROMO_NAME"].ToString(),
                    sqlRead["PROMO_DISCRIPTION"].ToString(),
                    sqlRead["PROMO_PRICE"].ToString(),
                    sqlRead["PROMO_QTY"].ToString(),
                    sqlRead["CL_ID"].ToString()
                    );
            }
            conn.Close();

            using (SqlConnection con = LaundryServiceConn.GetConnection())
            {
                SqlCommand sqlCmd = new SqlCommand("SELECT * FROM clothes", con);
                con.Open();
                SqlDataReader sqlReader = sqlCmd.ExecuteReader();


                while (sqlReader.Read())
                {
                    comboBox1.Items.Add(new Item(
                        Int32.Parse(sqlReader["CL_ID"].ToString()), sqlReader["CL_NAME"].ToString())
                    );
                }

                sqlReader.Close();
            }
        }
Example #10
0
        private void showDataGridComplete()
        {
            dataGridView2.Rows.Clear();
            dataGridView2.Refresh();

            using (SqlConnection conn = LaundryServiceConn.GetConnection())
            {
                SqlDataReader sqlRead = null;
                SqlCommand    scmd    = new SqlCommand(
                    " SELECT " +
                    "a.[ORDER_ID] , a.[ORDER_NO] ,a.[ORDER_REGISTER_DATE] , a.[ORDER_COMPETE] , a.[ORDER_EXPIRE] , a.[PROMO_ID] , a.[CUS_ID] , a.[CL_ID] , a.[ORDER_QTY] , a.[ORDER_PRICE] , a.[STATUS] , b.[PROMO_NAME] , b.[PROMO_PRICE] " +
                    " FROM[laundryService].[dbo].[order] a " +
                    " LEFT JOIN[laundryService].[dbo].[promotion]  b ON a.PROMO_ID = b.PROMO_ID " +
                    " WHERE a.[STATUS] = 1 AND a.[CUS_ID] = @cusId  " +
                    " ORDER BY a.[STATUS] ASC,a.[ORDER_NO], a.[ORDER_COMPETE] DESC", conn);
                scmd.Parameters.Clear();
                scmd.Parameters.AddWithValue("@cusId", cusID);

                if (ConnectionState.Closed == conn.State)
                {
                    conn.Open();
                }

                sqlRead = scmd.ExecuteReader();
                dataGridView2.ReadOnly = true;

                String orderNo = "";
                while (sqlRead.Read())
                {
                    //orderNo = orderNo.Equals(sqlRead["ORDER_NO"].ToString()) ? "" : sqlRead["ORDER_NO"].ToString();
                    orderNo = sqlRead["ORDER_NO"].ToString();
                    DateTime regisDate    = Convert.ToDateTime(sqlRead["ORDER_REGISTER_DATE"].ToString());
                    DateTime completeDate = Convert.ToDateTime(sqlRead["ORDER_COMPETE"].ToString());

                    dataGridView2.Rows.Add(
                        sqlRead["ORDER_ID"].ToString(),
                        orderNo,
                        sqlRead["ORDER_QTY"].ToString(),
                        sqlRead["ORDER_PRICE"].ToString(),
                        String.Format("{0:d}", regisDate),
                        String.Format("{0:d}", completeDate),
                        sqlRead["STATUS"].ToString() == "1"
                        );
                }

                conn.Close();
                txtOrdComplete.Text = String.Format("{0} {1}", txtOrdComplete.Text, dataGridView2.RowCount);
            }
        }
Example #11
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtClothesName.Text == "" ||
                txtClothesPrice.Text == "" ||
                comboBox1.Text == "")
            {
                MessageBox.Show("Enter all data ,please.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                if (txtClothesID.Text == "")
                {
                    // SAVE
                    SqlConnection conn = LaundryServiceConn.GetConnection();
                    SqlCommand    scmd = new SqlCommand("INSERT INTO clothes ([CL_NAME],[TYPE_ID],[PRICE_ADD]) VALUES ( @clothesName,@typeID,@priceAdd)", conn);
                    conn.Open();

                    scmd.Parameters.AddWithValue("@clothesName", txtClothesName.Text);
                    scmd.Parameters.AddWithValue("@typeID", comboBox1.SelectedIndex + 1);
                    scmd.Parameters.AddWithValue("@priceAdd", txtClothesPrice.Text);

                    scmd.ExecuteNonQuery();
                    conn.Close();
                    MessageBox.Show("Insert successed");
                }
                else
                {
                    // UPDATE


                    SqlConnection conn = LaundryServiceConn.GetConnection();
                    SqlCommand    scmd = new SqlCommand("UPDATE clothes SET  [CL_NAME] = @clothesName ,[TYPE_ID]= @typeID ,[PRICE_ADD] = @priceAdd WHERE [CL_ID]= @clothesID", conn);
                    conn.Open();

                    scmd.Parameters.AddWithValue("@clothesID", txtClothesID.Text);
                    scmd.Parameters.AddWithValue("@clothesName", txtClothesName.Text);
                    scmd.Parameters.AddWithValue("@typeID", comboBox1.SelectedIndex + 1);
                    scmd.Parameters.AddWithValue("@priceAdd", txtClothesPrice.Text);

                    scmd.ExecuteNonQuery();
                    conn.Close();
                    MessageBox.Show("Update successed");
                }
                clear();
                datagridRefresh();
            }
        }
Example #12
0
        private void update()
        {
            using (SqlConnection conn = LaundryServiceConn.GetConnection())
            {
                SqlCommand scmd = new SqlCommand("UPDATE customer SET  [CUS_NAME] =@cusName ,[CUS_PHONE] = @cusPhone,[CUS_ADDRESS] = @cusAddress WHERE [CUS_ID]= @cusId", conn);
                conn.Open();


                scmd.Parameters.AddWithValue("@cusName", txtCusname.Text);
                scmd.Parameters.AddWithValue("@cusPhone", txtCusPhone.Text);
                scmd.Parameters.AddWithValue("@cusAddress", txtCusAddress.Text);
                scmd.Parameters.AddWithValue("@cusId", txtCusId.Text);

                scmd.ExecuteNonQuery();
                conn.Close();
                MessageBox.Show("Update successed");
            }
        }
Example #13
0
        //private void add4()
        //{
        //    int insertID = 0;
        //    string sqlIns = "INSERT INTO  customer ([CUS_NAME],[CUS_PHONE],[CUS_ADDRESS]) VALUES ( @cusName ,@cusPhone,@cusAddress )";
        //    SqlConnection conn = LaundryServiceConn.GetConnection();
        //    conn.Open();
        //    try
        //    {
        //        SqlCommand cmdIns = new SqlCommand(sqlIns, conn);
        //        cmdIns.Parameters.AddWithValue("@cusName", "test");
        //        cmdIns.Parameters.AddWithValue("@cusPhone", "0866954585");
        //        cmdIns.Parameters.AddWithValue("@cusAddress", "dindang");
        //        cmdIns.ExecuteNonQuery();

        //        cmdIns.Parameters.Clear();
        //        cmdIns.CommandText = "SELECT @@IDENTITY";

        //        // Get the last inserted id.
        //        insertID = Convert.ToInt32(cmdIns.ExecuteScalar());

        //        cmdIns.Dispose();
        //        cmdIns = null;
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new Exception(ex.ToString(), ex);
        //    }
        //    finally
        //    {
        //        conn.Close();
        //    }

        //    Console.WriteLine(insertID);
        //}

        //private void add3()
        //{
        //    using (SqlConnection conn = LaundryServiceConn.GetConnection())
        //    {
        //        string saveCus = "INSERT INTO customer ([CUS_NAME],[CUS_PHONE],[CUS_ADDRESS]) VALUES ( @cusName ,@cusPhone,@cusAddress )";

        //        using (SqlCommand querySaveCus = new SqlCommand(saveCus))
        //        {
        //            querySaveCus.Connection = conn;
        //            querySaveCus.Parameters.Add("@cusName", SqlDbType.NVarChar, 255).Value = txtCusName.Text;
        //            querySaveCus.Parameters.Add("@cusPhone", SqlDbType.NVarChar, 20).Value = txtCusPhone.Text;
        //            querySaveCus.Parameters.Add("@cusAddress", SqlDbType.NVarChar, 255).Value = txtCusAddress.Text;
        //            conn.Open();
        //        }
        //    }
        //}

        private void add()
        {
            // connect database & Add data

            SqlConnection conn = LaundryServiceConn.GetConnection();
            SqlCommand    scmd = new SqlCommand("INSERT INTO customer ( [CUS_NAME],[CUS_PHONE],[CUS_ADDRESS] ) VALUES ( @cusName ,@cusPhone,@cusAddress )", conn);

            conn.Open();


            scmd.Parameters.AddWithValue("@cusName", txtCusName.Text);
            scmd.Parameters.AddWithValue("@cusPhone", txtCusPhone.Text);
            scmd.Parameters.AddWithValue("@cusAddress", txtCusAddress.Text);

            scmd.ExecuteNonQuery();
            conn.Close();
            MessageBox.Show("Saved successed");
        }
Example #14
0
        private void comboType()
        {
            // combobox
            using (SqlConnection conn = LaundryServiceConn.GetConnection())
            {
                SqlCommand sqlCmd = new SqlCommand("SELECT * FROM type", conn);
                conn.Open();
                SqlDataReader sqlReader = sqlCmd.ExecuteReader();

                while (sqlReader.Read())
                {
                    comboBox1.Items.Add(new ItemCombo(
                                            Int32.Parse(sqlReader["TYPE_ID"].ToString()), sqlReader["TYPE_NAME"].ToString())
                                        );
                }

                sqlReader.Close();
            }
        }
Example #15
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(txtUsername.Text) || txtUsername.Text == "Username")
            {
                MessageBox.Show("Enter Username ,please.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (String.IsNullOrEmpty(txtPassword.Text) || txtPassword.Text == "Password")
            {
                MessageBox.Show("Enter password ,please.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (count < 3)
            {
                SqlConnection conn = LaundryServiceConn.GetConnection();
                SqlCommand    scmd = new SqlCommand("select count (*) as cnt from [laundryService].[dbo].[user]  where [USERNAME]=@usr and [PASSWORD]=@pwd", conn);
                scmd.Parameters.Clear();
                scmd.Parameters.AddWithValue("@usr", txtUsername.Text);
                scmd.Parameters.AddWithValue("@pwd", txtPassword.Text);
                conn.Open();
                if (scmd.ExecuteScalar().ToString() == "1")
                {
                    MessageBox.Show("Login Success.");
                    frmMain frm = new frmMain();
                    frm.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Login fail.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txtUsername.Clear();
                    txtPassword.Clear();
                    count = count + 1;
                }
                conn.Close();
            }
            else
            {
                MessageBox.Show("Connect Developer", "Validate", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                this.Close();
            }
        }
Example #16
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtTypeName.Text == "")
            {
                MessageBox.Show("Enter all data ,please.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                if (txtTypeID.Text == "")
                {
                    // SAVE
                    SqlConnection conn = LaundryServiceConn.GetConnection();
                    SqlCommand    scmd = new SqlCommand("INSERT INTO type ([TYPE_NAME]) VALUES ( @typeName)", conn);
                    conn.Open();

                    scmd.Parameters.AddWithValue("@typeName", txtTypeName.Text);

                    scmd.ExecuteNonQuery();
                    conn.Close();
                    MessageBox.Show("Insert successed");
                }
                else
                {
                    // UPDATE


                    SqlConnection conn = LaundryServiceConn.GetConnection();
                    SqlCommand    scmd = new SqlCommand("UPDATE type SET  [TYPE_NAME] = @typeName WHERE [TYPE_ID]= @typeID", conn);
                    conn.Open();

                    scmd.Parameters.AddWithValue("@typeID", txtTypeID.Text);
                    scmd.Parameters.AddWithValue("@typeName", txtTypeName.Text);

                    scmd.ExecuteNonQuery();
                    conn.Close();
                    MessageBox.Show("Update successed");
                }
                clear();
                datagridRefresh();
            }
        }
Example #17
0
        private void frmOrder_Load(object sender, EventArgs e)
        {
            SqlConnection conn = LaundryServiceConn.GetConnection();
            SqlCommand    scmd = new SqlCommand("select * from customer where [CUS_ID]=@cusId", conn);

            scmd.Parameters.Clear();
            scmd.Parameters.AddWithValue("@cusId", cusID);
            conn.Open();
            SqlDataReader reader = null;

            reader = scmd.ExecuteReader();
            while (reader.Read())
            {
                lblCusID.Text   = "" + reader["CUS_ID"].ToString();
                lblCusName.Text = "" + reader["CUS_NAME"].ToString();
            }
            conn.Close();

            showDataGrid();
            comboType();
        }
Example #18
0
        private void frmCusInfo_Load(object sender, EventArgs e)
        {
            SqlConnection conn = LaundryServiceConn.GetConnection();
            SqlCommand    scmd = new SqlCommand("select * from customer where [CUS_ID]=@cusId", conn);

            scmd.Parameters.Clear();
            scmd.Parameters.AddWithValue("@cusId", cusID);
            conn.Open();
            SqlDataReader reader = null;

            reader = scmd.ExecuteReader();
            while (reader.Read())
            {
                txtCusId.Text      = "" + reader["CUS_ID"].ToString();
                txtCusname.Text    = reader["CUS_NAME"].ToString();
                txtCusPhone.Text   = reader["CUS_PHONE"].ToString();
                txtCusAddress.Text = reader["CUS_ADDRESS"].ToString();
            }
            conn.Close();
            showDataGrid();
        }
Example #19
0
        private void showDataGrid(int typeId)
        {
            SqlConnection conn    = LaundryServiceConn.GetConnection();
            SqlDataReader sqlRead = null;
            SqlCommand    scmd    = new SqlCommand(
                " SELECT * FROM clothes WHERE [TYPE_ID] = @typeId", conn);

            scmd.Parameters.Clear();
            scmd.Parameters.AddWithValue("@typeId", typeId);
            conn.Open();
            sqlRead = scmd.ExecuteReader();

            dataGridView2.Rows.Clear();
            dataGridView2.Refresh();

            dataGridView2.ReadOnly = true;
            while (sqlRead.Read())
            {
                dataGridView2.Rows.Add(sqlRead["CL_ID"].ToString(), sqlRead["CL_NAME"].ToString(), sqlRead["PRICE_ADD"].ToString());
            }
            conn.Close();
        }
Example #20
0
        private void frmParent_Load(object sender, EventArgs e)
        {
            SqlConnection conn = LaundryServiceConn.GetConnection();
            SqlCommand    scmd = new SqlCommand("select * from customer where [CUS_ID]=@cusId", conn);

            scmd.Parameters.Clear();
            scmd.Parameters.AddWithValue("@cusId", cusID);
            conn.Open();
            SqlDataReader reader = null;

            reader = scmd.ExecuteReader();
            while (reader.Read())
            {
                this.Text = "Customer : " + reader["CUS_NAME"].ToString();
            }
            conn.Close();
            panel1.Controls.Clear();
            frmCusInfo frm = new frmCusInfo(cusID);

            frm.TopLevel = false;
            panel1.Controls.Add(frm);
            frm.Show();
        }
Example #21
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(txtCustomer.Text))
            {
                MessageBox.Show("Enter ID customer,please.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            //seach by phone

            if (checkBoxPhone.Checked == true)
            {
                SqlConnection connn = LaundryServiceConn.GetConnection();
                SqlCommand    scmdd = new SqlCommand("select count (*) as cnt ,[CUS_ID] from [laundryService].[dbo].[customer]  where [CUS_PHONE]=@cusPhone GROUP BY [CUS_ID] ", connn);
                scmdd.Parameters.Clear();
                scmdd.Parameters.AddWithValue("@cusPhone", txtCustomer.Text);
                // scmdd.Parameters.AddWithValue("@cusId", txtCustomer.Text);

                connn.Open();
                if (scmdd.ExecuteScalar().ToString() == "1")
                {
                    String        cusId = null;
                    SqlDataReader sRead = scmdd.ExecuteReader();
                    while (sRead.Read())
                    {
                        //MessageBox.Show(sRead["CUS_ID"].ToString());
                        cusId = sRead["CUS_ID"].ToString();
                    }

                    Program.ACTIVE_CUSTOMER_ID = Int32.Parse(cusId);
                    frmParent frm = new frmParent(cusId);
                    frm.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Invalid ID customer or phone number,please enter again.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txtCustomer.Clear();
                }
                connn.Close();
            }
            else  //seach by ID
            {
                SqlConnection conn = LaundryServiceConn.GetConnection();
                SqlCommand    scmd = new SqlCommand("select count (*) as cnt,[CUS_ID] from [laundryService].[dbo].[customer]  where [CUS_ID]=@cusId GROUP BY [CUS_ID] ", conn);
                scmd.Parameters.Clear();
                scmd.Parameters.AddWithValue("@cusId", txtCustomer.Text);
                conn.Open();
                if (scmd.ExecuteScalar().ToString() == "1")
                {
                    String cusId = txtCustomer.Text;
                    Program.ACTIVE_CUSTOMER_ID = Int32.Parse(txtCustomer.Text);
                    frmParent frm = new frmParent(cusId);
                    frm.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Invalid ID customer or phone number,please enter again.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txtCustomer.Clear();
                }
                conn.Close();
            }
        }
Example #22
0
        private void btnReceive_Click(object sender, EventArgs e)
        {
            if (checkInput() == false)
            {
                MessageBox.Show("Please ,Fill your input");
                return;
            }

            if (Double.Parse(txtReceive.Text) < Double.Parse(txtTotal.Text) || String.IsNullOrEmpty(txtReceive.Text))
            {
                MessageBox.Show("Sorry, not enough money.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtReceive.Text = "";
            }
            else
            {
                // check all value to calculate
                double moneychange = 0.0;
                moneychange    = Double.Parse(txtReceive.Text) - Double.Parse(txtTotal.Text);
                txtChange.Text = moneychange.ToString("F");

                // CHECK PACKAGE BALANCE
                if (checkPackageBalance())
                {
                    // SAVE AND UPDATE BALANCE
                    string orderNo = generateOrderNo();
                    using (SqlConnection conn = LaundryServiceConn.GetConnection())
                    {
                        // date row data from dataGridView1
                        int cntSavedItem = 0;
                        int cntItem      = dataGridView1.RowCount;
                        foreach (DataGridViewRow row in dataGridView1.Rows)
                        {
                            string saveNewOrder = " INSERT INTO [order] " +
                                                  " ([ORDER_NO],[ORDER_REGISTER_DATE],[ORDER_COMPETE],[ORDER_EXPIRE],[PROMO_ID], [CUS_ID] ,[CL_ID] ,[ORDER_QTY] , [ORDER_PRICE] ) " +
                                                  " VALUES " +
                                                  " ( @orderNo, @orderRegisDate, @orderCompleteDate, @orderExpireDate, @promoId, @cusId , @clotherId ,@orderQty , @orderPrice) ";
                            SqlCommand scmd = new SqlCommand(saveNewOrder, conn);

                            if (ConnectionState.Closed == conn.State)
                            {
                                conn.Open();
                            }

                            String clotherId  = row.Cells[0].Value.ToString();
                            String orderPrice = row.Cells[2].Value.ToString();
                            String orderQty   = row.Cells[3].Value.ToString();
                            String promoId    = row.Cells[4].Value.ToString();

                            scmd.Parameters.Clear();
                            scmd.Parameters.AddWithValue("@orderNo", orderNo);
                            scmd.Parameters.AddWithValue("@orderRegisDate", DateTime.Now.Date);
                            scmd.Parameters.AddWithValue("@orderCompleteDate", dateTimePicker2.Value.Date);
                            scmd.Parameters.AddWithValue("@orderExpireDate", DateTime.Now.AddYears(1));
                            scmd.Parameters.AddWithValue("@promoId", promoId);
                            scmd.Parameters.AddWithValue("@cusId", cusID);
                            scmd.Parameters.AddWithValue("@clotherId", clotherId);
                            scmd.Parameters.AddWithValue("@orderQty", orderQty);
                            scmd.Parameters.AddWithValue("@orderPrice", orderPrice);

                            //check ( pakacge id  , promotion id ) is 0 not update promotion balance
                            if (promoId != "0")
                            {
                                // update balance in [promotionCondition]
                                string     upDate = "UPDATE [promotionCondition] SET [BALANCE] = [BALANCE] - @balance WHERE [PROMO_ID] = @promoId AND[CUS_ID] = @cusId ";
                                SqlCommand ucmd   = new SqlCommand(upDate, conn);
                                if (ConnectionState.Closed == conn.State)
                                {
                                    conn.Open();
                                }

                                ucmd.Parameters.Clear();
                                ucmd.Parameters.AddWithValue("@balance", orderQty);
                                ucmd.Parameters.AddWithValue("@promoId", promoId);
                                ucmd.Parameters.AddWithValue("@cusId", cusID);
                                ucmd.ExecuteNonQuery();
                            }

                            cntSavedItem += scmd.ExecuteNonQuery();
                        }


                        if (cntSavedItem == cntItem)
                        {
                            MessageBox.Show("Save complete");
                            dataGridView1.Rows.Clear();
                            dataGridView1.Refresh();
                            txtReceive.Text = "0";
                            txtChange.Text  = "";
                            txtTotal.Text   = "";
                        }
                        else
                        {
                            MessageBox.Show("Save not complete");
                        }

                        conn.Close();
                    }
                }
            }
        }