Пример #1
0
        /// <summary>
        /// 导入Excel表格
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static bool ImportExcel(string filePath, string type)
        {
            Equipment  eq;
            FileStream fileStream = new FileStream(@filePath, FileMode.Open);

            try
            {
                using (ExcelPackage package = new ExcelPackage(fileStream))
                {
                    for (int index = 1; index <= package.Workbook.Worksheets.Count; index++)
                    {
                        ExcelWorksheet sheet = package.Workbook.Worksheets[index];

                        for (int srow = sheet.Dimension.Start.Row + 1, erow = sheet.Dimension.End.Row; srow <= erow; srow++)
                        {
                            List <string> list = new List <string> {
                            };
                            for (int scolumn = sheet.Dimension.Start.Column, ecolumn = sheet.Dimension.End.Column; scolumn <= ecolumn; scolumn++)
                            {
                                if (sheet.GetValue <string>(srow, scolumn) != null)
                                {
                                    list.Add(sheet.GetValue <string>(srow, scolumn));
                                }

                                else
                                {
                                    list.Add("");
                                }
                            }
                            eq = EqMgr.SetEq(list);
                            EqMgr.Add(eq);
                        }
                    }
                }

                fileStream.Close();
                return(true);
            }
            catch (Exception e)
            {
                fileStream.Close();
                return(false);
            }
        }
Пример #2
0
        //保存修改的信息
        private void toolEqUpdate_Click(object sender, EventArgs e)
        {
            if (this.checkInput())
            {
                Equipment eq = new Equipment();
                eq.EqNo       = this.txtEqNo.Text;
                eq.EqName     = this.txtEqName.Text;
                eq.AssetNo    = this.txtAssetNo.Text;
                eq.EduNo      = this.txtEduNo.Text;
                eq.EqType     = this.cbxEqType.Text;
                eq.Gb         = this.txtGB.Text;
                eq.Usage      = this.cbxUsage.Text;
                eq.Unit       = this.cbxUnit.Text;
                eq.Direction  = this.cbxDirection.Text;
                eq.BuyWay     = this.cbxBuyWay.Text;
                eq.GetWay     = this.cbxGetWay.Text;
                eq.Purchaser  = this.cbxPurchaser.Text;
                eq.Agent      = this.txtAgent.Text;
                eq.Brand      = this.txtBrand.Text;
                eq.Model      = this.txtModel.Text;
                eq.Country    = this.txtCountry.Text;
                eq.Mfrs       = this.txtMfrs.Text;
                eq.ProductNo  = this.txtProductNo.Text;
                eq.Supplier   = this.txtSupplier.Text;
                eq.PriceType  = this.cbxPriceType.Text;
                eq.EqKeeper   = this.cbxEqKeeper.Text;
                eq.Department = DepartMgr.GetIdFromName(this.txtDepartment.Text);
                eq.Campus     = this.cbxCampus.Text;
                eq.KeepPlace  = this.cbxKeepPlace.Text;
                eq.Cn         = this.txtCN.Text;
                eq.InvNo      = this.txtInvNo.Text;
                eq.Funds      = this.cbxFunds.Text;
                eq.BelongTo   = "";
                eq.Photo      = "";
                eq.Remark     = this.txtRemark.Text;

                eq.Photo = this.getPhotoPath();


                if (this.dtpGetDate.Checked == true)
                {
                    eq.GetDate = this.dtpGetDate.Value.ToShortDateString();
                }
                else
                {
                    eq.GetDate = "";
                }

                if (dtpAddDate.Checked == true)
                {
                    eq.AddDate = this.dtpAddDate.Value.ToShortDateString();
                }
                else
                {
                    eq.AddDate = "";
                }

                if (this.dtpBirthday.Checked == true)
                {
                    eq.Birthday = this.dtpBirthday.Value.ToShortDateString();
                }
                else
                {
                    eq.Birthday = "";
                }

                if (this.dtpSvcDate.Checked == true)
                {
                    eq.SvcDate = this.dtpSvcDate.Value.ToShortDateString();
                }
                else
                {
                    eq.SvcDate = "";
                }
                /*****************************根据资产类别判断所要填的项********************************************/
                //资产类别为“土地、房屋及构筑物”时
                if (eq.EqType == "土地、房屋及构筑物")
                {
                    eq.Pr         = this.cbxPR.Text;
                    eq.Address    = this.txtAddress.Text;
                    eq.CertNature = this.cbxCertNature.Text;
                    eq.Structure  = this.cbxStructure.Text;

                    //有产权时以下四项才可以被填写
                    if (eq.Pr == "有产权")
                    {
                        if (this.txtCertNo.Text.Trim() == "")
                        {
                            untCommon.InfoMsg("请输入权属证号");
                            return;
                        }
                        else
                        {
                            eq.CertNo = this.txtCertNo.Text;
                        }

                        if (this.dtpIssueDate.Checked == false)
                        {
                            untCommon.InfoMsg("请选择发证日期");
                            return;
                        }
                        else
                        {
                            eq.IssueDate = this.dtpIssueDate.Value.ToShortDateString();
                        }

                        if (this.txtCertProve.Text.Trim() == "")
                        {
                            untCommon.InfoMsg("请输入权属证明");
                            return;
                        }
                        else
                        {
                            eq.CertProve = this.txtCertProve.Text;
                        }

                        try
                        {
                            eq.CertLim = int.Parse(this.txtCertLim.Text);
                        }
                        catch (FormatException)
                        {
                            untCommon.ErrorMsg("权属年限请输入数字。");
                            return;
                        }
                    }
                    else
                    {
                        eq.CertNo    = "";
                        eq.IssueDate = "";
                        eq.CertProve = "";
                        eq.CertLim   = 0;
                    }
                    try
                    {
                        eq.Area = double.Parse(this.txtArea.Text);
                    }
                    catch (FormatException)
                    {
                        untCommon.ErrorMsg("建筑/土地面积请输入数字。");
                        return;
                    }

                    try
                    {
                        eq.TenuArea = double.Parse(this.txtTenuArea.Text);
                    }
                    catch (FormatException)
                    {
                        untCommon.ErrorMsg("自用面积请输入数字。");
                        return;
                    }

                    try
                    {
                        eq.TenuPrice = double.Parse(this.txtTenuPrice.Text);
                    }
                    catch (FormatException)
                    {
                        untCommon.ErrorMsg("自用价值请输入数字。");
                        return;
                    }
                }
                else
                {
                    eq.Pr         = "";
                    eq.CertNo     = "";
                    eq.IssueDate  = "";
                    eq.CertProve  = "";
                    eq.Address    = "";
                    eq.CertNature = "";
                    eq.Structure  = "";
                    eq.Area       = 0;
                    eq.TenuArea   = 0;
                    eq.TenuPrice  = 0;
                    eq.CertLim    = 0;
                }

                //资产类别为"通用设备(车辆)"
                if (eq.EqType == "通用设备(车辆)")
                {
                    eq.CarUse    = this.cbxCarUse.Text;
                    eq.CarBP     = this.cbxCarBP.Text;
                    eq.LicNo     = this.txtLicNo.Text;
                    eq.Dspl      = this.txtDSPL.Text;
                    eq.EngNo     = this.txtEngNo.Text;
                    eq.Formation = this.cbxFormation.Text;
                }
                else
                {
                    eq.CarUse    = "";
                    eq.CarBP     = "";
                    eq.LicNo     = "";
                    eq.Dspl      = "";
                    eq.EngNo     = "";
                    eq.Formation = "";
                }

                //资产类别为"无形资产"
                if (eq.EqType == "无形资产")
                {
                    eq.RegAuz    = this.txtRegAuz.Text;
                    eq.PatNo     = this.txtPatNo.Text;
                    eq.ApvNo     = this.txtApvNo.Text;
                    eq.MgtAgency = this.txtMgtAgency.Text;

                    if (this.dtpRegTime.Checked == true)
                    {
                        eq.RegTime = this.dtpRegTime.Value.ToShortDateString();
                    }
                    else
                    {
                        eq.RegTime = "";
                    }
                }
                else
                {
                    eq.RegAuz    = "";
                    eq.RegTime   = "";
                    eq.PatNo     = "";
                    eq.ApvNo     = "";
                    eq.MgtAgency = "";
                }
                //资产类别为"文物和陈列品"
                if (eq.EqType == "文物和陈列品")
                {
                    eq.RelicLv = this.cbxRelicLv.Text;
                }
                else
                {
                    eq.RelicLv = "";
                }


                /*************************************判断结束******************************************************/
                try
                {
                    count = int.Parse(this.txtCount.Text);
                }
                catch (FormatException)
                {
                    untCommon.ErrorMsg("数量请输入数字。");
                    return;
                }
                try
                {
                    eq.Price = double.Parse(this.txtPrice.Text);
                }
                catch (FormatException)
                {
                    untCommon.ErrorMsg("价值请输入数字。");
                    return;
                }

                try
                {
                    if (this.txtUSDPrice.Text.Trim() != "")
                    {
                        eq.UsdPrice = double.Parse(this.txtUSDPrice.Text);
                    }
                    else
                    {
                        eq.UsdPrice = 0;
                    }
                }
                catch (FormatException)
                {
                    untCommon.ErrorMsg("美金单价请输入数字。");
                    return;
                }

                //判断更新模式
                switch (this.mode)
                {
                case 0:
                    this.DialogResult = DialogResult.OK;
                    break;

                //直接修改
                case 1:
                {
                    int error = 0;
                    //0级和1级用户直接更新
                    if (_power == "0" || _power == "1")
                    {
                        foreach (string field in eqnoList)
                        {
                            eq.EqNo  = field;
                            eq.State = "入库";
                            if (EqMgr.Update(eq))
                            {
                                //
                            }
                            else
                            {
                                error++;
                            }
                        }
                        if (error == 0)
                        {
                            untCommon.InfoMsg("更新成功");
                            this.DialogResult = DialogResult.OK;
                            this.Close();
                        }
                        else
                        {
                            untCommon.InfoMsg("操作失败,失败数目为:" + error.ToString());
                            this.DialogResult = DialogResult.OK;
                            this.Close();
                        }
                    }
                    else
                    {
                        DataTable Empdt = EmployeeMgr.GetAllName();
                        foreach (string field in eqnoList)
                        {
                            eq.EqNo  = "U" + this.Loginid + DateTime.Now.ToString("yyyyMMddHHmmss") + field;
                            eq.State = "更新待审核";
                            if (EqMgr.Add(eq))
                            {
                                //
                            }
                            else
                            {
                                error++;
                            }
                        }
                        if (error == 0)
                        {
                            untCommon.InfoMsg("更新成功,请等待审核");
                            this.DialogResult = DialogResult.OK;
                            this.Close();
                        }
                        else
                        {
                            untCommon.InfoMsg("操作失败,失败数目为:" + error.ToString());
                            this.DialogResult = DialogResult.OK;
                            this.Close();
                        }
                    }

                    break;
                }


                //直接批量修改
                case 2:
                {
                    string question = "确定要更改这单数量为: ";
                    question += EqMgr.AssetCount(this.asset).ToString() + " 的资产吗?";
                    if (untCommon.QuestionMsg(question))
                    {
                        if (_power == "0" || _power == "1")
                        {
                            eq.State = "入库";

                            if (EqMgr.UpdateByAsset(eq, asset))
                            {
                                untCommon.InfoMsg("更新成功");
                                this.DialogResult = DialogResult.OK;
                                this.Close();
                            }
                            else
                            {
                                untCommon.InfoMsg("更新失败。");
                                this.DialogResult = DialogResult.OK;
                                this.Close();
                            }
                        }
                        else
                        {
                            List <string> list  = EqMgr.GetEqNoByAssetNo(this.asset);
                            DataTable     Empdt = EmployeeMgr.GetAllName();
                            int           error = 0;
                            if (list != null)
                            {
                                foreach (string field in list)
                                {
                                    eq.EqNo  = "U" + this.name2ID(Empdt, this._user, "name") + DateTime.Now.ToString("yyyyMMddHHmmss") + field;
                                    eq.State = "更新待审核";
                                    if (EqMgr.Add(eq))
                                    {
                                    }
                                    else
                                    {
                                        error++;
                                    }
                                }
                            }
                            if (error == 0)
                            {
                                untCommon.InfoMsg("更新信息提交成功,请等待审核");
                                this.DialogResult = DialogResult.OK;
                                this.Close();
                            }
                            else
                            {
                                untCommon.InfoMsg("更新信息发生错误\n" + "失败数为: " + error.ToString());
                                this.DialogResult = DialogResult.OK;
                                this.Close();
                            }
                        }
                    }


                    break;
                }

                //从新增审核处修改
                case 3:
                {
                    eq.State = "新增待审核";
                    if (EqMgr.UpdateByAsset(eq, asset))
                    {
                        untCommon.InfoMsg("更新信息提交成功,请等待审核");
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                    else
                    {
                        untCommon.InfoMsg("更新失败。");
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                    break;
                }

                //从更新审核处修改
                case 4:
                {
                    int       error = 0;
                    DataTable Empdt = EmployeeMgr.GetAllName();
                    foreach (string field in eqnoList)
                    {
                        eq.EqNo  = field;
                        eq.State = "更新待审核";
                        if (EqMgr.Update(eq))
                        {
                            //
                        }
                        else
                        {
                            error++;
                        }
                    }

                    if (error == 0)
                    {
                        untCommon.InfoMsg("更新成功,请等待审核");
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                    else
                    {
                        untCommon.InfoMsg("操作失败,失败数目为:" + error.ToString());
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                    break;
                }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 添加资产
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolEqAdd_Click(object sender, EventArgs e)
        {
            if (this.checkInput())
            {
                this.SetNo();        //生成随机编号
                int       error = 0; //错误标志
                Equipment eq    = new Equipment();
                eq.EqName     = this.txtEqName.Text;
                eq.EduNo      = this.txtEduNo.Text;
                eq.EqType     = this.cbxEqType.Text;
                eq.Gb         = this.txtGB.Text;
                eq.Usage      = this.cbxUsage.Text;
                eq.Unit       = this.cbxUnit.Text;
                eq.Direction  = this.cbxDirection.Text;
                eq.BuyWay     = this.cbxBuyWay.Text;
                eq.GetWay     = this.cbxGetWay.Text;
                eq.Purchaser  = this.cbxPurchaser.Text;
                eq.Agent      = this.txtAgent.Text;
                eq.Brand      = this.txtBrand.Text;
                eq.Model      = this.txtModel.Text;
                eq.Country    = this.txtCountry.Text;
                eq.Mfrs       = this.txtMfrs.Text;
                eq.ProductNo  = this.txtProductNo.Text;
                eq.Supplier   = this.txtSupplier.Text;
                eq.PriceType  = this.cbxPriceType.Text;
                eq.EqKeeper   = this.cbxEqKeeper.Text;
                eq.Department = DepartMgr.GetIdFromName(this.txtDepartment.Text);
                eq.Campus     = this.cbxCampus.Text;
                eq.KeepPlace  = this.cbxKeepPlace.Text;
                eq.Cn         = this.txtCN.Text;
                eq.InvNo      = this.txtInvNo.Text;
                eq.Funds      = this.cbxFunds.Text;
                eq.BelongTo   = "";
                eq.Photo      = this.photoPath;
                eq.Remark     = this.txtRemark.Text;

                if (this.dtpGetDate.Checked == true)
                {
                    eq.GetDate = this.dtpGetDate.Value.ToShortDateString();
                }
                else
                {
                    eq.GetDate = "";
                }

                if (dtpAddDate.Checked == true)
                {
                    eq.AddDate = this.dtpAddDate.Value.ToShortDateString();
                }
                else
                {
                    eq.AddDate = "";
                }

                if (this.dtpBirthday.Checked == true)
                {
                    eq.Birthday = this.dtpBirthday.Value.ToShortDateString();
                }
                else
                {
                    eq.Birthday = "";
                }

                if (this.dtpSvcDate.Checked == true)
                {
                    eq.SvcDate = this.dtpSvcDate.Value.ToShortDateString();
                }
                else
                {
                    eq.SvcDate = "";
                }
                /*****************************根据资产类别判断所要填的项********************************************/
                //资产类别为“土地、房屋及构筑物”时
                if (eq.EqType == "土地、房屋及构筑物")
                {
                    eq.Pr         = this.cbxPR.Text;
                    eq.Address    = this.txtAddress.Text;
                    eq.CertNature = this.cbxCertNature.Text;
                    eq.Structure  = this.cbxStructure.Text;

                    //有产权时以下四项才可以被填写
                    if (eq.Pr == "有产权")
                    {
                        if (this.txtCertNo.Text.Trim() == "")
                        {
                            untCommon.InfoMsg("请输入权属证号");
                            return;
                        }
                        else
                        {
                            eq.CertNo = this.txtCertNo.Text;
                        }

                        if (this.dtpIssueDate.Checked == false)
                        {
                            untCommon.InfoMsg("请选择发证日期");
                            return;
                        }
                        else
                        {
                            eq.IssueDate = this.dtpIssueDate.Value.ToShortDateString();
                        }

                        if (this.txtCertProve.Text.Trim() == "")
                        {
                            untCommon.InfoMsg("请输入权属证明");
                            return;
                        }
                        else
                        {
                            eq.CertProve = this.txtCertProve.Text;
                        }

                        try
                        {
                            eq.CertLim = int.Parse(this.txtCertLim.Text);
                        }
                        catch (FormatException)
                        {
                            untCommon.ErrorMsg("权属年限请输入数字。");
                            return;
                        }
                    }
                    else
                    {
                        eq.CertNo    = "";
                        eq.IssueDate = "";
                        eq.CertProve = "";
                        eq.CertLim   = 0;
                    }
                    try
                    {
                        eq.Area = double.Parse(this.txtArea.Text);
                    }
                    catch (FormatException)
                    {
                        untCommon.ErrorMsg("建筑/土地面积请输入数字。");
                        return;
                    }

                    try
                    {
                        eq.TenuArea = double.Parse(this.txtTenuArea.Text);
                    }
                    catch (FormatException)
                    {
                        untCommon.ErrorMsg("自用面积请输入数字。");
                        return;
                    }

                    try
                    {
                        eq.TenuPrice = double.Parse(this.txtTenuPrice.Text);
                    }
                    catch (FormatException)
                    {
                        untCommon.ErrorMsg("自用价值请输入数字。");
                        return;
                    }
                }
                else
                {
                    eq.Pr         = "";
                    eq.CertNo     = "";
                    eq.IssueDate  = "";
                    eq.CertProve  = "";
                    eq.Address    = "";
                    eq.CertNature = "";
                    eq.Structure  = "";
                    eq.Area       = 0;
                    eq.TenuArea   = 0;
                    eq.TenuPrice  = 0;
                    eq.CertLim    = 0;
                }

                //资产类别为"通用设备(车辆)"
                if (eq.EqType == "通用设备(车辆)")
                {
                    eq.CarUse    = this.cbxCarUse.Text;
                    eq.CarBP     = this.cbxCarBP.Text;
                    eq.LicNo     = this.txtLicNo.Text;
                    eq.Dspl      = this.txtDSPL.Text;
                    eq.EngNo     = this.txtEngNo.Text;
                    eq.Formation = this.cbxFormation.Text;
                }
                else
                {
                    eq.CarUse    = "";
                    eq.CarBP     = "";
                    eq.LicNo     = "";
                    eq.Dspl      = "";
                    eq.EngNo     = "";
                    eq.Formation = "";
                }

                //资产类别为"无形资产"
                if (eq.EqType == "无形资产")
                {
                    eq.RegAuz    = this.txtRegAuz.Text;
                    eq.PatNo     = this.txtPatNo.Text;
                    eq.ApvNo     = this.txtApvNo.Text;
                    eq.MgtAgency = this.txtMgtAgency.Text;

                    if (this.dtpRegTime.Checked == true)
                    {
                        eq.RegTime = this.dtpRegTime.Value.ToShortDateString();
                    }
                    else
                    {
                        eq.RegTime = "";
                    }
                }
                else
                {
                    eq.RegAuz    = "";
                    eq.RegTime   = "";
                    eq.PatNo     = "";
                    eq.ApvNo     = "";
                    eq.MgtAgency = "";
                }
                //资产类别为"文物和陈列品"
                if (eq.EqType == "文物和陈列品")
                {
                    eq.RelicLv = this.cbxRelicLv.Text;
                }
                else
                {
                    eq.RelicLv = "";
                }


                /*************************************判断结束******************************************************/
                try
                {
                    count = int.Parse(this.txtCount.Text);
                }
                catch (FormatException)
                {
                    untCommon.ErrorMsg("数量请输入数字。");
                    return;
                }
                try
                {
                    eq.Price = double.Parse(this.txtPrice.Text);
                }
                catch (FormatException)
                {
                    untCommon.ErrorMsg("价值请输入数字。");
                    return;
                }

                try
                {
                    if (this.txtUSDPrice.Text.Trim() != "")
                    {
                        eq.UsdPrice = double.Parse(this.txtUSDPrice.Text);
                    }
                    else
                    {
                        eq.UsdPrice = 0;
                    }
                }
                catch (FormatException)
                {
                    untCommon.ErrorMsg("美金单价请输入数字。");
                    return;
                }

                if (_power == "0" || _power == "1")
                {
                    int tempCount  = EqMgr.getTempAssetCount();
                    int allCount   = EqMgr.getAllAssetCount();
                    int eqCount    = EqMgr.getAllEqCount();
                    int assetCount = allCount - tempCount + 1;
                    eq.State = "入库";
                    for (int j = 1; j <= count; j++)
                    {
                        eq.EqNo    = DateTime.Now.Year.ToString() + string.Format("{0:D6}", eqCount + j);
                        eq.AssetNo = SysUserMgr.GetDepartmentIDByUser(this._user) + DateTime.Now.Year.ToString() + string.Format("{0:D4}", assetCount);
                        if (EqMgr.Add(eq))
                        {
                            /*if (!SqlFileMgr.PhotoAdd(eq.EqNo, photoPath))
                             *  error++;
                             * if (!WriteAttachment(eq.EqNo))
                             *  error++;*/
                        }
                        else
                        {
                            error++;
                        }
                    }
                }
                else
                {
                    for (int i = 1; i <= count; i++)
                    {
                        eq.EqNo    = "TE" + random + string.Format("{0:000}", i);
                        eq.AssetNo = "TA" + random + string.Format("{0:000}", count);
                        eq.State   = "新增待审核";
                        //if (this.pbPhoto.Image != null)
                        //photoPath = this.pbPhoto.ImageLocation;
                        if (EqMgr.Add(eq))
                        {
                            /*if (!SqlFileMgr.PhotoAdd(eq.EqNo, photoPath))
                             *  error++;
                             * if (!WriteAttachment(eq.EqNo))
                             *  error++;*/
                        }
                        else
                        {
                            error++;
                        }
                    }
                }

                if (error == 0)
                {
                    untCommon.InfoMsg("添加成功");
                    ClearInput();
                    this.SetNo();
                    this.Close();
                }
                else
                {
                    untCommon.InfoMsg("错误数目:" + error.ToString());
                    this.SetNo();
                }
            }
        }