Esempio n. 1
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            //    NPDanhsachnhavantai
            string connection_string = Utils.getConnectionstr();

            LinqtoSQLDataContext dc = new LinqtoSQLDataContext(connection_string);

            //     var rs1 = Model.MKT.danhsachkhoMKT(dc);

            //  string storeright =    Model.Username.getmaquyenkho();



            var rs1 = Model.MKT.danhsachkhoMKTRight(dc);

            Viewtable viewtbl = new Viewtable(rs1, dc, "DANH SÁCH STORE rIGHT", 15, "MKT_kHORIGHT");// mã 15 là danh sach STORE Right

            viewtbl.ShowDialog();
        }
        private void button3_Click_1(object sender, EventArgs e)
        {
            if (this.ionumber == "")
            {
                MessageBox.Show("Please nhập IO number ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                txtionumber.Focus();
                return;
            }

            if (txtchargetoaccount.Text == "")
            {
                MessageBox.Show("Please nhập Account charge to ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                txtchargetoaccount.Focus();
                return;
            }

            if (txtcostcenter.Text == "")
            {
                MessageBox.Show("Please nhập Cost center ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                txtcostcenter.Focus();
                return;
            }
            //check if payment natf đã request ? // một khách hàng 1/ 1 iio chỉ một lần request



            #region q List các document có trong bảng tbl_MKT_Payment_AprovalTMP không có trong bảng tbl_MKT_Payment_Aproval   !
            //---
            string connection_string = Utils.getConnectionstr();
            LinqtoSQLDataContext dc  = new LinqtoSQLDataContext(connection_string);

            var q = from paymenttemp in dc.tbl_MKT_Payment_AprovalTMPs
                    where (from payment in dc.tbl_MKT_Payment_Aprovals
                           select payment.Customercode).Contains(paymenttemp.Customercode) &&
                    (from payment in dc.tbl_MKT_Payment_Aprovals
                     select payment.IO_number).Contains(paymenttemp.IO_number)

                    select paymenttemp;



            if (q.Count() != 0)
            {
                Viewtable viewtbl = new Viewtable(q, dc, "List các payment request đã lập request rồi, please check", 100, "paymentrequest");

                viewtbl.ShowDialog();
                return;
            }



            var q2 = from p in dc.tbl_MKT_Payment_AprovalTMPs
                     where p.username == username
                     select p;

            if (q2.Count() == 0)
            {
                MessageBox.Show("Please nhập nhập chi tiết request ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                btiosetup.Focus();
                return;
            }
            #endregion q



            //update head IOpayment
            var newpaymentrequest = (from p in dc.tbl_MKT_Payment_Aproval_heads
                                     where p.IO_number == "TMP" && p.username == username
                                     select p).FirstOrDefault();


            if (newpaymentrequest != null)
            {
                newpaymentrequest.IO_number  = Utils.Truncate(txtionumber.Text, 50);
                newpaymentrequest.payID      = this.payID;
                newpaymentrequest.Account    = Utils.Truncate(txtchargetoaccount.Text, 50);
                newpaymentrequest.costcenter = Utils.Truncate(txtcostcenter.Text, 50);
                newpaymentrequest.Requestby  = username;

                newpaymentrequest.ProgrameIDDocno = Utils.Truncate(txtsohieuct.Text, 225);
                newpaymentrequest.ProgrameName    = Utils.Truncate(txttenct.Text, 50);

                newpaymentrequest.Approval           = "Not Approved";
                newpaymentrequest.TotalAprovalBudget = this.totalBudget;

                dc.SubmitChanges();
            }
            else
            {
                MessageBox.Show("Pleae check IO payment ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                btiosetup.Focus();
                return;
            }
            // tbl_MKT_Payment_Aproval_head newpaymentrequest = new tbl_MKT_Payment_Aproval_head();



            // udate payment progarme
            var tmprequest = from p in dc.tbl_MKT_Payment_AprovalTMPs
                             where p.username == username
                             select p;


            foreach (var item in tmprequest)
            {
                tbl_MKT_Payment_Aproval newpaymentRQ = new tbl_MKT_Payment_Aproval();


                newpaymentRQ.IO_number  = Utils.Truncate(txtionumber.Text, 50);
                newpaymentRQ.payID      = this.payID;
                newpaymentRQ.Account    = Utils.Truncate(txtchargetoaccount.Text, 50);
                newpaymentRQ.costcenter = Utils.Truncate(txtcostcenter.Text, 50);
                newpaymentRQ.Requestby  = username;

                newpaymentRQ.AprovalBudget = item.AprovalBudget;

                newpaymentRQ.Customercode    = item.Customercode;
                newpaymentRQ.CustomerName    = item.CustomerName;
                newpaymentRQ.CustomerAddress = item.CustomerAddress;
                newpaymentRQ.ProgrameIDDocno = Utils.Truncate(txtsohieuct.Text, 50);

                newpaymentRQ.Requsestdate = txtfromdate.Value;
                newpaymentRQ.Approval     = "Not Approved";

                dc.tbl_MKT_Payment_Aprovals.InsertOnSubmit(newpaymentRQ);
                dc.SubmitChanges();
            }


            MessageBox.Show("Upload payment done ! ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

            blanknewpayment();
        }