public int UpdateWorkorder(Stream stream)
        {
            DALDB dal = new DALDB(connStr);
            WorkOrder.Workorder wo = new Workorder();
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(WorkOrder.Workorder));
            wo = (WorkOrder.Workorder)ser.ReadObject(stream);

            if (wo != null)
            {
                if (dal.GetWorkorder(wo.wo_ID) != null)
                {
                    dal.UpdateWorkorder(wo);
                }
                return 1;
            }
            dal.AddWorkorder(wo);
            //string fileName = Server.MapPath("Output.txt");
            // write a text file
            FileStream fs = new FileStream(@"c:\xworkorders.txt", FileMode.Append);
            TextWriter tws = new StreamWriter(fs);

            // write the current datetime to the stream
            tws.WriteLine(DateTime.Now);

            // write test strings to the stream
            tws.WriteLine(wo.wo_ID);
            tws.WriteLine(wo.wo_Number);
            tws.WriteLine(wo.wo_Date);
            tws.WriteLine(wo.wo_Debtor);
            tws.WriteLine(wo.wo_Address);
            tws.WriteLine(wo.wo_StartTime);

            tws.Close();   // close the stream

            return 1;
        }
Пример #2
0
        public List<WorkOrder.Workorder> GetWorkorders()
        {
            try
            {
                using (conn)
                {
                    woList = new List<WorkOrder.Workorder>();
                    string sqlSelectStr = "SELECT wo_ID, wo_Number, wo_Date, wo_Debtor, wo_Address, wo_StartTime FROM Workorders;";
                    conn = new SqlConnection(connString);
                    SqlCommand command = new SqlCommand();
                    command.Connection = conn;
                    command.Connection.Open();
                    command.CommandText = sqlSelectStr;

                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        WorkOrder.Workorder wo = new Workorder();
                        wo.wo_ID = (int)reader[0];
                        wo.wo_Number = (int) reader[1];
                        wo.wo_Date = (DateTime) reader[2];
                        wo.wo_Debtor = reader[3].ToString();
                        wo.wo_Address = reader[4].ToString();
                        wo.wo_StartTime = (DateTime)reader[5];

                        woList.Add(wo);
                    }

                    command.Connection.Close();
                    return woList;
                }

            }
            catch (Exception ex)
            {
                err.ErrorMessage = ex.Message.ToString();
                throw;
            }
        }