示例#1
0
        /// <summary>
        /// Get id max <10000
        /// cộng thêm 1 vào idmax
        /// kiểm tra xem hasname đã có mã chưa
        /// nếu có rồi thì id = id of hasname
        /// </summary>
        /// <param name="hasName"></param>
        /// <param name="checkInsert"></param>
        /// <returns></returns>
        private int GetIDValue(int hasName, out bool checkInsert)
        {
            checkInsert = false;
            int idMax = 0;

            try
            {
                idMax = Common.Obj2Int(this.propertiesValueTableAdapter.ScalarQuery_GetMaxIDDienTay());
            }
            catch (Exception)
            {
            }
            int idValue = idMax + 1;

            DBProperties.PropertiesValueDataTable dt = new DBProperties.PropertiesValueDataTable();
            this.propertiesValueTableAdapter.FillBy_SelectOne(dt, idValue);
            if (dt.Rows.Count <= 0)
            {
                checkInsert = true;
                dt          = new DBProperties.PropertiesValueDataTable();
                this.propertiesValueTableAdapter.FillBy_HasName(dt, hasName);
                if (dt.Rows.Count > 0)
                {
                    checkInsert = false;
                    idValue     = Common.Obj2Int(dt.Rows[0]["ID"].ToString());
                }
                else
                {
                    /// duyet từ đầu tìm id
                    ///
                    DBProperties.PropertiesValueDataTable dtValue = new DBProperties.PropertiesValueDataTable();
                    this.propertiesValueTableAdapter.FillBy_Top10000ID(dtValue);
                    for (int id = 0; id < dtValue.Count - 1; id++)
                    {
                        if (id != Common.Obj2Int(dtValue.Rows[id]["ID"].ToString()))
                        {
                            idValue = id;
                            break;
                        }
                    }
                }
            }
            return(idValue);
        }
示例#2
0
        private void btDeleteValue_Click(object sender, EventArgs e)
        {
            DBPropertiesTableAdapters.PropertiesValueTableAdapter adt = new DBPropertiesTableAdapters.PropertiesValueTableAdapter();
            adt.Connection.ConnectionString = QT.Entities.Server.ConnectionString;
            DBPropertiesTableAdapters.Product_PropertiesTableAdapter adtPro = new DBPropertiesTableAdapters.Product_PropertiesTableAdapter();
            adtPro.Connection.ConnectionString = QT.Entities.Server.ConnectionString;

            DBProperties.PropertiesValueDataTable dtvalue = new DBProperties.PropertiesValueDataTable();
            adt.Fill(dtvalue);
            int i = 0, dem = 0;

            foreach (DBProperties.PropertiesValueRow dr in dtvalue)
            {
                int count = Common.Obj2Int(adtPro.ScalarQuery_CountByValue(dr.ID));
                if (count == 0)
                {
                    dem++;
                    adt.DeleteQuery(dr.ID);
                }
                i++;
                this.laMess.Text = string.Format("{0}/{1}--{2}", i, dtvalue.Count, dem);
                Application.DoEvents();
            }
        }