Example #1
0
        //Document
        public static string fncGenDocNo(string lvDocCode)
        {
            #region //Connect Database
            SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PSConnection"].ToString());
            SqlCommand    cmd = new SqlCommand();
            SqlDataReader dr;
            #endregion

            string lvReturn = "";

            cmd.Connection = con;
            con.Open();
            cmd.CommandText = "SELECT * FROM SysDocNo WHERE S_MCode = '" + lvDocCode + "' ";
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    //GenDoc
                    string lvShort   = dr["S_ShortCode"].ToString();
                    int    lvYearChk = DateTime.Now.Year;
                    if (lvYearChk < 2500)
                    {
                        lvYearChk += 543;
                    }
                    string lvYear    = (lvYearChk - 2500).ToString();
                    int    lvMonth   = DateTime.Now.Month;
                    int    lvDay     = DateTime.Now.Day;
                    string lvSection = "121";
                    int    lvRunDoc  = Gstr.fncToInt(dr["S_RunNo"].ToString());

                    string lvDocID = "";
                    if (dr["S_TypeGen"].ToString() == "YYMMDept")
                    {
                        lvDocID = lvShort + lvYear.ToString() + lvMonth.ToString("00") + lvSection + lvRunDoc.ToString(dr["S_Format"].ToString());
                    }
                    else if (dr["S_TypeGen"].ToString() == "YYMMdd")
                    {
                        lvDocID = lvShort + lvYear.ToString() + lvMonth.ToString("00") + lvDay.ToString("00") + lvRunDoc.ToString(dr["S_Format"].ToString());
                    }
                    else
                    {
                        lvDocID = lvShort + lvRunDoc.ToString(dr["S_Format"].ToString());
                    }

                    lvReturn = lvDocID;
                }
            }
            else
            {
                lvReturn = "";
            }

            dr.Close();
            con.Close();

            return(lvReturn);
        }
Example #2
0
        public void LoadAssetData(bool lvShow)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                btnIn.Enabled       = false;
                btnOut.Enabled      = false;
                btnBorrow.Enabled   = false;
                btnNoteBook.Enabled = false;

                string lvSQL = "Select * from Asset Where Asset_ID2 >= '" + txtSearchS.Text + "' And Asset_ID2 <= '" + txtSearchE.Text + "' ";

                DataTable DT = new DataTable();
                DT = GsysSQL.fncGetQueryData(lvSQL, DT);

                int lvNumRow = DT.Rows.Count;
                sp3.ActiveSheet.RowCount = lvNumRow;

                progressBar1.Maximum = lvNumRow;
                progressBar1.Value   = 0;
                pnStatus.Visible     = true;

                for (int i = 0; i < lvNumRow; i++)
                {
                    sp3.ActiveSheet.Cells[i, 0].Text = DT.Rows[i]["Asset_ID2"].ToString();
                    sp3.ActiveSheet.Cells[i, 1].Text = DT.Rows[i]["Asset_Faction"].ToString();
                    sp3.ActiveSheet.Cells[i, 2].Text = Gstr.fncChangeSDate(DT.Rows[i]["Asset_ResiveDate"].ToString());
                    sp3.ActiveSheet.Cells[i, 3].Text = DT.Rows[i]["Asset_Name"].ToString();

                    progressBar1.Value += 1;
                    Application.DoEvents();
                }

                pnStatus.Visible = false;
                DT.Dispose();

                btnIn.Enabled       = true;
                btnOut.Enabled      = true;
                btnBorrow.Enabled   = true;
                btnNoteBook.Enabled = true;

                if (lvShow)
                {
                    tabControl1.SelectedIndex = 3;
                }

                this.Cursor = Cursors.Default;
            }
            catch
            {
                Application.Restart();
            }
        }
Example #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (pvMode == "IN")
            {
                #region รับเข้า
                //เช็คข้อมูล
                if (txtDate.EditValue == "")
                {
                    MessageBox.Show("กรุณาระบุ วันที่", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtDate.Focus();
                    return;
                }
                else if (txtID.Text == "")
                {
                    MessageBox.Show("กรุณาระบุ รหัส", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtID.Focus();
                    return;
                }
                else if (Gstr.fncToInt(txtAmount.Text) <= 0)
                {
                    MessageBox.Show("กรุณาระบุ จำนวน", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtAmount.Focus();
                    return;
                }
                else if (txtUserResive.Text == "")
                {
                    MessageBox.Show("กรุณาระบุ ผู้รับ", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtUserResive.Focus();
                    return;
                }

                string lvType       = "R";
                string lvDate       = Gstr.fncChangeTDate(txtDate.EditValue.ToString());
                string lvItemID     = Gstr.fncGetDataCode(txtID.Text, ";");
                string lvAmount     = txtAmount.Text;
                string lvBal        = GsysSQL.fncFindBal(lvItemID);
                string lvUserResive = txtUserResive.Text;
                string lvUserPay    = "";
                string lvRemark     = txtRemark.Text;

                string lvSQL     = "";
                string lvResault = "";

                int lvTotalBal = Gstr.fncToInt(lvBal) + Gstr.fncToInt(lvAmount);
                if (lvTotalBal < 0)
                {
                    lvTotalBal = 0;
                }

                //Update ยอด
                lvSQL     = "Update SysITEM_Stock set Item_Amount = '" + lvTotalBal + "' Where Item_ID = '" + lvItemID + "' ";
                lvResault = GsysSQL.fncExecuteQueryData(lvSQL);

                //Insert เคลื่อนไหว
                lvSQL     = "Insert into Inv_Moving (M_Type, M_Date, M_ItemID, M_AmountR, M_AmountP, M_AmountBal, M_UserResive, M_UserPay, M_Remark) ";
                lvSQL    += "values('" + lvType + "', '" + lvDate + "', '" + lvItemID + "', '" + lvAmount + "', '', '" + lvTotalBal + "', '" + lvUserResive + "', '" + lvUserPay + "', '" + lvRemark + "')";
                lvResault = GsysSQL.fncExecuteQueryData(lvSQL);

                if (lvResault == "Success")
                {
                    GVar.gvSave = true;
                    MessageBox.Show("บันทึกข้อมูลเรียบร้อย", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
                #endregion
            }
            else if (pvMode == "Borrow")
            {
                #region ยืมของ
                //เช็คข้อมูล
                if (txtDate.EditValue == "")
                {
                    MessageBox.Show("กรุณาระบุ วันที่", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtDate.Focus();
                    return;
                }
                else if (txtID.Text == "")
                {
                    MessageBox.Show("กรุณาระบุ รหัส", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtID.Focus();
                    return;
                }
                else if (Gstr.fncToInt(txtAmount.Text) <= 0)
                {
                    MessageBox.Show("กรุณาระบุ จำนวน", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtAmount.Focus();
                    return;
                }
                else if (txtUserResive.Text == "")
                {
                    MessageBox.Show("กรุณาระบุ ผู้ขอเบิก", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtUserResive.Focus();
                    return;
                }
                else if (txtUserPay.Text == "")
                {
                    MessageBox.Show("กรุณาระบุ ผู้จ่าย", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtUserResive.Focus();
                    return;
                }

                string lvType       = "B";
                string lvDate       = Gstr.fncChangeTDate(txtDate.EditValue.ToString());
                string lvItemID     = Gstr.fncGetDataCode(txtID.Text, ";");
                string lvAmount     = txtAmount.Text;
                string lvBal        = GsysSQL.fncFindBal(lvItemID);
                string lvUserResive = Gstr.fncGetDataCode(txtUserResive.Text, ";");
                string lvUserPay    = Gstr.fncGetDataCode(txtUserPay.Text, ";");
                string lvRemark     = txtRemark.Text;

                string lvSQL     = "";
                string lvResault = "";

                int lvTotalBal = Gstr.fncToInt(lvBal) - Gstr.fncToInt(lvAmount);
                int lvMinStock = Gstr.fncToInt(GsysSQL.fncFindMinStock(lvItemID));

                string lvOption = "";
                if (ChkMouse.Checked)
                {
                    lvOption += "Mouse ";
                }
                if (ChkMousePad.Checked)
                {
                    lvOption += "MousePad ";
                }
                if (ChkAdapter.Checked)
                {
                    lvOption += "Adapter ";
                }
                if (ChkPointer.Checked)
                {
                    lvOption += "Pointer ";
                }
                if (ChkFlashDrive.Checked)
                {
                    lvOption += "FlashDrive ";
                }

                lvOption = lvOption.Replace(' ', ',');

                ////ห้ามจ่ายติดลบ
                //if (lvTotalBal < 0)
                //{
                //    MessageBox.Show("จำนวนคงเหลือไม่เพียงพอ", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //    txtAmount.Focus();
                //    return;
                //}

                //if (lvTotalBal < 0) lvTotalBal = 0;

                ////Update ยอด
                //lvSQL = "Update SysITEM_Stock set Item_Amount = '" + lvTotalBal + "' Where Item_ID = '" + lvItemID + "' ";
                //lvResault = GsysSQL.fncExecuteQueryData(lvSQL);

                //Insert เคลื่อนไหว
                lvSQL     = "Insert into Inv_Moving (M_Type, M_Date, M_ItemID, M_AmountR, M_AmountP, M_AmountBal, M_UserResive, M_UserPay, M_Remark, M_Option) ";
                lvSQL    += "values('" + lvType + "', '" + lvDate + "', '" + lvItemID + "', '', '" + lvAmount + "', '" + lvTotalBal + "', '" + lvUserResive + "', '" + lvUserPay + "', '" + lvRemark + "', '" + lvOption + "')";
                lvResault = GsysSQL.fncExecuteQueryData(lvSQL);

                if (lvResault == "Success")
                {
                    GVar.gvSave = true;
                    string lvUserName = GsysSQL.fncFindFullEmpName(lvUserResive);
                    string lvItemName = GsysSQL.fncFindItemName(lvItemID);
                    string lvItemUnit = GsysSQL.fncFindItemUnit(lvItemID);
                    if (lvItemName == "อื่นๆ")
                    {
                        lvItemName = lvRemark;
                    }
                    string lvMessage = "แจ้งเตือน " + lvUserName + " ได้ยืม  " + lvItemName + "  จำนวน " + lvAmount + " " + lvItemUnit + " " + lvRemark;
                    lineNotify(lvMessage);

                    MessageBox.Show("บันทึกข้อมูลเรียบร้อย", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
                #endregion
            }
            else
            {
                #region เบิกจ่าย
                //เช็คข้อมูล
                if (txtDate.EditValue == "")
                {
                    MessageBox.Show("กรุณาระบุ วันที่", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtDate.Focus();
                    return;
                }
                else if (txtID.Text == "")
                {
                    MessageBox.Show("กรุณาระบุ รหัส", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtID.Focus();
                    return;
                }
                else if (Gstr.fncToInt(txtAmount.Text) <= 0)
                {
                    MessageBox.Show("กรุณาระบุ จำนวน", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtAmount.Focus();
                    return;
                }
                else if (txtUserResive.Text == "")
                {
                    MessageBox.Show("กรุณาระบุ ผู้ขอเบิก", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtUserResive.Focus();
                    return;
                }
                else if (txtUserPay.Text == "")
                {
                    MessageBox.Show("กรุณาระบุ ผู้จ่าย", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtUserResive.Focus();
                    return;
                }

                string lvType       = "P";
                string lvDate       = Gstr.fncChangeTDate(txtDate.EditValue.ToString());
                string lvItemID     = Gstr.fncGetDataCode(txtID.Text, ";");
                string lvAmount     = txtAmount.Text;
                string lvBal        = GsysSQL.fncFindBal(lvItemID);
                string lvUserResive = Gstr.fncGetDataCode(txtUserResive.Text, ";");
                string lvUserPay    = Gstr.fncGetDataCode(txtUserPay.Text, ";");
                string lvRemark     = txtRemark.Text;

                string lvSQL     = "";
                string lvResault = "";

                int lvTotalBal = Gstr.fncToInt(lvBal) - Gstr.fncToInt(lvAmount);
                int lvMinStock = Gstr.fncToInt(GsysSQL.fncFindMinStock(lvItemID));

                //ห้ามจ่ายติดลบ
                if (lvTotalBal < 0)
                {
                    MessageBox.Show("จำนวนคงเหลือไม่เพียงพอ", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtAmount.Focus();
                    return;
                }

                if (lvTotalBal < 0)
                {
                    lvTotalBal = 0;
                }

                //Update ยอด
                lvSQL     = "Update SysITEM_Stock set Item_Amount = '" + lvTotalBal + "' Where Item_ID = '" + lvItemID + "' ";
                lvResault = GsysSQL.fncExecuteQueryData(lvSQL);

                //Insert เคลื่อนไหว
                lvSQL     = "Insert into Inv_Moving (M_Type, M_Date, M_ItemID, M_AmountR, M_AmountP, M_AmountBal, M_UserResive, M_UserPay, M_Remark) ";
                lvSQL    += "values('" + lvType + "', '" + lvDate + "', '" + lvItemID + "', '', '" + lvAmount + "', '" + lvTotalBal + "', '" + lvUserResive + "', '" + lvUserPay + "', '" + lvRemark + "')";
                lvResault = GsysSQL.fncExecuteQueryData(lvSQL);

                if (lvResault == "Success")
                {
                    if (lvTotalBal <= lvMinStock && lvMinStock != 0)
                    {
                        string lvMessage = "แจ้งเตือน " + txtName.Text + " ใกล้หมดแล้ว ยอดคงเหลือปัจุบัน คือ " + lvTotalBal;
                        lineNotify(lvMessage);
                    }
                    else
                    {
                        string lvEmpName  = GsysSQL.fncFindFullEmpName(lvUserResive);
                        string lvItemName = GsysSQL.fncFindItemName(lvItemID);
                        string lvItemUnit = GsysSQL.fncFindItemUnit(lvItemID);

                        string lvMessage = "แจ้งเตือน " + lvEmpName + " ได้เบิก " + lvItemName + " จำนวน " + lvAmount + " " + lvItemUnit;
                        lineNotify(lvMessage);
                    }

                    MessageBox.Show("บันทึกข้อมูลเรียบร้อย", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
                #endregion
            }
        }
Example #4
0
        public void lvLoadItem(bool lvShow)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                btnreg.Enabled      = false;
                btnIn.Enabled       = false;
                btnOut.Enabled      = false;
                btnBorrow.Enabled   = false;
                btnNoteBook.Enabled = false;

                string lvSQL = "Select Top 50 * from Inv_Moving Where M_Type in ('R','P') Order by M_Pk Desc ";

                DataTable DT = new DataTable();
                DT = GsysSQL.fncGetQueryData(lvSQL, DT);

                int lvNumRow = DT.Rows.Count;
                sp1.ActiveSheet.RowCount = lvNumRow;

                progressBar1.Maximum = lvNumRow;
                progressBar1.Value   = 0;
                pnStatus.Visible     = true;

                for (int i = 0; i < lvNumRow; i++)
                {
                    sp1.ActiveSheet.Cells[i, 0].Text = Gstr.fncChangeSDate(DT.Rows[i]["M_Date"].ToString());
                    sp1.ActiveSheet.Cells[i, 1].Text = DT.Rows[i]["M_ItemID"].ToString();
                    sp1.ActiveSheet.Cells[i, 2].Text = GsysSQL.fncFindItemName(DT.Rows[i]["M_ItemID"].ToString());
                    sp1.ActiveSheet.Cells[i, 3].Text = DT.Rows[i]["M_AmountR"].ToString();
                    sp1.ActiveSheet.Cells[i, 4].Text = DT.Rows[i]["M_AmountP"].ToString();
                    sp1.ActiveSheet.Cells[i, 5].Text = DT.Rows[i]["M_AmountBal"].ToString();
                    sp1.ActiveSheet.Cells[i, 6].Text = GsysSQL.fncFindEmpName(DT.Rows[i]["M_UserResive"].ToString());
                    sp1.ActiveSheet.Cells[i, 7].Text = GsysSQL.fncFindEmpName(DT.Rows[i]["M_UserPay"].ToString());
                    sp1.ActiveSheet.Cells[i, 8].Text = GsysSQL.fncFindEmpName(DT.Rows[i]["M_Remark"].ToString());

                    progressBar1.Value += 1;
                    Application.DoEvents();
                }

                pnStatus.Visible = false;
                DT.Dispose();

                btnreg.Enabled      = true;
                btnIn.Enabled       = true;
                btnOut.Enabled      = true;
                btnBorrow.Enabled   = true;
                btnNoteBook.Enabled = true;

                if (lvShow)
                {
                    tabControl1.SelectedIndex = 0;
                }

                this.Cursor = Cursors.Default;
            }
            catch
            {
                Application.Restart();
            }
        }