/* * Finding the difference between the start booking date and end booking date * to calculate the cost of a booking */ public void calculateBookingCost(DateTimePicker startDate, DateTimePicker endDate, ComboBox cbo_Description, TextBox txt_Cost) { connection.Close(); DateTime dt1 = Convert.ToDateTime(startDate.Text); DateTime dt2 = Convert.ToDateTime(endDate.Text); TimeSpan timeSpan = dt2 - dt1; int numberOfDays = timeSpan.Days; string query_String = "SELECT Car_Rate FROM Car_Class WHERE Description ='" + cbo_Description.Text + "'"; connection.Open(); try { cmd = connection.CreateCommand(); cmd.CommandText = query_String; data_reader = cmd.ExecuteReader();//the reader is used to read in the required record if (data_reader.HasRows) { data_reader.Read(); txt_Cost.Text = ("" + data_reader.GetInt32(0) * numberOfDays); } connection.Close(); } catch (Exception) { } }
public void selectBookingId( TextBox txt_Booking_Id) { string query_String = "SELECT MAX(Booking_Id) FROM Bookings"; try { connection.Open(); cmd = connection.CreateCommand(); cmd.CommandText = query_String; data_reader = cmd.ExecuteReader();//the reader is used to read in the required record if (data_reader.HasRows) { data_reader.Read(); var count = data_reader.GetInt32(0); var nextId = count + 1; txt_Booking_Id.Text =("" + nextId) ; } connection.Close(); } catch (Exception ex) // Catching exception if the id dosent match any records { ex.GetBaseException(); } }
public void recalculate(DateTimePicker start, DateTimePicker end, TextBox txt_Cost, ComboBox cbo_Car_Reg) { DateTime dt1 = Convert.ToDateTime(start.Text); DateTime dt2 = Convert.ToDateTime(end.Text); TimeSpan timeSpan = dt2 - dt1; int numberOfDays = timeSpan.Days; string query_String2 = string.Format("SELECT Car_Rate FROM Car_Class C JOIN Cars S ON C.Class_Id = S.Class_Id WHERE Car_Reg = '{0}'", cbo_Car_Reg.Text); try { connection.Open(); cmd = connection.CreateCommand(); cmd.CommandText = query_String2; data_reader = cmd.ExecuteReader();//the reader is used to read in the required record if (data_reader.HasRows) { data_reader.Read(); txt_Cost.Text = ("" + data_reader.GetInt32(0) * numberOfDays); } connection.Close(); } catch (Exception) // Catching exception if the id dosent match any records { //MessageBox.Show("No Record Found"); MessageBox.Show("No Cars Found", "ERROR", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } }
public void extraCost(TextBox txt_Days_Late, TextBox txt_Search_Reg, TextBox txt_Additional_Costs,EventArgs e) { string query_String = string.Format("SELECT Car_Rate FROM Car_Class C JOIN Cars S ON C.Class_Id = S.Class_Id WHERE Car_Reg = '{0}'", txt_Search_Reg.Text); try { connection.Open(); cmd = connection.CreateCommand(); cmd.CommandText = query_String; data_reader = cmd.ExecuteReader();//the reader is used to read in the required record if (data_reader.HasRows) { data_reader.Read(); if (numberOfDays < 0) { txt_Additional_Costs.Text =("" + 0); } else { txt_Additional_Costs.Text = (" " + data_reader.GetInt32(0) * numberOfDays); } } connection.Close(); } catch (Exception ex) // Catching exception if the id dosent match any records { ex.GetBaseException(); } }
public override int GetInt32(int ordinal) { return(rdr.GetInt32(ordinal)); }
public CWarehouseTask GetTask2(int channel) { if (channel == 4) channel = 0; bool sucess = false; CWarehouseTask newTask = null; if (Connection.State != ConnectionState.Open) { return null; } try { using (OracleCommand cmd = new OracleCommand()) { cmd.Connection = Connection; //MessageBox.Show(GetTaskSQLCommand2); cmd.CommandText = string.Format(GetTaskSQLCommand2, channel); cmd.CommandType = CommandType.Text; using (dataReader = cmd.ExecuteReader()) { if (dataReader.Read()) {//如果有任务 OprationState = "正在读取任务"; #region 读取 //#region task_id,task_type,status,from_addr,to_addr,create_time,product_id,pack_unit,pack_num,pallet_id CWarehouseTask tmpTask = new CWarehouseTask(); tmpTask.TaskID = dataReader.GetInt32(0); tmpTask.TaskType = (CWarehouseTask.ETaskType)int.Parse(dataReader.GetString(1)); tmpTask.State = int.Parse(dataReader.GetString(2)); //调整地址格式 string tmp = dataReader.GetString(3); tmp = tmp.Replace("LF00", "WH01"); tmpTask.SourceAddress = tmp; tmp = dataReader.GetString(4); tmp = tmp.Replace("LF00", "WH01"); tmp = tmp.Replace("CR0115", "CR0105"); tmpTask.DestinationAddress = tmp; //调整空托盘直出任务类型 if ((tmpTask.TaskType == CWarehouseTask.ETaskType.空托盘返库) && (tmpTask.DestinationAddress == "CR0105")) { tmpTask.TaskType = CWarehouseTask.ETaskType.空托盘直出; } tmpTask.CreateTime = dataReader.GetDateTime(5); tmpTask.ProductID = dataReader.GetString(6); tmpTask.PackingUnit = dataReader.GetString(7); tmpTask.PackingNumber = dataReader.GetInt32(8); tmpTask.PalletID = dataReader.GetString(9); tmpTask.ProductName = dataReader.GetString(10); if (dataReader[11] != null) { int ch = dataReader.GetInt32(11); tmpTask.ChannelID = (ch == 0) ? (4) : (ch); } else { tmpTask.ChannelID = 4; } tmpTask.Priority = dataReader.GetInt32(12); //tmpTask.RunningState = CWarehouseTask.EState.创建; #endregion #region 创建 try { newTask = new CWarehouseTask(tmpTask.TaskID, tmpTask.Req_ID, (int)tmpTask.TaskType, tmpTask.State, tmpTask.SourceAddress, tmpTask.DestinationAddress, tmpTask.CreateTime, tmpTask.ProductID, tmpTask.PackingUnit, tmpTask.PackingNumber, tmpTask.Num, tmpTask.Priority, tmpTask.PalletID, tmpTask.ProductName, tmpTask.ChannelID); sucess = true; } catch (Exception ex1) { sucess = false; Program.ErrorManager.Add(new RuntimeError(oprationState, RuntimeError.EVisibility.Programer, new Exception("生成任务实例出现异常,此异常并不会影响程序执行结果。", ex1))); } #endregion } else {//无任务 sucess = false; } } } } catch (Exception ex) // catches any other error { sucess = false; OprationState = "读取任务过程中出现数据库相关的操作错误"; Program.ErrorManager.Add(new RuntimeError(oprationState, RuntimeError.EVisibility.Programer, ex)); } //如果无错误,返回newTask,否则返回null return ((sucess) && newTask != null) ? (newTask) : (null); }