public projectDetailTable GetEntityById(int Id)
        {
            SqlParameter param  = new SqlParameter("@detailID", Id);
            string       strSQL = "select * from [projectDetailTable] where detailID = @detailID ";

            System.Data.SqlClient.SqlDataReader dr;
            dr = SQLHelper.ExecuteReader(strSQL, param);
            try
            {
                projectDetailTable entity = new projectDetailTable();
                entity = SQLHelper.ReaderToList <projectDetailTable>(dr)[0];
                return(entity);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.StackTrace);
                return(null);
            }
            finally
            {
                if (!dr.IsClosed)
                {
                    dr.Close();
                }
            }
        }
 public bool updateDetailInfo(projectDetailTable entity)
 {
     if (entity.detailID > 0)
     {
         return(dal.SaveEntity(entity) > 0);
     }
     else
     {
         return(false);
     }
 }
        public int assignRepairMan(int projID, int rmID)
        {
            projectDetailTable entity = new projectDetailTable();

            entity.detailID    = -1;
            entity.projectID   = projID;
            entity.repairmanID = rmID;
            entity.faultStatus = 2;
            entity.severity    = 0;
            entity.faultType   = 0;
            if ((entity.detailID = dal.SaveEntity(entity)) > 1)
            {
                //projectTableDAL projDal = new projectTableDAO();
                projectTableDAL projDal    = new projectRepository();
                projectTable    projEntity = projDal.GetEntityById(entity.projectID.Value);
                projEntity.hasDetail = 1;
                entity.detailID      = projDal.SaveEntity(projEntity) > 0 ? entity.detailID : 0;
            }
            return(entity.detailID);
        }
Example #4
0
        private void getRepairInfoByID(int detailID)
        {
            projectDetailTable entity = detailBLL.getDetailInfoByID(detailID);

            if (entity != null)
            {
                tbProjectID.Text             = entity.projectID.ToString();
                viewProject.NavigateUrl      = Global.projectURL + "?projID=" + entity.projectID.ToString();
                tbRepairmanID.Text           = rmBLL.getRMinfoById(entity.repairmanID.Value).repairmanName;
                dateCreate.SelectedDate      = entity.createDate.Value;
                cmbFaultStatus.SelectedValue = entity.faultStatus.ToString();
                cmbFaultType.SelectedValue   = entity.faultType.ToString();
                cmbSeverity.SelectedValue    = entity.severity.ToString();
                tbFaultDetail.Text           = entity.faultDetail;
                tbAddRequirement.Text        = entity.add_requirement;
                if (entity.photos != null)
                {
                    ViewState["PhotoList"] = entity.photos; GridPhoto.Rebind();
                }
            }
        }
Example #5
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (isInterrupted)
            {
                return;
            }

            projectDetailTable entity = detailBLL.getDetailInfoByID(Convert.ToInt32(tbDetailID.Text));

            if (cmbFaultStatus.SelectedIndex > 0)
            {
                entity.faultStatus = Convert.ToInt32(cmbFaultStatus.SelectedValue);
            }
            if (cmbFaultType.SelectedIndex > 0)
            {
                entity.faultType = Convert.ToInt32(cmbFaultType.SelectedValue);
            }
            if (cmbSeverity.SelectedIndex > 0)
            {
                entity.severity = Convert.ToInt32(cmbSeverity.SelectedValue);
            }
            if (tbFaultDetail.Text != "")
            {
                entity.faultDetail = tbFaultDetail.Text;
            }
            if (tbAddRequirement.Text != "")
            {
                entity.add_requirement = tbAddRequirement.Text;
            }
            List <repairPhoto> newList    = new List <repairPhoto>();
            List <string>      fnList_old = entity.photos.Select(photo => photo.picName).ToList();

            foreach (UploadedFile uploadPic in RadAsyncUpload1.UploadedFiles)
            {
                repairPhoto pic = new repairPhoto();
                pic.detailID = entity.detailID;
                if (Session["CurrentRole"] != null && Session["CurrentLoginUser"] != null)
                {
                    pic.roleID = Convert.ToInt32(Session["CurrentRole"]);
                    if (pic.roleID == 1)
                    {
                        pic.userID = (Session["CurrentLoginUser"] as employeeTable).employeeID;
                    }
                    else if (pic.roleID == 0)
                    {
                        pic.userID = (Session["CurrentLoginUser"] as repairmanTable).repairmanID;
                    }
                }
                pic.picName = uploadPic.FileName;
                byte[] fileData = new byte[uploadPic.InputStream.Length];
                uploadPic.InputStream.Read(fileData, 0, (int)uploadPic.InputStream.Length);
                pic.picData      = fileData;
                pic.deleteStatus = 1;
                if (!fnList_old.Contains(pic.picName))
                {
                    newList.Add(pic);
                }
            }
            entity.photos = newList;
            //if (entity.photos == null) entity.photos = newList;
            //else
            //{
            //    foreach (var existPhoto in entity.photos)
            //    {
            //        if (newList.Contains(existPhoto)) continue;
            //        else existPhoto.deleteStatus = 0;
            //    }
            //    //newList = newList.Except(entity.photos).ToList(); //取差集
            //    entity.photos = newList.Union(entity.photos).ToList(); //剔除重复项
            //}

            if (detailBLL.updateDetailInfo(entity))
            {
                RadAjaxManager1.Alert("更新成功");
                setInputEnable(false);
                getRepairInfoByID(entity.detailID);
            }
            else
            {
                RadAjaxManager1.Alert("更新失败");
            }
        }
Example #6
0
        public int SaveEntity(projectDetailTable entity)
        {
            if (entity.detailID == -1)
            {
                entity.detailID     = 1 + MongoHelper.GetMaxId(collection);
                entity.createDate   = DateTime.Now;
                entity.deleteStatus = 1;
                try
                {
                    collection.InsertOne(entity);
                    GridFSUploadOptions options;
                    if (entity.photos != null)
                    {
                        foreach (repairPhoto pic in entity.photos)
                        {
                            options = new GridFSUploadOptions
                            {
                                Metadata = new BsonDocument {
                                    { "detailID", pic.detailID },
                                    { "uploadUser", new BsonDocument {
                                          { "role", pic.roleID }, { "user", pic.userID }
                                      } },
                                    { "deleteStatus", 1 }
                                }
                            };
                            pic.picID = MongoHelper.StorePicture(photosBucketName, pic.picName, pic.picData, options);
                        }
                    }
                    return(entity.detailID);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    System.Diagnostics.Debug.WriteLine(e.StackTrace);
                    return(0);
                }
            }
            else
            {
                var idFilter = Builders <projectDetailTable> .Filter.Eq(p => p.detailID, entity.detailID);

                var updateResult = collection.UpdateOne(idFilter,
                                                        Builders <projectDetailTable> .Update.Set("projectID", entity.projectID)
                                                        .Set("repairmanID", entity.repairmanID)
                                                        .Set("severity", entity.severity)
                                                        .Set("faultType", entity.faultType)
                                                        .Set("faultStatus", entity.faultStatus)
                                                        .Set("faultDetail", entity.faultDetail)
                                                        .Set("add_requirement", entity.add_requirement)
                                                        //.Set("createDate", entity.createDate)
                                                        .Set("updateDate", DateTime.Now)
                                                        //.Set("deleteStatus", entity.deleteStatus)
                                                        );
                if (!updateResult.IsAcknowledged || updateResult.ModifiedCount == 0)
                {
                    return(0);
                }
                else
                {
                    GridFSUploadOptions options;
                    foreach (repairPhoto pic in entity.photos)
                    {
                        options = new GridFSUploadOptions
                        {
                            Metadata = new BsonDocument {
                                { "detailID", pic.detailID },
                                { "uploadUser", new BsonDocument {
                                      { "role", pic.roleID }, { "user", pic.userID }
                                  } },
                                { "deleteStatus", 1 }
                            }
                        };
                        pic.picID = MongoHelper.StorePicture(photosBucketName, pic.picName, pic.picData, options);
                    }
                    return(1);
                }
            }
        }
        public int SaveEntity(projectDetailTable entity)
        {
            List <SqlParameter> paramList = new List <SqlParameter>();
            var detailID_parameter        = new SqlParameter("@detailID", SqlDbType.Int);

            if (entity.detailID > 0)
            {
                detailID_parameter.Value = entity.detailID;
            }
            else
            {
                detailID_parameter.Value = DBNull.Value;
            }
            var projectID_parameter = new SqlParameter("@projectID", entity.projectID);

            paramList.Add(projectID_parameter);
            var repairmanID_parameter = new SqlParameter("@repairmanID", entity.repairmanID);

            paramList.Add(repairmanID_parameter);
            var severity_parameter = new SqlParameter("@severity", entity.severity);

            paramList.Add(severity_parameter);
            var faultType_parameter = new SqlParameter("@faultType", entity.faultType);

            paramList.Add(faultType_parameter);
            var faultStatus_parameter = new SqlParameter("@faultStatus", entity.faultStatus);

            paramList.Add(faultStatus_parameter);
            SqlParameter faultDetail_parameter = new SqlParameter("@faultDetail", entity.faultDetail);

            if (string.IsNullOrEmpty(entity.faultDetail))
            {
                faultDetail_parameter.Value = DBNull.Value;
            }
            paramList.Add(faultDetail_parameter);
            SqlParameter add_requirement_parameter = new SqlParameter("@add_requirement", entity.add_requirement);

            if (string.IsNullOrEmpty(entity.add_requirement))
            {
                add_requirement_parameter.Value = DBNull.Value;
            }
            paramList.Add(add_requirement_parameter);
            string       sql = "";
            SqlParameter identityParameter = new SqlParameter("@IdentityId", SqlDbType.Int);

            if (entity.detailID == -1)
            {
                identityParameter.Direction = ParameterDirection.Output;
                paramList.Add(identityParameter);
                sql  = "insert into projectDetailTable(projectID,repairmanID,severity,faultType,faultStatus,faultDetail,add_requirement,createDate,deleteStatus) ";
                sql += "values(@projectID,@repairmanID,@severity,@faultType,@faultStatus,@faultDetail,@add_requirement,GETDATE(),1) Select @IdentityId = @@identity  ";
            }
            else
            {
                paramList.Add(detailID_parameter);
                sql = "update projectDetailTable set projectID = @projectID,repairmanID = @repairmanID,severity = @severity,faultType = @faultType,faultStatus = @faultStatus,faultDetail = @faultDetail,add_requirement = @add_requirement,updateDate = GETDATE() where detailID =@detailID ";
            }
            int count = SQLHelper.ExecuteonQuery(sql, paramList.ToArray());

            return(entity.detailID > 0 ? count : (identityParameter == null ? -1 : Convert.ToInt32(identityParameter.Value)));
        }