示例#1
0
    public bool AddMeterReadout(string key, string userName, string meterReadoutObj, byte[] readoutImg)
    {
        string imgName = string.Empty;

        if (key != "6E5F0C851FD4")
        {
            return(false);
        }
        try
        {
            var entityReadout = JsonConvert.DeserializeObject <project.Entity.Op.EntityReadout>(meterReadoutObj);
            entityReadout.RowPointer = Guid.NewGuid().ToString();
            //表记资料
            var businessMeter = new project.Business.Base.BusinessMeter();
            businessMeter.load(entityReadout.MeterNo);
            if (businessMeter.Entity == null)
            {
                return(false);
            }
            entityReadout.RMID      = businessMeter.Entity.MeterRMID;
            entityReadout.MeterType = businessMeter.Entity.MeterType;
            entityReadout.MeteRate  = businessMeter.Entity.MeterRate;
            //抄表附带数据
            DataTable dt = obj.PopulateDataSet(string.Format("SELECT READERNO FROM Mstr_MeterReader WHERE READERNAME='{0}'", userName)).Tables[0];
            entityReadout.ROOperator   = dt.Rows.Count > 0 ? dt.Rows[0]["ReaderNo"].ToString() : "";
            entityReadout.ROCreateDate = GetDate();
            entityReadout.ROCreator    = userName;
            entityReadout.RODate       = GetDate();
            //图片处理
            if (readoutImg != null)
            {
                imgName = SaveReadoutImg(entityReadout.MeterNo, readoutImg);
            }
            entityReadout.Img = imgName;
            //数据保存
            var businessReadout = new project.Business.Op.BusinessReadout(entityReadout);
            if (businessReadout.Save("insert") > 0)
            {
                return(true);
            }
            else
            {
                if (!string.IsNullOrEmpty(imgName))
                {
                    string imgPath = ReadoutImgPath + imgName;
                    if (File.Exists(imgPath))
                    {
                        File.Delete(imgPath);
                    }
                }
            }
        }
        catch (Exception)
        {
            if (!string.IsNullOrEmpty(imgName))
            {
                string imgPath = ReadoutImgPath + imgName;
                if (File.Exists(imgPath))
                {
                    File.Delete(imgPath);
                }
            }
        }
        return(false);
    }
示例#2
0
    public bool UpdateMeterReadout(string key, string userName, string rowPointer, string meterReadoutObj, byte[] readoutImg)
    {
        string imgName    = string.Empty;
        string newImgName = string.Empty;

        if (key != "6E5F0C851FD4")
        {
            return(false);
        }
        try
        {
            var entityReadout   = JsonConvert.DeserializeObject <project.Entity.Op.EntityReadout>(meterReadoutObj);
            var businessReadout = new project.Business.Op.BusinessReadout();
            businessReadout.load(rowPointer);
            if (string.IsNullOrEmpty(businessReadout.Entity.RowPointer))
            {
                return(false);
            }
            //数据填充
            imgName = businessReadout.Entity.Img;
            businessReadout.Entity.ReadoutType  = entityReadout.ReadoutType;
            businessReadout.Entity.LastReadout  = entityReadout.LastReadout;
            businessReadout.Entity.Readout      = entityReadout.Readout;
            businessReadout.Entity.JoinReadings = entityReadout.JoinReadings;
            businessReadout.Entity.Readings     = entityReadout.Readings;
            DataTable dt = obj.PopulateDataSet(string.Format("SELECT READERNO FROM Mstr_MeterReader WHERE READERNAME='{0}'", userName)).Tables[0];
            businessReadout.Entity.ROOperator = dt.Rows.Count > 0 ? dt.Rows[0]["ReaderNo"].ToString() : "";
            businessReadout.Entity.RODate     = GetDate();
            //图片处理
            if (readoutImg != null)
            {
                newImgName = SaveReadoutImg(businessReadout.Entity.MeterNo, readoutImg);
            }
            if (!string.IsNullOrEmpty(newImgName))
            {
                businessReadout.Entity.Img = newImgName;
            }
            //保存
            if (businessReadout.Save("update") > 0)
            {
                //删除旧图片
                if (!string.IsNullOrEmpty(newImgName))
                {
                    string imgPath = ReadoutImgPath + imgName;
                    if (File.Exists(imgPath))
                    {
                        File.Delete(imgPath);
                    }
                }
                return(true);
            }
            else
            {
                //删除新图片
                if (!string.IsNullOrEmpty(newImgName))
                {
                    string imgPath = ReadoutImgPath + newImgName;
                    if (File.Exists(imgPath))
                    {
                        File.Delete(imgPath);
                    }
                }
            }
        }
        catch (Exception)
        {
            //删除新图片
            if (!string.IsNullOrEmpty(newImgName))
            {
                string imgPath = ReadoutImgPath + newImgName;
                if (File.Exists(imgPath))
                {
                    File.Delete(imgPath);
                }
            }
        }
        return(false);
    }
示例#3
0
    public string MeterReadout(string MeterNo, string ReadoutType, decimal LastReadout, decimal Readout,
                               decimal JoinReadings, decimal Readings, string UserName, string KEY, byte[] ImgByte)
    {
        if (KEY != "6E5F0C851FD4")
        {
            return("");
        }

        string InfoMsg = "";
        string imgName = MeterNo + "-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg";
        string imgPath = ReadoutImgPath + imgName;

        try
        {
            if (ImgByte != null)
            {
                SaveReadoutImg(MeterNo, imgName, ImgByte);                 //保存图片
            }
            else
            {
                imgName = string.Empty;
            }

            project.Business.Op.BusinessReadout bc = new project.Business.Op.BusinessReadout();
            string id = Guid.NewGuid().ToString();
            bc.Entity.RowPointer = id;
            bc.Entity.MeterNo    = MeterNo;

            string isOk = "1";
            try
            {
                project.Business.Base.BusinessMeter bm = new project.Business.Base.BusinessMeter();
                bm.load(MeterNo);
                bc.Entity.RMID      = bm.Entity.MeterRMID;
                bc.Entity.MeterType = bm.Entity.MeterType;
                bc.Entity.MeteRate  = bm.Entity.MeterRate;
            }
            catch
            {
                isOk    = "0";
                InfoMsg = "当前表记未找到!";
                DelReadoutImg(imgPath);
            }

            if (isOk == "1")
            {
                bc.Entity.ReadoutType  = ReadoutType;
                bc.Entity.LastReadout  = LastReadout;
                bc.Entity.Readout      = Readout;
                bc.Entity.JoinReadings = JoinReadings;
                bc.Entity.Readings     = Readings;
                DataTable tempDt = obj.PopulateDataSet(string.Format("SELECT READERNO FROM Mstr_MeterReader WHERE READERNAME='{0}'", UserName)).Tables[0];
                bc.Entity.ROOperator   = tempDt.Rows.Count > 0 ? tempDt.Rows[0]["ReaderNo"].ToString() : "";
                bc.Entity.RODate       = GetDate();
                bc.Entity.Img          = imgName;
                bc.Entity.ROCreateDate = GetDate();
                bc.Entity.ROCreator    = UserName;

                //获取换表记录 [换表记录已审核,并没有被抄表引用]
                DataTable dt = obj.PopulateDataSet("select RowPointer,OldMeterReadings from Op_ChangeMeter " +
                                                   "where AuditStatus='1' and NewMeterNo='" + bc.Entity.MeterNo + "' " +
                                                   "and RowPointer not in (select ChangeID from Op_Readout_ChangeList)").Tables[0];
                if (dt.Rows.Count > 0)
                {
                    bc.Entity.IsChange = true;
                    decimal OldMeterReadings = 0;

                    //考虑多次换表的情况
                    foreach (DataRow dr in dt.Rows)
                    {
                        OldMeterReadings += ParseDecimalForString(dr["OldMeterReadings"].ToString());
                    }
                    bc.Entity.OldMeterReadings = OldMeterReadings;
                }
                else
                {
                    bc.Entity.IsChange         = false;
                    bc.Entity.OldMeterReadings = 0;
                }

                int r = bc.Save("insert");
                if (r <= 0)
                {
                    DelReadoutImg(imgPath);
                    InfoMsg = "抄表写入失败!";
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        obj.ExecuteNonQuery("insert into Op_Readout_ChangeList(RowPointer,RefRP,ChangeID) values(newid(),'" + id + "','" + dr["RowPointer"].ToString() + "')");
                    }
                }
            }
        }
        catch (Exception ex)
        {
            DelReadoutImg(imgPath);
            InfoMsg = ex.Message;
        }

        return(InfoMsg);
    }