/*更新備用備件資訊*/ public static bool UpdateDeviceModel(BackupDeviceModel backupDevice) { string updateSql = "update [t_device_backup] set "; updateSql += "typeId=" + backupDevice.getTypeId() + ","; updateSql += "deviceName=" + SqlString.GetQuotedString(backupDevice.getDeviceName()) + ","; updateSql += "deviceModel=" + SqlString.GetQuotedString(backupDevice.getDeviceModel()) + ","; updateSql += "price=" + backupDevice.getPrice() + ","; updateSql += "deviceFrom=" + SqlString.GetQuotedString(backupDevice.getDeviceFrom()) + ","; updateSql += "manufacturer=" + SqlString.GetQuotedString(backupDevice.getManufacturer()) + ","; updateSql += "inDate=" + SqlString.GetQuotedString(backupDevice.getInDate()) + ","; updateSql += "outDate=" + SqlString.GetQuotedString(backupDevice.getOutDate()) + ","; updateSql += "stockCount=" + backupDevice.getStockCount() + ","; updateSql += "inOperator=" + SqlString.GetQuotedString(backupDevice.getInOperator()) + ","; updateSql += "outOperator=" + SqlString.GetQuotedString(backupDevice.getOutOperator()); updateSql += " where id=" + backupDevice.getId(); DataBase db = new DataBase(); if (db.InsertOrUpdate(updateSql) < 0) { return(false); } return(true); }
//判斷用戶的登陸管理許可權 public bool checkLogin(UserModel userModel) { string queryString; bool hasUser, isPasswordRight; //首先在資料庫中查詢該管理帳號是否存在 queryString = "select * from [t_user] where username = "******"對不起,用戶名不存在!"; return(false); } //再查詢資料庫該管理帳號的密碼是否正確 queryString = "select * from [t_user] where username = "******" and password = "******"對不起,使用者密碼錯誤!"; return(false); } return(true); }
/*登記備用備件資訊*/ public static bool AddBackupDevice(BackupDeviceModel backupDevice) { //string sqlString = string.Format("insert into [t_device_backup] (typeId,deviceName,deviceModel,price,deviceFrom,manufacturer,inDate,outDate,stockCount,inOperator,outOperator) values '{0}', '{1}', N'{2}', N'{3}', '{4}', N'{5}', N'{6}', '{7}', '{8}', N'{9}', N'{10}'", string sqlString = "insert into [t_device_backup] (typeId,deviceName,deviceModel,price,deviceFrom,manufacturer,inDate,outDate,stockCount,inOperator,outOperator) values ("; sqlString += backupDevice.getTypeId() + ","; sqlString += SqlString.GetQuotedString(backupDevice.getDeviceName()) + ","; sqlString += SqlString.GetQuotedString(backupDevice.getDeviceModel()) + ","; sqlString += backupDevice.getPrice() + ","; sqlString += SqlString.GetQuotedString(backupDevice.getDeviceFrom()) + ","; sqlString += SqlString.GetQuotedString(backupDevice.getManufacturer()) + ","; sqlString += SqlString.GetQuotedString(backupDevice.getInDate()) + ","; sqlString += SqlString.GetQuotedString(backupDevice.getOutDate()) + ","; sqlString += backupDevice.getStockCount() + ","; sqlString += SqlString.GetQuotedString(backupDevice.getInOperator()) + ","; sqlString += SqlString.GetQuotedString(backupDevice.getOutOperator()) + ")"; DataBase db = new DataBase(); if (db.InsertOrUpdate(sqlString) < 0) { return(false); } return(true); }
/*刪除某個使用者記錄*/ public bool DelUserInfo(string username) { string deleteString = "delete from [t_user] where username="******"刪除使用者發生了錯誤!"; return(false); } return(true); }
//修改登陸密碼 public bool ChangePassword(UserModel userModel) { string updateString = "update [t_user] set password="******" where username=" + SqlString.GetQuotedString(userModel.getUsername()); DataBase db = new DataBase(); if (db.InsertOrUpdate(updateString) < 0) { return(false); } return(true); }
/*更新報廢設備資訊*/ public static bool UpdateUselessDevice(UselessDeviceModel uselessDevice) { string updateString = "update [t_device_useless] set typeId="; updateString += uselessDevice.getTypeId() + ",deviceName="; updateString += SqlString.GetQuotedString(uselessDevice.getDeviceName()) + ",deviceModel="; updateString += SqlString.GetQuotedString(uselessDevice.getDeviceModel()) + ",deviceFrom="; updateString += SqlString.GetQuotedString(uselessDevice.getDeviceFrom()) + ",deviceCount="; updateString += uselessDevice.getDeviceCount() + " where id=" + uselessDevice.getId(); DataBase db = new DataBase(); if (db.InsertOrUpdate(updateString) > 0) { return(true); } return(true); }
/*登記報廢設備資訊*/ public static bool AddUselessDevice(UselessDeviceModel uselessDevice) { string insertString = "insert into [t_device_useless] (typeId,deviceName,deviceModel,deviceFrom,deviceCount) values ("; insertString += uselessDevice.getTypeId() + ","; insertString += SqlString.GetQuotedString(uselessDevice.getDeviceName()) + ","; insertString += SqlString.GetQuotedString(uselessDevice.getDeviceModel()) + ","; insertString += SqlString.GetQuotedString(uselessDevice.getDeviceFrom()) + ","; insertString += uselessDevice.getDeviceCount() + ")"; DataBase db = new DataBase(); if (db.InsertOrUpdate(insertString) > 0) { return(true); } return(false); }
/*添加設備類別資訊*/ public bool AddDeviceType(string typeName) { string queryString = "select * from [t_device_type] where typeName=" + SqlString.GetQuotedString(typeName); DataBase db = new DataBase(); DataSet ds = db.GetDataSet(queryString); if (ds.Tables[0].Rows.Count > 0) { this.errMessage = "此類別名稱已經存在!"; return(false); } string insertString = "insert into [t_device_type] (typeName) values ('" + typeName + "')"; if (db.InsertOrUpdate(insertString) < 0) { this.errMessage = "添加類別失敗!"; return(false); } return(true); }
/*加入新的使用者資訊*/ public bool AddUserInfo(UserModel userModel) { string queryString = "select count(*) from [t_user] where username="******"該用戶名已經存在!"; return(false); } string insertString = "insert into [t_user] (username,password) values ("; insertString += SqlString.GetQuotedString(userModel.getUsername()) + ","; insertString += SqlString.GetQuotedString(userModel.getPassword()) + ")"; if (db.InsertOrUpdate(insertString) < 0) { this.errMessage = "添加使用者資訊時發生了錯誤!"; return(false); } return(true); }
/*添加在用設備資訊*/ public static bool AddUsingDevice(UsingDeviceModel usingDevice) { string insertString = "insert into [t_device_using] (typeId,deviceName,deviceModel,deviceFrom,manufacturer,useDate,deviceLife,usePlace,deviceCount,deviceState) values ("; insertString += usingDevice.getTypeId() + ","; insertString += SqlString.GetQuotedString(usingDevice.getDeviceName()) + ","; insertString += SqlString.GetQuotedString(usingDevice.getDeviceModel()) + ","; insertString += SqlString.GetQuotedString(usingDevice.getDeviceFrom()) + ","; insertString += SqlString.GetQuotedString(usingDevice.getManufacturer()) + ","; insertString += SqlString.GetQuotedString(usingDevice.getUseDate().ToString()) + ","; insertString += usingDevice.getDeviceLife() + ","; insertString += SqlString.GetQuotedString(usingDevice.getUsePlace()) + ","; insertString += usingDevice.getDeviceCount() + ","; insertString += SqlString.GetQuotedString(usingDevice.getDeviceState()) + ")"; DataBase db = new DataBase(); if (db.InsertOrUpdate(insertString) < 0) { return(false); } return(true); }
/*更新在用設備資訊*/ public static bool UpdateUsingDevice(UsingDeviceModel usingDevice) { string updateString = "update [t_device_using] set typeId="; updateString += usingDevice.getTypeId() + ",deviceName="; updateString += SqlString.GetQuotedString(usingDevice.getDeviceName()) + ",deviceModel="; updateString += SqlString.GetQuotedString(usingDevice.getDeviceModel()) + ",deviceFrom="; updateString += SqlString.GetQuotedString(usingDevice.getDeviceFrom()) + ",manufacturer="; updateString += SqlString.GetQuotedString(usingDevice.getManufacturer()) + ",useDate="; updateString += SqlString.GetQuotedString(usingDevice.getUseDate().ToString()) + ",deviceLife="; updateString += usingDevice.getDeviceLife() + ",usePlace="; updateString += SqlString.GetQuotedString(usingDevice.getUsePlace()) + ",deviceCount="; updateString += usingDevice.getDeviceCount() + ",deviceState="; updateString += SqlString.GetQuotedString(usingDevice.getDeviceState()); updateString += " where id=" + usingDevice.getId(); DataBase db = new DataBase(); if (db.InsertOrUpdate(updateString) < 0) { return(false); } return(true); }
/*找出庫存報警的設備*/ public static ArrayList GetStockWarningDevices() { ArrayList devices = new ArrayList(); string queryString = "select * from [t_device_using]"; DataBase db = new DataBase(); DataSet usingDeviceDs = db.GetDataSet(queryString); for (int i = 0; i < usingDeviceDs.Tables[0].Rows.Count; i++) { DataRow dr = usingDeviceDs.Tables[0].Rows[i]; /*設備名稱*/ string deviceName = dr["deviceName"].ToString(); /*使用開始時間*/ DateTime useDate = Convert.ToDateTime(dr["useDate"]); /*使用壽命*/ int deviceLife = Convert.ToInt32(dr["deviceLife"]); /*當前時間*/ DateTime nowDate = DateTime.Now; /*計算已經使用的天數*/ TimeSpan ts = nowDate - useDate; int haveUsedDays = Convert.ToInt32(ts.TotalDays); /*計算剩餘可以使用的天數*/ int leftDays = deviceLife - haveUsedDays; if (leftDays < Constant.WARNING_DAYS) { /*如果在用設備壽命即將到期,查詢備用備件中該設備是否存在*/ queryString = "select * from [t_device_backup] where deviceName=" + SqlString.GetQuotedString(deviceName); DataSet backupDeviceDs = db.GetDataSet(queryString); if (backupDeviceDs.Tables[0].Rows.Count == 0) { /*如果備用設備不存在,則將該設備名稱加入到庫存報警資訊中*/ devices.Add(deviceName); } } } return(devices); }