コード例 #1
0
        private void btnPhatHanhHuy_Click(object sender, EventArgs e)
        {
            int    m_bd         = Convert.ToInt16(txtbd.Text);
            int    m_kt         = Convert.ToInt16(txtkt.Text);
            int    m_bd_indexdt = 0;
            int    m_kt_indexdt = 0;
            string m_XML        = "";
            string SQL;
            string reSult = "";

            // int[,] a;

            if (!checkEdit1.Checked)
            {
                if (m_bd < Convert.ToInt16(dt.Rows[0]["stt_order"]) || m_kt > Convert.ToInt16(dt.Rows[dt.Rows.Count - 1]["stt_order"]))
                {
                    MessageBox.Show("Số in nhỏ hơn số bắt đầu hoặc số kết thúc lớn hơn dữ liệu");
                }
                else
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        if (Convert.ToInt32(dt.Rows[i]["stt_order"]) == m_bd)
                        {
                            m_bd_indexdt = i;
                        }
                        if (Convert.ToInt32(dt.Rows[i]["stt_order"]) == m_kt)
                        {
                            m_kt_indexdt = i;
                        }
                    }
                    //a = PhatHanh.phan_doan(dt.Rows.Count, Connection.m_so_hoa_don);
                    for (int j = m_bd_indexdt; j <= m_kt_indexdt; j++)
                    {
                        string m_keyR = dt.Rows[j]["m_key"].ToString().Trim();
                        m_XML = PhatHanh.phat_hanh_hoa_don_huy(txtTensodoc.Text.ToString().Trim(), dt, j, j, dateEdit1.DateTime.Month, dateEdit1.DateTime.Year, dateEdit2.Text);
                        // goi webservice phát hành hóa đơn
                        //string m_keyR = dt.Rows[j]["m_key"].ToString();
                        //ghi file xml vao thu muc chua file exe
                        if (m_XML != null)
                        {
                            string strStartupPath       = Application.StartupPath;
                            string strXmlDataFilePath   = strStartupPath + "\\" + "einv" + ".xml";
                            System.IO.StreamWriter file = new System.IO.StreamWriter(strXmlDataFilePath);
                            file.WriteLine(m_XML);
                            file.Close();
                        }

                        //string m_keyR = "1804660104$1";
                        plWebservice.PublishService pl = new plWebservice.PublishService();
                        pl.Timeout = Connection.pl_timeout;
                        reSult     = pl.ImportAndPublishInv(Connection.accountHsm, Connection.accpassHsm, m_XML, Connection.userNameHsm, Connection.userPassHsm, Connection.patternHsm, Connection.serial1, 0);
                        if (reSult.Substring(0, 2) == "OK")
                        {
                            // cap nhat so lan ph tang len 1 log file vào table DaPH
                            Connection.ConnectSQLSERVER();
                            //,m_key = left(m_key, 10) + '$' + rtrim(convert(nchar, m_lan))
                            SQL = "UPDATE DaPH SET m_lan=m_lan+1,m_key='" + dt.Rows[j]["m_key"].ToString().Trim() + "' WHERE ma_kh='" + dt.Rows[j]["ma_kh"].ToString().Trim() + "' AND thang=" + Convert.ToInt16(dt.Rows[j]["thang"]) + " AND nam=" + Convert.ToInt16(dt.Rows[j]["nam"]);
                            using (SqlCommand c = new SqlCommand(SQL, Connection.conn))
                            {
                                try
                                {
                                    c.ExecuteNonQuery();
                                }
                                finally
                                {
                                    c.Dispose();
                                    Connection.DisconnectData();
                                }
                            }
                            // end cap nhat so lan ph tang len 1 log file vào table DaPH
                        }
                        else
                        {
                            MessageBox.Show("Chưa phát hành hóa đơn thứ " + j.ToString() + reSult.ToString() + "\t" + m_XML.ToString());
                        }
                    }
                }
            }
            else
            {
                if (isCheck())
                {
                    for (int i = 0; i < gridView2.RowCount; i++)
                    {
                        if (Convert.ToBoolean(gridView2.GetRowCellValue(i, status)))
                        {
                            string m_keyR = dt.Rows[i]["m_key"].ToString().Trim();
                            m_XML = PhatHanh.phat_hanh_hoa_don_huy(txtTensodoc.Text.ToString().Trim(), dt, i, i, dateEdit1.DateTime.Month, dateEdit1.DateTime.Year, dateEdit2.Text);
                            // goi webservice phát hành hóa đơn
                            if (m_XML != null)
                            {
                                string strStartupPath       = Application.StartupPath;
                                string strXmlDataFilePath   = strStartupPath + "\\" + "einv" + ".xml";
                                System.IO.StreamWriter file = new System.IO.StreamWriter(strXmlDataFilePath);
                                file.WriteLine(m_XML);
                                file.Close();
                            }
                            plWebservice.PublishService pl = new plWebservice.PublishService();
                            reSult = pl.ImportAndPublishInv(Connection.accountHsm, Connection.accpassHsm, m_XML, Connection.userNameHsm, Connection.userPassHsm, Connection.patternHsm, Connection.serial1, 0);
                            if (reSult.Substring(0, 2) == "OK")
                            {
                                // cap nhat so lan ph tang len 1 log file vào table DaPH
                                Connection.ConnectSQLSERVER();
                                SQL = "UPDATE DaPH SET m_lan=m_lan+1,m_key='" + dt.Rows[i]["m_key"].ToString().Trim() + "' WHERE ma_kh='" + dt.Rows[i]["ma_kh"].ToString().Trim() + "' AND thang=" + Convert.ToInt16(dt.Rows[i]["thang"]) + " AND nam=" + Convert.ToInt16(dt.Rows[i]["nam"]);
                                using (SqlCommand c = new SqlCommand(SQL, Connection.conn))
                                {
                                    try
                                    {
                                        c.ExecuteNonQuery();
                                    }
                                    finally
                                    {
                                        c.Dispose();
                                        Connection.DisconnectData();
                                    }
                                }
                                // end cap nhat so lan ph tang len 1 log file vào table DaPH
                            }
                            else
                            {
                                MessageBox.Show("Chưa phát hành hóa đơn thứ " + i.ToString());
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Chưa check chọn hóa đơn nào");
                }
            }
            get_data();
        }
コード例 #2
0
        private void cmdPhathanh_Click(object sender, EventArgs e)
        {
            int    m_bd         = Convert.ToInt16(txtbd.Text);
            int    m_kt         = Convert.ToInt16(txtkt.Text);
            int    m_bd_indexdt = 0;
            int    m_kt_indexdt = 0;
            string m_XML        = "";
            string SQL;
            string reSult = "";

            // int[,] a;
            plWebservice.PublishService pl = new plWebservice.PublishService();
            if (m_bd < Convert.ToInt16(dt.Rows[0]["stt_order"]) || m_kt > Convert.ToInt16(dt.Rows[dt.Rows.Count - 1]["stt_order"]))
            {
                MessageBox.Show("Số in nhỏ hơn số bắt đầu hoặc số kết thúc lớn hơn dữ liệu");
            }
            else
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (Convert.ToInt32(dt.Rows[i]["stt_order"]) == m_bd)
                    {
                        m_bd_indexdt = i;
                    }
                    if (Convert.ToInt32(dt.Rows[i]["stt_order"]) == m_kt)
                    {
                        m_kt_indexdt = i;
                    }
                }
                //a = PhatHanh.phan_doan(dt.Rows.Count, Connection.m_so_hoa_don);
                for (int j = m_bd_indexdt; j <= m_kt_indexdt; j++)
                {
                    // goi webservice phát hành hóa đơn
                    m_XML  = PhatHanh.phat_hanh_hoa_don(txtTensodoc.Text.Trim(), dt, j, j, dateEdit1.DateTime.Month, dateEdit1.DateTime.Year, "", "");
                    reSult = pl.ImportAndPublishInv(Connection.accountHsm, Connection.accpassHsm, m_XML, Connection.userNameHsm, Connection.userPassHsm, Connection.patternHsm, Connection.serial1, 0);
                    System.Threading.Thread.Sleep(2000);
                    if (reSult.Substring(0, 2) == "OK")
                    {
                        //string ngay_ct4 = Connection.convert_date(dt.Rows[j]["ngay_ct0"].ToString().Substring(0, 10));
                        // cap nhat so lan ph tang len 1 log file vào table DaPH
                        Connection.ConnectSQLSERVER();
                        SQL = "INSERT INTO DaPH(ma_kh,ngay_ct0,nam,thang,so_doc,status,m_key,m_lan)" +
                              "VALUES('" + dt.Rows[j]["ma_kh"].ToString().Trim() + "','" + Connection.convert_date(dt.Rows[j]["ngay_ct0"].ToString().Substring(0, 10)) + "'," + Convert.ToInt16(dt.Rows[j]["nam"]) + "," + Convert.ToInt16(dt.Rows[j]["thang"]) + ",'" + dt.Rows[j]["so_doc"].ToString().Trim() + "',1,'" + dt.Rows[j]["m_key"].ToString().Trim() + "',1)";
                        using (SqlCommand c = new SqlCommand(SQL, Connection.conn))
                        {
                            try
                            {
                                c.ExecuteNonQuery();
                            }
                            finally
                            {
                                c.Dispose();
                            }
                        }
                        // end cap nhat so lan ph tang len 1 log file vào table DaPH
                    }
                    else
                    {
                        MessageBox.Show("Chưa phát hành hóa đơn thứ " + j.ToString());
                    }
                }
                // kiem tra xem nếu tất cả các row trong so doc co key thi inser vao table in_sodoc de danh dau so doc nay da in het roi
                if (!isCheckNULL(dt))
                {
                    Connection.ConnectSQLSERVER();
                    SQL = "INSERT INTO in_sodoc(nam,thang,so_doc,status)" +
                          "VALUES(" + Convert.ToInt16(dt.Rows[m_kt_indexdt]["nam"]) + "," + Convert.ToInt16(dt.Rows[m_kt_indexdt]["thang"]) + ",'" + dt.Rows[m_kt_indexdt]["so_doc"].ToString().Trim() + "',1)";

                    using (SqlCommand c = new SqlCommand(SQL, Connection.conn))
                    {
                        try
                        {
                            c.ExecuteNonQuery();
                        }
                        finally
                        {
                            c.Dispose();
                        }
                    }
                    Connection.DisconnectData();
                }
            }
        }
コード例 #3
0
        private void cmdPhathanh_Click(object sender, EventArgs e)
        {
            label3.Text         = "Đang phát hành hóa đơn";
            cmdPhathanh.Enabled = false;
            //System.Threading.Thread.Sleep(5000);
            //gridView1.DeleteRow(1);
            // DataTable dt=  GetData.Get_InvoiceList("045", dateEdit1.DateTime.Month, dateEdit1.DateTime.Year);

            string    m_sodoc = "";
            string    m_XML   = "";
            string    SQL;
            string    reSult = "";
            DataTable dt     = new DataTable();

            int[,] a;

            try
            {
                if (isCheck())
                {
                    //Bat đau phat hanh hoa don
                    for (int k = 0; k < gridView1.RowCount; k++)
                    {
                        if (Convert.ToBoolean(gridView1.GetRowCellValue(k, status)))
                        {
                            dt.Clear();
                            m_sodoc = gridView1.GetRowCellValue(k, so_doc).ToString().Trim();
                            string m_ten_so_doc = gridView1.GetRowCellValue(k, ten_so_doc).ToString().Trim();
                            dt = GetData.Get_InvoiceList(m_sodoc, dateEdit1.DateTime.Month, dateEdit1.DateTime.Year, "InvoiceList");

                            //string m_sodoc= gridView1.GetRowCellValue(i, status)
                            //DataTable dt =  gridView1.GetRowCellValue(i, status)
                            Connection.ConnectSQLSERVER();

                            a = PhatHanh.phan_doan(dt.Rows.Count, Connection.m_so_hoa_don);
                            int t = a.GetLength(1);
                            for (int i = 0; i < a.GetLength(1); i++)
                            {
                                m_XML = PhatHanh.phat_hanh_hoa_don(m_ten_so_doc, dt, a[0, i], a[1, i], dateEdit1.DateTime.Month, dateEdit1.DateTime.Year, "", dngayPH.Text);
                                plWebservice.PublishService pl = new plWebservice.PublishService();
                                pl.Timeout = Connection.pl_timeout;
                                reSult     = pl.ImportAndPublishInv(Connection.accountHsm, Connection.accpassHsm, m_XML, Connection.userNameHsm, Connection.userPassHsm, Connection.patternHsm, Connection.serial1, 0);
                                if (reSult.Substring(0, 2) == "OK")
                                {
                                    // ghi log file vào table DaPH
                                    // Connection.ConnectSQLSERVER();
                                    for (int j = a[0, i]; j <= a[1, i]; j++)
                                    {
                                        //string ngay_ct2 = Connection.convert_date(dt.Rows[j]["ngay_ct0"].ToString().Substring(0, 10));
                                        SQL = "INSERT INTO DaPH(ma_kh,ngay_ct0,nam,thang,so_doc,status,m_key,m_lan)" +
                                              "VALUES('" + dt.Rows[j]["ma_kh"].ToString().Trim() + "','" + Connection.convert_date(dt.Rows[j]["ngay_ct0"].ToString().Substring(0, 10)) + "'," + Convert.ToInt16(dt.Rows[j]["nam"]) + "," + Convert.ToInt16(dt.Rows[j]["thang"]) + ",'" + dt.Rows[j]["so_doc"].ToString().Trim() + "',1,'" + dt.Rows[j]["m_key"].ToString().Trim() + "',1)";

                                        using (SqlCommand c = new SqlCommand(SQL, Connection.conn))
                                        {
                                            try
                                            {
                                                c.ExecuteNonQuery();
                                            }
                                            finally
                                            {
                                                c.Dispose();
                                            }
                                        }
                                    }

                                    // end ghi log file vào table DaPH
                                    // MessageBox.Show(a[0,i].ToString());
                                    //MessageBox.Show(a[1, i].ToString());
                                }
                                else
                                {
                                    MessageBox.Show("Chưa phát hành hóa đơn đoạn " + dt.Rows[a[0, i]]["stt_order"].ToString() + " đến " + dt.Rows[a[1, i]]["stt_order"].ToString() + " của sổ đọc " + m_sodoc);
                                    return;
                                }
                            }
                            label3.Text = "Đã phát hành hóa đơn xong";
                            MessageBox.Show("Đã phát hành hóa đơn xong !");
                            if (reSult.Substring(0, 2) == "OK")
                            {
                                SQL = "INSERT INTO in_sodoc(nam,thang,so_doc,status)" +
                                      "VALUES(" + dateEdit1.DateTime.Year + "," + dateEdit1.DateTime.Month + ",'" + gridView1.GetRowCellValue(k, "so_doc") + "',1)";

                                using (SqlCommand c = new SqlCommand(SQL, Connection.conn))
                                {
                                    try
                                    {
                                        c.ExecuteNonQuery();
                                    }
                                    finally
                                    {
                                        c.Dispose();
                                    }
                                }
                                //gridView1.DeleteRow(k);
                                //dt.Rows[k].Delete();
                                //load_dl_grid2(dateEdit1.DateTime.Month, dateEdit1.DateTime.Year);
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Chưa chọn sổ đọc nào");
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                load_dl(gridControl1, dateEdit1.DateTime.Month, dateEdit1.DateTime.Year);
                Connection.DisconnectData();
                cmdPhathanh.Enabled = true;
            }
        }