Exemplo n.º 1
0
 /// <summary>
 /// 判断是否登陆成功
 /// </summary>
 /// <param name="userName">用户名</param>
 /// <param name="password">密码</param>
 /// <returns></returns>
 public bool LoginIn(string userName, string password)
 {
     if (IsUserExist(userName))
     {
         string sql = $"select count(*) from Users Where userName = '******' and password = '******';";
         return((int)AccessDbHelper.SelectForScalar(sql) > 0);
     }
     return(false);
 }
Exemplo n.º 2
0
        public override void InitializeDisplay()
        {
            using (var helper = new AccessDbHelper())
            {
                Items = helper.GetDataTable(@"SELECT * FROM [CUSTOMER] WHERE ISDELETED = 0").ToItemList <Customer>().Select(x => (IModel)x.ToViewModel()).ToList();
            }

            base.InitializeDisplay();
        }
Exemplo n.º 3
0
        public override void InitializeDisplay()
        {
            using (var helper = new AccessDbHelper())
            {
                Items = helper.GetDataTable(string.Format(@"SELECT * FROM [Prescription] WHERE CustomerId= {0} AND ISDELETED = 0", CustomerInfo.Id)).ToItemList <Prescription>().Select(x => (IModel)x.ToViewModel()).ToList();
            }

            base.InitializeDisplay();
        }
Exemplo n.º 4
0
        private void btnSelectDrugs_Click(object sender, EventArgs e)
        {
            string sql = string.Format("select *from DrugsTable");;

            if (txtDrugs.Text.Trim() != string.Empty)
            {
                sql += string.Format(" where DrugsName like '%{0}%'", txtDrugs.Text.Trim());
            }
            DataTable dt = AccessDbHelper.ExecuteDataTable(sql);

            dataGridView1.DataSource = dt;
        }
Exemplo n.º 5
0
        protected override void ProcessRecord()
        {
            WriteProgress(new ProgressRecord(1, "Conversion", "Converting database..."));
            AccessDbHelper acccessdbHelper = new AccessDbHelper(AccessDbFilePath, "Database");
            IJsonConverter dbJsonConverter = new DataSetConverter(acccessdbHelper.GetDataSet());
            string         databaseJson    = dbJsonConverter.ConvertToJson();

            if (SaveOutputToFile)
            {
                FileHelper.SaveToFile(databaseJson, $"output_{Guid.NewGuid()}.json");
            }
            WriteObject(databaseJson);
        }
Exemplo n.º 6
0
        private void Login(object payload)
        {
            if (string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(Password))
            {
                Logger.Warn(string.Format("Login attemp failed for user {0}", UserName));
                MessageBox.Show("用户名或者密码不能为空!", "登录失败", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            using (AccessDbHelper helper = new AccessDbHelper())
            {
                object passObject = null;
                try
                {
                    passObject = helper.ExecuteScalar(string.Format("SELECT [PASSWORD] FROM [USER] WHERE USERNAME='******'", UserName));
                }
                catch (Exception)
                {
                    Logger.Warn(string.Format("Login attemp failed for user {0}", UserName));
                    //Noting to do
                    //Password can't be got.
                }

                if (passObject != null && passObject.ToString() == Password)
                {
                    Logger.Info(string.Format("User {0} login.", UserName));
                    AppContext.CurrentUser.UserName = UserName;
                    //AppContext.CurrentUser = new Entity.UserEntity() { UserName = UserName };
                    OnBack("");
                }
                else
                {
                    Logger.Warn(string.Format("Login attemp failed for user {0}", UserName));
                    MessageBox.Show("用户名或者密码不正确!", "登录失败", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                //int count = (int)helper.ExecuteScalar(string.Format("select count(*) from [user] where username='******' and password='******'", UserName, Password));

                //if (count > 0)
                //{
                //    OnBack("");
                //}
                //else
                //{
                //    Logger.Warn(string.Format("Login attemp failed for user {0}", UserName));
                //    MessageBox.Show("用户名或者密码不正确!", "登录失败", MessageBoxButton.OK, MessageBoxImage.Error);
                //    return;
                //}
            }
        }
Exemplo n.º 7
0
        public List <string> GetTeacher()
        {
            string sql = "select RealName from Users Where IsTeacher = true;";
            var    dr  = AccessDbHelper.SelectForDataReader(sql);

            List <string> teachers = new List <string>();

            while (dr.Read())
            {
                string TeacherName = dr["RealName"].ToString();
                teachers.Add(TeacherName);
            }
            return(teachers);
        }
Exemplo n.º 8
0
        private void dataGridView3_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                //取消打印
                if (dataGridView3.Columns[e.ColumnIndex].Name == "btnPrintDel")
                {
                    int       RowIndex  = Convert.ToInt32(e.RowIndex);
                    string    DrugsID   = dataGridView3.Rows[RowIndex].Cells[0].Value.ToString();
                    string    SelectSQL = string.Format("select *from DrugsTable where DrugsID={0}", DrugsID);
                    string    UpdateSQL;
                    DataTable dt = AccessDbHelper.ExecuteDataTable(SelectSQL);

                    //库存数据变更

                    //查询现有库存数量
                    int stock = Convert.ToInt32(dt.Rows[0]["Stock"]);

                    //删除打印的数量与现有库存相加
                    stock += Convert.ToInt32(dataGridView3.Rows[RowIndex].Cells[10].Value);
                    //更新现有库存数据
                    UpdateSQL = string.Format("UPDATE DrugsTable SET Stock='{0}' WHERE DrugsID={1} ", stock, DrugsID);
                    if (!(AccessDbHelper.ExecuteNonQuery(UpdateSQL) > 0))
                    {
                        if (!ignore)//判断消息是否要忽略
                        {
                            DialogResult dialogResult = MessageBox.Show("更新库存失败,但不会影响您的打印!不再提示此类消息?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                            if (dialogResult == System.Windows.Forms.DialogResult.Yes)
                            {
                                ignore = true;
                            }
                        }
                    }

                    //删除打印区的数据
                    DataGridViewRow row = dataGridView3.Rows[RowIndex];
                    dataGridView3.Rows.Remove(row);

                    //重新计算价格
                    CountNum();
                    //刷新库存
                    btnSelectDrugs_Click(null, null);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 9
0
        public List <Storage> GetAllStorage()
        {
            var            dr       = AccessDbHelper.SelectDataReader("select * from Storage;");
            List <Storage> storages = new List <Storage>();

            while (dr.Read())
            {
                Storage storage = new Storage();
                storage.Id           = dr["Id"].ToString();
                storage.SlaveAddress = Convert.ToInt32(dr["Id"].ToString());
                storage.FuncCode     = dr["Id"].ToString();
                storage.StartAddress = Convert.ToInt32(dr["Id"].ToString());
                storage.Length       = Convert.ToInt32(dr["Id"].ToString());
                storages.Add(storage);
            }
            return(storages);
        }
Exemplo n.º 10
0
        public static bool DeleteFromDb(this IDataModel obj)
        {
            try
            {
                using (AccessDbHelper helper = new AccessDbHelper())
                {
                    helper.ExecuteSQLNonQuery(string.Format("UPDATE [{0}] SET ISDELETED =1 WHERE ID={1}", obj.GetType().Name, ((IDataModel)obj).Id));
                }
                return(true);
            }
            catch (Exception ex)
            {
                ApplicationContext.Current.Logger.Error("DeleteFromDb failed.", ex);
            }

            return(false);
        }
Exemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="RowIndex">第RowIndex行</param>
        /// <param name="GoodsCount">出仓货物数量</param>
        void AddPrintItemToGridView(int RowIndex, int GoodsCount)
        {
            //获取主键标识
            string DrugsID = dataGridView1.Rows[RowIndex].Cells["DrugsID"].Value.ToString();
            int    surplus = Convert.ToInt32(dataGridView1.Rows[RowIndex].Cells["Stock"].Value) - GoodsCount;
            string strSQL  = string.Format("UPDATE DrugsTable SET Stock='{0}' WHERE DrugsID={1}", surplus, DrugsID);

            try
            {
                //数据库更新库存数据

                //BUG 执行成功依然返回0
                //if (AccessDbHelper.ExecuteNonQuery(strSQL) > 0)
                //{
                //    //只提示用户库存未更新!不影响用户使用打印数据
                //    MessageBox.Show("库存信息更新失败!您依然可以进行打印,但库存信息有错误!");
                //}

                //更新库存
                AccessDbHelper.ExecuteNonQuery(strSQL);
                //取得其他字段值
                string DrugsName      = dataGridView1.Rows[RowIndex].Cells["DrugsName"].Value.ToString();
                string Specification  = dataGridView1.Rows[RowIndex].Cells["Specification"].Value.ToString();
                string Model          = dataGridView1.Rows[RowIndex].Cells["Model"].Value.ToString();
                string Unti           = dataGridView1.Rows[RowIndex].Cells["Unti"].Value.ToString();
                string Price          = dataGridView1.Rows[RowIndex].Cells["Price"].Value.ToString();
                string Origin         = dataGridView1.Rows[RowIndex].Cells["Origin"].Value.ToString();
                string Batch          = dataGridView1.Rows[RowIndex].Cells["Batch"].Value.ToString();
                string ProductionDate = Convert.ToDateTime(dataGridView1.Rows[RowIndex].Cells["ProductionDate"].Value).ToString("yyyy-MM-dd");
                string Validity       = Convert.ToDateTime(dataGridView1.Rows[RowIndex].Cells["Validity"].Value).ToString("yyyy-MM-dd");
                string Stock          = GoodsCount.ToString();
                string Quality        = dataGridView1.Rows[RowIndex].Cells["Quality"].Value.ToString();
                dataGridView3.Rows.Add(DrugsID, DrugsName, Specification, Model, Unti, Price, Origin, Batch, ProductionDate, Validity, Stock, Quality);
                //清空:计算价格
                CountNum();
            }
            catch (Exception ex)
            {
                MessageBox.Show("库存信息更新失败!请稍后再试。错误信息:" + ex.Message);
            }
            finally {
                //刷新表格数据
                btnSelectDrugs_Click(null, null);
            }
        }
Exemplo n.º 12
0
        public static bool SaveToDb(this IDataModel obj)
        {
            try
            {
                using (var helper = new AccessDbHelper())
                {
                    string insertParams = GetInsertString(obj);
                    helper.ExecuteSQLNonQuery(string.Format("INSERT INTO [{0}] {1}", obj.GetType().Name, insertParams));
                }
                return(true);
            }
            catch (Exception ex)
            {
                ApplicationContext.Current.Logger.Error("DeleteFromDb failed.", ex);
            }

            return(false);
        }
Exemplo n.º 13
0
        public static bool UpdateToDb(this IDataModel obj)
        {
            try
            {
                using (var helper = new AccessDbHelper())
                {
                    string updateParams = GetUpdateString(obj);
                    helper.ExecuteSQLNonQuery(string.Format("UPDATE [{0}] SET {1}", obj.GetType().Name, updateParams));
                }
                return(true);
            }
            catch (Exception ex)
            {
                ApplicationContext.Current.Logger.Error("DeleteFromDb failed.", ex);
            }

            return(false);
        }
Exemplo n.º 14
0
        /// <summary>
        /// 获取当前用户信息
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <returns>返回用户信息</returns>
        public User GetUserInfo(string userName)
        {
            string sql  = $"select * from Users Where userName = '******';";
            var    dr   = AccessDbHelper.SelectForDataReader(sql);
            User   user = new User();

            while (dr.Read())
            {
                user.UserID       = dr["UserID"].ToString();
                user.UserName     = dr["UserName"].ToString();
                user.RealName     = dr["RealName"].ToString();
                user.Password     = dr["Password"].ToString();
                user.Avatar       = dr["Avatar"].ToString();
                user.Gender       = Convert.ToInt32(dr["Gender"]);
                user.IsValidation = (bool)dr["IsValidation"];
                user.IsCanLogin   = (bool)dr["IsCanLogin"];
                user.IsTeacher    = (bool)dr["IsTeacher"];
            }
            return(user);
        }
Exemplo n.º 15
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string StrSql = "insert into DrugsTable (DrugsName,Specification,Model,Unti,Price,Origin,Batch,ProductionDate,Validity,Stock,Quality)values(@DrugsName,@Specificatio,@Model,@Unti,@Price,@Origin,@Batch,@ProductionDate,@Validity,@Stock,@Quality)";

            try
            {
                if (AccessDbHelper.ExecuteNonQuery(StrSql,
                                                   new OleDbParameter("@DrugsName", txtDrugsName.Text.Trim()),
                                                   new OleDbParameter("@Specification", txtSpecification.Text.Trim()),
                                                   new OleDbParameter("@Model", txtModel.Text.Trim()),
                                                   new OleDbParameter("@Unti", txtUnti.Text.Trim()),
                                                   new OleDbParameter("@Price", txtPrice.Text.Trim() == string.Empty?"0":txtPrice.Text.Trim()),
                                                   new OleDbParameter("@Origin", txtOrigin.Text.Trim()),
                                                   new OleDbParameter("@Batch", txtBatch.Text.Trim()),
                                                   new OleDbParameter("@ProductionDate", dtpProductionDate.Value.ToShortDateString()),
                                                   new OleDbParameter("@Validity", dtpValidity.Value.ToShortDateString()),
                                                   new OleDbParameter("@Stock", txtStock.Text.Trim() == string.Empty?"0":txtStock.Text.Trim()),
                                                   new OleDbParameter("@Quality", txtQuality.Text.Trim())
                                                   ) > 0)
                {
                    txtDrugsName.Text     = string.Empty;
                    txtBatch.Text         = string.Empty;
                    txtModel.Text         = string.Empty;
                    txtOrigin.Text        = string.Empty;
                    txtPrice.Text         = string.Empty;
                    txtQuality.Text       = string.Empty;
                    txtSpecification.Text = string.Empty;
                    txtStock.Text         = string.Empty;
                    txtUnti.Text          = string.Empty;
                    MessageBox.Show("添加成功!");
                }
                else
                {
                    MessageBox.Show("添加失败!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("添加失败!");
            }
        }
Exemplo n.º 16
0
        public static void Upgrade()
        {
            //IDataModel
            var assembly      = typeof(IDataModel).Assembly;
            var dataModelList = assembly.GetTypes().Where(x => x.GetInterfaces().Contains(typeof(IDataModel))).ToList();

            foreach (var item in dataModelList)
            {
                string tableName  = item.Name;
                var    properties = item.GetProperties();
                using (var helper = new AccessDbHelper())
                {
                    var table = helper.GetDataTable(string.Format("SELECT * FROM [{0}]", tableName));
                    foreach (var property in properties)
                    {
                        if (!table.Columns.Contains(property.Name))
                        {
                            helper.ExecuteSQLNonQuery(string.Format("ALTER TABLE [{0}] ADD COLUMN [{1}] {2}", tableName, property.Name, GetDBType(property)));
                        }
                    }
                }
            }
        }
Exemplo n.º 17
0
        //清除打印区
        private void btnClearPrint_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewColumn Columns in dataGridView3.Columns)
            {
                foreach (DataGridViewRow row in dataGridView3.Rows)
                {
                    //获取取消打印行的数据的主键
                    string DrugsID = row.Cells[0].Value.ToString();
                    //查询取消打印行现有库存数量
                    string    SelectSQL = string.Format("select *from DrugsTable where DrugsID={0}", DrugsID);
                    DataTable dt        = AccessDbHelper.ExecuteDataTable(SelectSQL);
                    int       stock     = Convert.ToInt32(dt.Rows[0]["Stock"]);
                    //删除打印的数量与现有库存相加
                    stock += Convert.ToInt32(row.Cells[10].Value);
                    //更新现有库存数据
                    string UpdateSQL = string.Format("UPDATE DrugsTable SET Stock='{0}' WHERE DrugsID={1}", stock, DrugsID);
                    if (!(AccessDbHelper.ExecuteNonQuery(UpdateSQL) > 0))
                    {
                        if (!ignore)//判断消息是否要忽略
                        {
                            DialogResult dialogResult = MessageBox.Show("更新库存失败,但不会影响您的打印!不再提示此类消息?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                            if (dialogResult == System.Windows.Forms.DialogResult.Yes)
                            {
                                ignore = true;
                            }
                        }
                    }

                    dataGridView3.Rows.Remove(row);//删除行
                }
            }
            //刷新表格数据
            btnSelectDrugs_Click(null, null);
            //清空:计算价格
            CountNum();
        }
Exemplo n.º 18
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //删除
            if (dataGridView1.Columns[e.ColumnIndex].Name == "colbtnDel")
            {
                int RowIndex = Convert.ToInt32(e.RowIndex);
                //点击按钮操作
                string DrugsID   = dataGridView1.Rows[RowIndex].Cells["DrugsID"].Value.ToString();
                string DrugsName = dataGridView1.Rows[RowIndex].Cells["DrugsName"].Value.ToString();

                DialogResult dr = MessageBox.Show(string.Format("确认删除[{0}]吗", DrugsName), "提示", MessageBoxButtons.OKCancel);
                if (dr == DialogResult.OK)
                {
                    //数据删除
                    string strSQL = string.Format("DELETE FROM DrugsTable WHERE DrugsID = {0} ", DrugsID);
                    if (AccessDbHelper.ExecuteNonQuery(strSQL) > 0)
                    {
                        //刷新DataGridView
                        btnSelectDrugs_Click(null, null);
                    }
                    else
                    {
                        MessageBox.Show(string.Format("删除时 [{0}] 失败!", DrugsName));
                    }
                }
            }
            //编辑
            else if (dataGridView1.Columns[e.ColumnIndex].Name == "colbtnEdit")
            {
                try
                {
                    int RowIndex = Convert.ToInt32(e.RowIndex);
                    //主键
                    string DrugsID = dataGridView1.Rows[RowIndex].Cells["DrugsID"].Value.ToString();
                    //取得其他字段值
                    string DrugsName      = dataGridView1.Rows[RowIndex].Cells["DrugsName"].Value.ToString();;
                    string Specification  = dataGridView1.Rows[RowIndex].Cells["Specification"].Value.ToString();
                    string Model          = dataGridView1.Rows[RowIndex].Cells["Model"].Value.ToString();
                    string Unti           = dataGridView1.Rows[RowIndex].Cells["Unti"].Value.ToString();
                    string Price          = dataGridView1.Rows[RowIndex].Cells["Price"].Value.ToString();
                    string Origin         = dataGridView1.Rows[RowIndex].Cells["Origin"].Value.ToString();
                    string Batch          = dataGridView1.Rows[RowIndex].Cells["Batch"].Value.ToString();
                    string ProductionDate = dataGridView1.Rows[RowIndex].Cells["ProductionDate"].Value.ToString();
                    string Validity       = dataGridView1.Rows[RowIndex].Cells["Validity"].Value.ToString();
                    string Stock          = dataGridView1.Rows[RowIndex].Cells["Stock"].Value.ToString();
                    string Quality        = dataGridView1.Rows[RowIndex].Cells["Quality"].Value.ToString();

                    //构造执行语句
                    string strSQL = string.Format("UPDATE DrugsTable SET DrugsName='{0}',Specification='{1}',Model='{2}',Unti='{3}',Price='{4}',Origin='{5}',Batch='{6}',ProductionDate='{7}',Validity='{8}',Stock='{9}',Quality='{10}' WHERE DrugsID={11}",
                                                  DrugsName,
                                                  Specification,
                                                  Model,
                                                  Unti,
                                                  Price == null || Price == string.Empty?"0":Price,
                                                  Origin,
                                                  Batch,
                                                  ProductionDate,
                                                  Validity,
                                                  Stock == null || Stock == string.Empty ? "0" : Stock,
                                                  Quality,
                                                  DrugsID
                                                  );
                    if (AccessDbHelper.ExecuteNonQuery(strSQL) > 0)
                    {
                        MessageBox.Show("修改成功!");
                        //刷新DataGridView
                        btnSelectDrugs_Click(null, null);
                    }
                    else
                    {
                        MessageBox.Show("修改失败!请检查数据是否填写正确");
                    }
                }
                catch
                {
                    MessageBox.Show("修改失败!");
                }
            }
            //打印
            else if (dataGridView1.Columns[e.ColumnIndex].Name == "colbtnPrint")
            {
                try
                {
                    int RowIndex = Convert.ToInt32(e.RowIndex);
                    //主键
                    string   DrugsID           = dataGridView1.Rows[RowIndex].Cells["DrugsID"].Value.ToString();
                    string   DrugsName         = dataGridView1.Rows[RowIndex].Cells["DrugsName"].Value.ToString();
                    int      GoodsCount        = Convert.ToInt32(dataGridView1.Rows[RowIndex].Cells["Stock"].Value);
                    CallBack AddPrint_CallBack = new CallBack(AddPrintItemToGridView);

                    new AddPrint(AddPrint_CallBack, RowIndex, DrugsName, GoodsCount).ShowDialog();

                    //MessageBox.Show(dataGridView3.Rows[0].Cells[0].Value.ToString());
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// 判断用户名是否存在
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <returns>存在或不存在</returns>
        public bool IsUserExist(string userName)
        {
            string sql = $"select count(*) from Users Where userName = '******';";

            return((int)AccessDbHelper.SelectForScalar(sql) > 0);
        }
Exemplo n.º 20
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            dataGridView1.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView3.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            //ReportParameterCostume ReportParameterPrintDate ReportParameterID ReportParameterRed ReportParameterCountAll
            //ReportParameterCountAllCN ReportParameterDrawer ReportParameterPhone ReportParameterRecAddr ReportParameterWhite ReportParameterBlue
            //ReportParameterSalesman ReportParameterVerification ReportParameterDelivery ReportParameterSaver ReportParameterPrintTime
            PrintParams.Add("ReportParameterCostume", "");
            PrintParams.Add("ReportParameterPrintDate", "");
            PrintParams.Add("ReportParameterID", "");
            PrintParams.Add("ReportParameterRed", "");
            PrintParams.Add("ReportParameterCountAll", "");
            PrintParams.Add("ReportParameterCountAllCN", "");
            PrintParams.Add("ReportParameterDrawer", "");
            PrintParams.Add("ReportParameterPhone", "");
            PrintParams.Add("ReportParameterRecAddr", "");
            PrintParams.Add("ReportParameterWhite", "");
            PrintParams.Add("ReportParameterBlue", "");
            PrintParams.Add("ReportParameterSalesman", "");
            PrintParams.Add("ReportParameterVerification", "");
            PrintParams.Add("ReportParameterDelivery", "");
            PrintParams.Add("ReportParameterSaver", "");
            PrintParams.Add("ReportParameterPrintTime", "");
            PrintParams.Add("ReportParameterYellow", "");

            #region 初始化数据库
            string filePath = Environment.CurrentDirectory + @"\DrugsDatabase.mdb";
            //初始化数据库,若数据库不存在则创建
            if (!File.Exists(filePath))
            {
                if (AccessDbHelper.CreateAccessDb(filePath))
                {
                    #region 初始化表字段
                    //药品名称 DrugsName
                    ADOX.ColumnClass DrugsName = new ADOX.ColumnClass
                    {
                        //ParentCatalog = catalog,
                        Name        = "DrugsName",
                        Attributes  = ColumnAttributesEnum.adColNullable, //允许空值
                        Type        = DataTypeEnum.adVarWChar,
                        DefinedSize = 255,
                    };
                    //规格 Specification
                    ADOX.ColumnClass Specification = new ADOX.ColumnClass
                    {
                        //ParentCatalog = catalog,
                        Name        = "Specification",
                        Attributes  = ColumnAttributesEnum.adColNullable, //允许空值
                        Type        = DataTypeEnum.adVarWChar,
                        DefinedSize = 255,
                    };
                    //型号 Model
                    ADOX.ColumnClass Model = new ADOX.ColumnClass
                    {
                        //ParentCatalog = catalog,
                        Name        = "Model",
                        Attributes  = ColumnAttributesEnum.adColNullable, //允许空值
                        Type        = DataTypeEnum.adVarWChar,
                        DefinedSize = 50,
                    };
                    //单位 Unti
                    ADOX.ColumnClass Unti = new ADOX.ColumnClass
                    {
                        //ParentCatalog = catalog,
                        Name        = "Unti",
                        Attributes  = ColumnAttributesEnum.adColNullable, //允许空值
                        Type        = DataTypeEnum.adVarWChar,
                        DefinedSize = 50,
                    };
                    //单价 Price
                    ADOX.ColumnClass Price = new ADOX.ColumnClass
                    {
                        //ParentCatalog = catalog,
                        Name        = "Price",
                        Attributes  = ColumnAttributesEnum.adColNullable, //允许空值
                        Type        = DataTypeEnum.adDouble,
                        DefinedSize = 50,
                    };
                    //产地 Origin
                    ADOX.ColumnClass Origin = new ADOX.ColumnClass
                    {
                        //ParentCatalog = catalog,
                        Name        = "Origin",
                        Attributes  = ColumnAttributesEnum.adColNullable, //允许空值
                        Type        = DataTypeEnum.adVarWChar,
                        DefinedSize = 255,
                    };
                    //批准批号 Batch
                    ADOX.ColumnClass Batch = new ADOX.ColumnClass
                    {
                        //ParentCatalog = catalog,
                        Name        = "Batch",
                        Attributes  = ColumnAttributesEnum.adColNullable, //允许空值
                        Type        = DataTypeEnum.adVarWChar,
                        DefinedSize = 50,
                    };
                    //生产日期 ProductionDate
                    ADOX.ColumnClass ProductionDate = new ADOX.ColumnClass
                    {
                        //ParentCatalog = catalog,
                        Name       = "ProductionDate",
                        Attributes = ColumnAttributesEnum.adColNullable, //允许空值
                        Type       = ADOX.DataTypeEnum.adDate,
                    };
                    //有效日期 Validity
                    ADOX.ColumnClass Validity = new ADOX.ColumnClass
                    {
                        //ParentCatalog = catalog,
                        Name       = "Validity",
                        Attributes = ColumnAttributesEnum.adColNullable, //允许空值
                        Type       = ADOX.DataTypeEnum.adDate,
                    };
                    //库存 Stock
                    ADOX.ColumnClass Stock = new ADOX.ColumnClass
                    {
                        //ParentCatalog = catalog,
                        Name        = "Stock",
                        Attributes  = ColumnAttributesEnum.adColNullable, //允许空值
                        Type        = ADOX.DataTypeEnum.adInteger,
                        DefinedSize = 100
                    };
                    //质量状况 Quality
                    ADOX.ColumnClass Quality = new ADOX.ColumnClass
                    {
                        //ParentCatalog = catalog,
                        Name        = "Quality",
                        Attributes  = ColumnAttributesEnum.adColNullable, //允许空值
                        Type        = ADOX.DataTypeEnum.adVarWChar,
                        DefinedSize = 255
                    };

                    #endregion
                    List <ADOX.ColumnClass> columns = new List <ADOX.ColumnClass>();
                    columns.Add(DrugsName);
                    columns.Add(Specification);
                    columns.Add(Model);
                    columns.Add(Unti);
                    columns.Add(Price);
                    columns.Add(Origin);
                    columns.Add(Batch);
                    columns.Add(ProductionDate);
                    columns.Add(Validity);
                    columns.Add(Stock);
                    columns.Add(Quality);
                    AccessDbHelper.CreateAccessTable(filePath, "DrugsTable", columns);
                }
                else
                {
                    MessageBox.Show("数据库创建失败,以管理员身份运行!或添加数据库[DrugsDatabase.mdb]到程序运行目录下。", "警告");
                }
            }
            else
            {
                ReflashDataGridView();
            }
            #endregion
            #region DataGridView 按钮渲染
            DataGridViewButtonColumn btnDel = new DataGridViewButtonColumn();
            btnDel.Name       = "colbtnDel";
            btnDel.HeaderText = "操作";
            btnDel.DefaultCellStyle.NullValue = "删除";

            DataGridViewButtonColumn btnEdit = new DataGridViewButtonColumn();
            btnEdit.Name       = "colbtnEdit";
            btnEdit.HeaderText = "操作";
            btnEdit.DefaultCellStyle.NullValue = "编辑";

            DataGridViewButtonColumn btnPrint = new DataGridViewButtonColumn();
            btnPrint.Name       = "colbtnPrint";
            btnPrint.HeaderText = "操作";
            btnPrint.DefaultCellStyle.NullValue = "打印";

            dataGridView1.Columns.Add(btnDel);
            dataGridView1.Columns.Add(btnEdit);
            dataGridView1.Columns.Add(btnPrint);

            DataGridViewButtonColumn btnPrintDel = new DataGridViewButtonColumn();
            btnPrintDel.Name       = "btnPrintDel";
            btnPrintDel.HeaderText = "操作";
            btnPrintDel.DefaultCellStyle.NullValue = "删除";
            dataGridView3.Columns.Add(btnPrintDel);

            #endregion
        }
Exemplo n.º 21
0
        private void ReflashDataGridView()
        {
            string strSQL = "select *from DrugsTable";

            dataGridView1.DataSource = AccessDbHelper.ExecuteDataTable(strSQL);
        }