コード例 #1
0
        //添加员工_2s
        public static Employee AddEmployee(Employee employee)
        {
            int            i              = 0;
            string         id             = "";
            OdbcConnection odbcConnection = DBManager.GetOdbcConnection();

            odbcConnection.Open();
            OdbcCommand    odbcCommand    = new OdbcCommand();
            OdbcDataReader odbcDataReader = null;

            odbcCommand.Connection = odbcConnection;
            string selectSql = "select * from employee where E_ID='";

            while (i < 5)//检查id是否可用
            {
                id        = IDFormat.getID_8();
                selectSql = selectSql + id + "'";
                odbcCommand.CommandText = selectSql;
                odbcDataReader          = odbcCommand.ExecuteReader(CommandBehavior.CloseConnection);
                if (!odbcDataReader.HasRows)
                {
                    break;
                }
                odbcDataReader.Close();
                i++;
            }
            if (i >= 5)//5次获取不到ID,返回null
            {
                odbcConnection.Close();
                return(null);
            }
            //成功获取到ID
            odbcDataReader.Close();
            odbcConnection.Close();
            odbcConnection.Open();
            employee.ID       = id;
            employee.PassWord = "******";
            String insertSql = String.Format("insert into `marketmanage`.`employee`  (`E_ID`, `E_Name`, `E_Sex`, `E_Phone`, `E_Birth`, `E_BankAccount`, `E_Email`, `E_Position`, `E_Password`) " +
                                             "values ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}')"
                                             , employee.ID, employee.Name, employee.Sex, employee.Phone, employee.Birth, employee.BankAccount, employee.Email, employee.Position, employee.PassWord);

            odbcCommand.CommandText = insertSql;
            i = odbcCommand.ExecuteNonQuery();
            odbcConnection.Close();
            return((i > 0) ? employee : null);
        }
コード例 #2
0
        //入库(手动输入生产日期)
        public static bool AddGoods(GoodsIn goodsin, DateTime producedate)
        {
            //判断商品ID是否存在
            string         sql            = "select * from goods where G_ID='" + goodsin.G_ID + "'";
            OdbcConnection odbcConnection = DBManager.GetOdbcConnection();

            odbcConnection.Open();
            OdbcCommand    odbcCommand    = new OdbcCommand(sql, odbcConnection);
            OdbcDataReader odbcDataReader = odbcCommand.ExecuteReader(CommandBehavior.CloseConnection);

            if (!odbcDataReader.HasRows)//商品ID不存在 返回空
            {
                return(false);
            }
            //商品ID存在 插入
            bool flag;

            goodsin.GI_ID = IDFormat.getID_8();
            String insertSql = String.Format("insert into `marketmanage`.`goodsin`  (`GI_ID`, `G_ID`,`S_ID`,`GI_PriceIn`,`GI_Num`,`GI_Date`,`GI_OriginPlace`) " +
                                             "values ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')"
                                             , goodsin.GI_ID, goodsin.G_ID, goodsin.S_ID, goodsin.PriceIn, goodsin.Num, goodsin.Date, goodsin.OriginPlace);

            flag = ExecuteSQL.ExecuteNonQuerySQL_GetBool(insertSql);

            //更新库存表
            if (!flag)
            {
                return(false);
            }
            string update_storelist = String.Format("insert into `marketmanage`.`storelist` (`G_ID`,`GI_ID`,`SL_Num`,`SL_ProducedDate`) values ('{0}','{1}','{2}','{3}')"
                                                    , goodsin.G_ID, goodsin.GI_ID, goodsin.Num, producedate);

            flag = ExecuteSQL.ExecuteNonQuerySQL_GetBool(update_storelist);

            //更新商品表(库存数量)
            if (!flag)
            {
                return(false);
            }
            String update_goods = "update Goods set G_Store=G_Store+" + goodsin.Num + " where G_ID='" + goodsin.G_ID + "'";

            flag = ExecuteSQL.ExecuteNonQuerySQL_GetBool(update_goods);

            return(flag? true : false);
        }