public IHttpActionResult Get(int companyId, string clientMac, int contactId)
        {
            try
            {
                DateTime?lastUpdateTime = WebCommon.GetSyncTime(companyId, clientMac);

                using (SqlConnection sqlcon = new SqlConnection(WebCommon.WebConnection))
                {
                    sqlcon.Open();

                    string     sSQL = @"WS_FLEM_LEMEquip_Get";
                    SqlCommand cmd  = new SqlCommand(sSQL, sqlcon);
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.Add(new SqlParameter("@contactId", contactId));
                    cmd.Parameters.Add(new SqlParameter("@CompanyId", companyId));
                    cmd.Parameters.Add(new SqlParameter("@LastSyncTime", (object)lastUpdateTime ?? DBNull.Value));

                    DataTable table = new DataTable();
                    table.Load(cmd.ExecuteReader());

                    List <EquipTimeEntry> list = table.Select().Select(r => new EquipTimeEntry
                    {
                        MatchId       = (int)r["MatchId"],
                        CompanyId     = companyId,
                        HeaderId      = (int)r["HeaderMatchId"],
                        EqpNum        = $"{r["eqi_num"]}",
                        ChangeOrderId = ConvertEx.ToNullable <int>(r["EstId"]),
                        Level1Id      = ConvertEx.ToNullable <int>(r["lv1_id"]),
                        Level2Id      = ConvertEx.ToNullable <int>(r["lv2_id"]),
                        Level3Id      = ConvertEx.ToNullable <int>(r["lv3_id"]),
                        Level4Id      = ConvertEx.ToNullable <int>(r["lv4_id"]),
                        Billable      = (bool)r["Billable"],
                        Quantity      = Convert.ToDecimal(r["Quantity"]),
                        BillCycle     = (Equipment.EnumBillCycle)(Convert.ToChar(r["BillCycle"])),
                        BillAmount    = ConvertEx.ToNullable <decimal>(r["dollars_total"]),
                    }).ToList();

                    return(Ok(list));
                }
            }
            catch (Exception e)
            {
                SqlCommon.ReportInfo(e.Message);
                return(BadRequest(e.Message));
            }
        }
예제 #2
0
        public IHttpActionResult Get(int companyId, string clientMac, int contactId)
        {
            try
            {
                DateTime?lastUpdateTime = WebCommon.GetSyncTime(companyId, clientMac);

                using (SqlConnection sqlcon = new SqlConnection(WebCommon.WebConnection))
                {
                    sqlcon.Open();

                    string sSQL = @"WS_FLEM_LEMHeader_Get";
                    using (SqlCommand cmd = new SqlCommand(sSQL, sqlcon))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;

                        cmd.Parameters.Add(new SqlParameter("@contactId", contactId));
                        cmd.Parameters.Add(new SqlParameter("@CompanyId", companyId));
                        cmd.Parameters.Add(new SqlParameter("@LastSyncTime", (object)lastUpdateTime ?? DBNull.Value));

                        DataTable table = new DataTable();
                        table.Load(cmd.ExecuteReader());

                        List <LemHeader> list = table.Select().Select(r => new LemHeader
                        {
                            MatchId          = r.Field <int>("MatchId"),
                            CompanyId        = companyId,
                            LogDate          = r.Field <DateTime>("LogDate"),
                            LogStatus        = (EnumLogStatus)Enum.Parse(typeof(EnumLogStatus), $"{r["LogStatus"]}"),
                            ProjectId        = r.Field <int>("pri_ID"),
                            LemNum           = Convert.ToString(r["LemNum"]),
                            CreatorId        = r.Field <int>("LogCreatedBy"),
                            Description      = Convert.ToString(r["Description"]),
                            ApprovalComments = Convert.ToString(r["ApprovalComments"]),
                        }).ToList();

                        return(Ok(list));
                    }
                }
            }
            catch (Exception e)
            {
                SqlCommon.ReportInfo(e.Message);
                return(BadRequest(e.Message));
            }
        }
        public IHttpActionResult Get(int companyId, string clientMac, int contactId)
        {
            try
            {
                DateTime?lastUpdateTime = WebCommon.GetSyncTime(companyId, clientMac);

                DataSet ds = new DataSet();
                using (SqlConnection sqlcon = new SqlConnection(WebCommon.WebConnection))
                {
                    using (SqlDataAdapter da = new SqlDataAdapter())
                    {
                        da.SelectCommand = new SqlCommand("WS_FLEM_LEMLab_Get", sqlcon);
                        da.SelectCommand.Parameters.Add(new SqlParameter("@contactId", contactId));
                        da.SelectCommand.Parameters.Add(new SqlParameter("@CompanyId", companyId));
                        da.SelectCommand.Parameters.Add(new SqlParameter("@LastSyncTime", (object)lastUpdateTime ?? DBNull.Value));
                        da.SelectCommand.CommandType = CommandType.StoredProcedure;
                        da.Fill(ds, "Labour");

                        da.SelectCommand = new SqlCommand("WS_FLEM_LEMLabHrs_Get", sqlcon);
                        da.SelectCommand.Parameters.Add(new SqlParameter("@contactId", contactId));
                        da.SelectCommand.Parameters.Add(new SqlParameter("@CompanyId", companyId));
                        da.SelectCommand.Parameters.Add(new SqlParameter("@LastSyncTime", (object)lastUpdateTime ?? DBNull.Value));
                        da.SelectCommand.CommandType = CommandType.StoredProcedure;
                        da.Fill(ds, "LabourDetails");
                    }
                }

                List <LabourTimeEntry> list = ds.Tables["Labour"].Select().Select(r => new LabourTimeEntry
                {
                    MatchId       = (int)r["MatchId"],
                    CompanyId     = companyId,
                    HeaderId      = (int)r["HeaderMatchId"],
                    EmpNum        = (int)r["emp_no"],
                    ChangeOrderId = ConvertEx.ToNullable <int>(r["EstId"]),
                    Level1Id      = ConvertEx.ToNullable <int>(r["lv1_id"]),
                    Level2Id      = ConvertEx.ToNullable <int>(r["lv2_id"]),
                    Level3Id      = ConvertEx.ToNullable <int>(r["lv3_id"]),
                    Level4Id      = ConvertEx.ToNullable <int>(r["lv4_id"]),
                    Billable      = (bool)r["Billable"],
                    Manual        = ConvertEx.ToNullable <bool>(r["Manual"]) ?? false,
                    WorkClassCode = (string)r["wc_code"],
                    IncludedHours = ConvertEx.ToNullable <decimal>(r["IncludedHours"]),
                    TotalHours    = ConvertEx.ToNullable <decimal>(r["hrs_total"]),
                    BillAmount    = ConvertEx.ToNullable <decimal>(r["dollars_total"]),
                }).ToList();

                foreach (LabourTimeEntry entry in list)
                {
                    entry.DetailList = ds.Tables["LabourDetails"].Select().Where(x => (int)x["EntryMatchId"] == entry.MatchId).Select(d => new LabourTimeDetail
                    {
                        DetailId   = (int)d["id"],
                        CompanyId  = companyId,
                        EntryId    = entry.MatchId,
                        TimeCodeId = (int)d["time_code_id"],
                        BillRate   = ConvertEx.ToNullable <decimal>(d["BillRate"]),
                        WorkHours  = ConvertEx.ToNullable <decimal>(d["WorkHours"]),
                        Amount     = ConvertEx.ToNullable <decimal>(d["Amount"]),
                    }).ToList();
                }

                return(Ok(list));
            }
            catch (Exception e)
            {
                SqlCommon.ReportInfo(e.Message);
                return(BadRequest(e.Message));
            }
        }