예제 #1
0
        protected void Addnamestockgroup(object sender, EventArgs e)
        {
            DBConnect dbBranch = new DBConnect("Center");

            //string mcnum = tbaddnum.Text;
            //string mcname = tbaddmachine.Text;
            //string mcmodalname = tbaddmodelmc.Text;
            //string epeaid = ddladdepeamodel.SelectedValue;
            //string mcbobbin = tbaddbobbin.Text;
            //string mcfronbacklength = tbaddfronbacklength.Text;

            // mcname = mcname.ToUpper();
            if (txt_Groupname.Text != "")
            {
                string sqlInsert   = "INSERT Stock_group(group_name) VALUES('" + txt_Groupname.Text + "')";
                bool   checkInsert = dbBranch.DBQuery(sqlInsert);
                if (checkInsert == true)
                {
                    //bool ckhistory = WovenHistory.SaveHistory(ddlBranch.SelectedValue, "ข้อมูลเครื่องทอ", "เพิ่มเครื่องทอ " + mcname, Session["emp_id"].ToString());
                    //if (ckhistory == false)
                    //{
                    //    ShowMessage("ไม่สามารถบันทึกประวัติการทำกิจกรรมได้ กรุณาติดต่อฝ่ายผลิตชิ้นส่วนและอุปกรณ์", MessageType.Warning);
                    //}
                    ShowMessage("บันทึกข้อมูลสำเร็จ", MessageType.Success);
                    ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "redirectJS", "setTimeout(function() { window.location.replace('Add.aspx') }, 3000);", true);
                }
                else
                {
                    ShowMessage("ไม่สามารถบันทึกข้อมูลได้ กรุณาลองใหม่อีกครั้งหรือติดต่อฝ่ายผลิตชิ้นส่วนและอุปกรณ์", MessageType.Error);
                }
            }
            else
            {
                ShowMessage("กรุณากรอกข้อมูลให้ครบ", MessageType.Warning);
            }
        }
        protected void lbtnSaveEdit_Click(object sender, EventArgs e)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
            DBConnect dbBranch = new DBConnect("Center");
            string    setpp_id = "";
            DateTime  datenow  = DateTime.Now;

            foreach (CheckBox item in lstChckBox)
            {
                if (item.Checked == true)
                {
                    setpp_id = item.ID;
                    break;
                }
            }
            if (setpp_id != "")
            {
                if (tbdisbursestcok.Text != "")
                {
                    string sqlstock = "SELECT st.group_name,st.st_id,st.Itemcode,st.Itemname,st.Itemtotal_amount," +
                                      "st.unit,st.storage_number,st.remark FROM [DBRDEngineering].[dbo].[Stock] as st " +
                                      "where st.st_id  ='" + tbstock_id.Text + "'";
                    DataSet dsstock    = dbBranch.DBSelect(sqlstock);
                    int     countstock = dsstock.Tables[0].Rows.Count;
                    if (countstock > 0)
                    {
                        for (int i = 0; i < countstock; i++)
                        {
                            string st_id            = dsstock.Tables[0].Rows[i]["st_id"].ToString();
                            string Itemtotal_amount = dsstock.Tables[0].Rows[i]["Itemtotal_amount"].ToString();

                            // mcname = mcname.ToUpper();
                            if (tbdisbursestcok.Text != "")
                            {
                                int    add_amount = Convert.ToInt32(Itemtotal_amount) - Convert.ToInt32(tbdisbursestcok.Text);
                                string stock_add  = "'" + st_id + "','จ่าย','" + tbdisbursestcok.Text + "','" + add_amount + "','" + Session["Emp_id"].ToString() + "',Getdate()";

                                string sqlInsert   = "INSERT History_stock(st_id,his_nametype,amount,his_totalamount,emp_id,inpdate) VALUES(" + stock_add + ")";
                                bool   checkInsert = dbBranch.DBQuery(sqlInsert);


                                if (checkInsert == true)
                                {
                                    string sqlupdate   = "UPDATE Stock set Itemtotal_amount = '" + add_amount + "' where  st_id = '" + st_id + "'";
                                    bool   checkupdate = dbBranch.DBQuery(sqlupdate);

                                    //bool ckhistory = WovenHistory.SaveHistory(ddlBranch.SelectedValue, "ข้อมูลเครื่องทอ", "เพิ่มเครื่องทอ " + mcname, Session["emp_id"].ToString());
                                    //if (ckhistory == false)
                                    //{
                                    //    ShowMessage("ไม่สามารถบันทึกประวัติการทำกิจกรรมได้ กรุณาติดต่อฝ่ายผลิตชิ้นส่วนและอุปกรณ์", MessageType.Warning);
                                    //}
                                    ShowMessage("บันทึกข้อมูลสำเร็จ", MessageType.Success);

                                    ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "redirectJS", "setTimeout(function() { window.location.replace('Stock.aspx') }, 3000);", true);
                                }
                                else
                                {
                                    ShowMessage("ไม่สามารถบันทึกข้อมูลได้ กรุณาลองใหม่อีกครั้งหรือติดต่อฝ่ายผลิตชิ้นส่วนและอุปกรณ์", MessageType.Error);
                                }
                            }
                            else
                            {
                                ShowMessage("กรุณากรอกข้อมูลให้ครบ", MessageType.Warning);
                            }
                        }
                    }
                }
            }
        }
예제 #3
0
        protected void btAdduser_Click(object sender, EventArgs e)
        {
            DBConnect db = new DBConnect("Center");

            string[] str = new string[8];
            str[0] = TxtEmp_id.Text;
            str[1] = txtFname.Text;
            str[2] = txtLname.Text;
            str[3] = txtPosition.Text;
            str[4] = ddlRole.SelectedItem.Value;
            str[5] = txtUsername.Text;
            str[6] = txtPassword.Text;
            bool checknull = false;

            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == "")
                {
                    checknull = true;
                }
            }
            if (checknull == true)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "alertWornNull();", true);
            }
            else
            {
                DataSet dsEmp  = new DataSet();
                string  sqlEmp = "SELECT * FROM Employee";
                dsEmp = db.DBSelect(sqlEmp);
                int  countEmp = dsEmp.Tables[0].Rows.Count;
                bool checkDup = false;
                for (int j = 0; j < countEmp; j++)
                {
                    if (dsEmp.Tables[0].Rows[j]["Emp_id"].ToString() == str[0])
                    {
                        checkDup = true;
                    }
                }
                if (checkDup == true)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "alertWornDup();", true);
                }
                else
                {
                    String sqlEmpIS = "INSERT INTO Employee([Emp_id],[Fname],[Lname],"
                                      + "[Position],[role_id],[Username],[Password]) "
                                      + "VALUES('" + str[0] + "','" + str[1] + "','"
                                      + str[2] + "','" + str[3] + "','" + str[4] + "','" + str[5]
                                      + "','" + str[6] + "');";
                    bool checkEmpIS = db.DBQuery(sqlEmpIS);
                    if (checkEmpIS == true)
                    {
                        TxtEmp_id.Text   = "";
                        txtFname.Text    = "";
                        txtLname.Text    = "";
                        txtPosition.Text = "";
                        txtUsername.Text = "";
                        txtPassword.Text = "";
                    }
                }
            }
        }
        protected void lbtAddstock_Click(object sender, EventArgs e)
        {
            DBConnect dbBranch       = new DBConnect("Center");
            string    Itemcode       = TxItemcode.Text;
            string    stockgroup     = ddlstockgroup.SelectedValue;
            string    Itemname       = TxItemname.Text;
            string    amount         = Txamount_disburse.Text;
            string    unit           = ddlunit.SelectedValue;
            string    storage_number = Txstorage_number.Text;
            string    remark         = Txremark.Text;


            string sqlstock = "SELECT st.group_name,st.st_id,st.Itemcode,st.Itemname,st.Itemtotal_amount," +
                              "st.unit,st.storage_number,st.remark FROM [DBRDEngineering].[dbo].[Stock] as st " +
                              "where st.st_id  ='" + tbst_id.Text + "'";
            DataSet dsstock    = dbBranch.DBSelect(sqlstock);
            int     countstock = dsstock.Tables[0].Rows.Count;

            if (countstock > 0)
            {
                for (int i = 0; i < countstock; i++)
                {
                    string st_id            = dsstock.Tables[0].Rows[i]["st_id"].ToString();
                    string Itemtotal_amount = dsstock.Tables[0].Rows[i]["Itemtotal_amount"].ToString();

                    // mcname = mcname.ToUpper();
                    if (Txamount_disburse.Text != "" && TxItemname.Text != "" && Convert.ToInt32(amount) < Convert.ToInt32(Itemtotal_amount))
                    {
                        int    add_amount = Convert.ToInt32(Itemtotal_amount) - Convert.ToInt32(amount);
                        string stock_add  = "'" + st_id + "','จ่าย','" + amount + "','" + add_amount + "','" + Session["Emp_id"].ToString() + "',Getdate()";

                        string sqlInsert   = "INSERT History_stock(st_id,his_nametype,amount,his_totalamount,emp_id,inpdate) VALUES(" + stock_add + ")";
                        bool   checkInsert = dbBranch.DBQuery(sqlInsert);


                        if (checkInsert == true)
                        {
                            string sqlupdate   = "UPDATE Stock set Itemtotal_amount = '" + add_amount + "' where  st_id = '" + st_id + "'";
                            bool   checkupdate = dbBranch.DBQuery(sqlupdate);

                            //bool ckhistory = WovenHistory.SaveHistory(ddlBranch.SelectedValue, "ข้อมูลเครื่องทอ", "เพิ่มเครื่องทอ " + mcname, Session["emp_id"].ToString());
                            //if (ckhistory == false)
                            //{
                            //    ShowMessage("ไม่สามารถบันทึกประวัติการทำกิจกรรมได้ กรุณาติดต่อฝ่ายผลิตชิ้นส่วนและอุปกรณ์", MessageType.Warning);
                            //}
                            ShowMessage("บันทึกข้อมูลสำเร็จ", MessageType.Success);

                            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "redirectJS", "setTimeout(function() { window.location.replace('Add.aspx') }, 3000);", true);
                        }
                        else
                        {
                            ShowMessage("ไม่สามารถบันทึกข้อมูลได้ กรุณาลองใหม่อีกครั้งหรือติดต่อฝ่ายผลิตชิ้นส่วนและอุปกรณ์", MessageType.Error);
                        }
                    }
                    else
                    {
                        ShowMessage("กรุณากรอกข้อมูลให้ครบ", MessageType.Warning);
                    }
                }
                //    History_stock
            }
            else
            {
                // mcname = mcname.ToUpper();
                if (Itemname != "" && stockgroup != "" && amount != "")
                {
                    string stock = "'" + stockgroup + "','" + Itemcode + "','" + Itemname + "','" + amount + "','" + unit + "','" + storage_number + "','" + remark + "'";
                    //string script = "alert(\"" + stock + "\");";
                    //ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", script, true);
                    string sqlInsert   = "INSERT Stock(group_name,Itemcode,Itemname,Itemtotal_amount,unit,storage_number,remark) VALUES(" + stock + ")";
                    bool   checkInsert = dbBranch.DBQuery(sqlInsert);
                    if (checkInsert == true)
                    {
                        //bool ckhistory = WovenHistory.SaveHistory(ddlBranch.SelectedValue, "ข้อมูลเครื่องทอ", "เพิ่มเครื่องทอ " + mcname, Session["emp_id"].ToString());
                        //if (ckhistory == false)
                        //{
                        //    ShowMessage("ไม่สามารถบันทึกประวัติการทำกิจกรรมได้ กรุณาติดต่อฝ่ายผลิตชิ้นส่วนและอุปกรณ์", MessageType.Warning);
                        //}
                        ShowMessage("บันทึกข้อมูลสำเร็จ", MessageType.Success);

                        ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "redirectJS", "setTimeout(function() { window.location.replace('Add.aspx') }, 3000);", true);
                    }
                    else
                    {
                        ShowMessage("ไม่สามารถบันทึกข้อมูลได้ กรุณาลองใหม่อีกครั้งหรือติดต่อฝ่ายผลิตชิ้นส่วนและอุปกรณ์", MessageType.Error);
                    }
                }
                else
                {
                    ShowMessage("กรุณากรอกข้อมูลให้ครบ", MessageType.Warning);
                }
            }
        }