Пример #1
0
        private void f_Chuyen_dmbd(int d_nhomkho_nguon, int d_nhomkho_dich)
        {
            int     m_id     = f_get_maxid("d_dmbd");
            string  s_userdb = d.user;
            string  asql     = "select id from " + s_userdb + ".d_dmbd where nhom=" + d_nhomkho_dich;
            DataSet ads      = d.get_data(asql);

            if (ads != null && ads.Tables.Count > 0 && ads.Tables[0].Rows.Count > 0)
            {
                MessageBox.Show("Danh mục d_dmbd đã chuyển.");
                return;
            }
            string s_field = d.f_get_select_field("d_dmbd", "", "a");

            s_field = s_field.Replace("a.id,", "a.id+" + m_id + " as id,");
            s_field = s_field.Replace("a.nhom,", d_nhomkho_dich + " as nhom,");
            asql    = " insert into " + s_userdb + ".d_dmbd ";
            asql   += "select " + s_field + " from " + s_userdb + ".d_dmbd a where nhom=" + d_nhomkho_nguon;
            d.execute_data(asql);

            asql = "update " + s_userdb + ".d_dmbd set ma=null where nhom=" + d_nhomkho_dich;
            d.execute_data(asql);
            asql = "select id, ma, ten from " + s_userdb + ".d_dmbd where nhom=" + d_nhomkho_dich;
            ads  = d.get_data(asql);
            string s_ma = "";

            foreach (DataRow dr in ads.Tables[0].Rows)
            {
                s_ma = d.getMabd("d_dmbd", dr["ten"].ToString(), d_nhomkho_dich);
                if (s_ma != "")
                {
                    asql = "update " + s_userdb + ".d_dmbd set ma='" + s_ma + "' where id=" + dr["id"].ToString();
                    d.execute_data(asql);
                }
                lblStatus.Text = dr["ten"].ToString();
                lblStatus.Refresh();
            }
        }