예제 #1
0
 public InMemoryIn PeekValue()
 {
     var result = new InMemoryIn();
     result.CatalogId = catalog.SelectedValue.None() ? (Guid?)null : catalog.SelectedValue.GlobalId();
     result.ObjectId = obj.SelectedValue == null || obj.Text.None() ? (Guid?)null : obj.SelectedValue.GlobalId();
     result.Amount = amount.Value.HasValue ? (decimal)amount.Value.Value : (decimal?)null;
     result.PriceSet = priceSet.Value.HasValue ? (decimal)priceSet.Value.Value : (decimal?)null;
     result.Money = money.Value.HasValue ? (decimal)money.Value.Value : (decimal?)null;
     result.Age = age.Text;
     result.Place = place.Text;
     result.Note = note.Text;
     result.ResponsibleId = people.SelectedValue.None() ? (Guid?)null : people.SelectedValue.GlobalId();
     return result;
 }
예제 #2
0
    protected void im_ok_Click(object sender, EventArgs e)
    {
        try
        {
            var book = new Workbook(file.Value);
            var data = book.Worksheets[0].Cells.ExportDataTableAsString(0, 0, book.Worksheets[0].Cells.Rows.Where(o => o[0].Value != null && o[0].Value.ToString().Trim() != "").Count(), 16, true);
            var handled = new DataTable();
            foreach (var index in new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 })
            {
                handled.Columns.Add(data.Columns[index].ColumnName);
            }
            foreach (DataRow row in data.Rows)
            {
                var _row = handled.NewRow();
                foreach (DataColumn col in handled.Columns)
                {
                    _row[col.ColumnName] = row[col.ColumnName];
                }
                handled.Rows.Add(_row);
            }
            if (handled.Rows.Count > 0)
            {
                var 固定资产库Id = Depot.Id;
                var 固定资产库购置单Id = DataContext.GlobalId();

                DataContext.DepotOrderAdd(固定资产库购置单Id, 固定资产库Id, "固定资产导入_{0}".Formatted(DateTime.Now.ToString("yyyyMMddHHmmss")), "导入", "导入", "导入", "导入", 0M, 0M, null, null, DateTime.Now, DepotUser.Id, "", false);

                foreach (DataRow row in handled.Rows)
                {
                    try
                    {
                        var 一级分类 = row[4].ToString().Trim();
                        if (string.IsNullOrEmpty(一级分类))
                            continue;

                        Guid 一级分类Id;
                        if (DataContext.DepotCatalog.Count(o => o.DepotId == 固定资产库Id && o.Name == 一级分类 && o.State < State.停用 && o.ParentId == null) == 0)
                        {
                            一级分类Id = DataContext.DepotCatalogAdd(固定资产库Id, null, Guid.Empty, 一级分类, 100, "");
                        }
                        else
                        {
                            一级分类Id = DataContext.DepotCatalog.Single(o => o.DepotId == 固定资产库Id && o.Name == 一级分类 && o.State < State.停用 && o.ParentId == null).Id;
                        }

                        var 二级分类 = row[5].ToString().Trim();
                        Guid 二级分类Id;
                        if (DataContext.DepotCatalog.Count(o => o.DepotId == 固定资产库Id && o.Name == 二级分类 && o.State < State.停用 && o.ParentId == 一级分类Id) == 0)
                        {
                            二级分类Id = DataContext.DepotCatalogAdd(固定资产库Id, 一级分类Id, 一级分类Id, 二级分类, 100, "");
                        }
                        else
                        {
                            二级分类Id = DataContext.DepotCatalog.Single(o => o.DepotId == 固定资产库Id && o.Name == 二级分类 && o.State < State.停用 && o.ParentId == 一级分类Id).Id;
                        }

                        var fullCode = row[0].ToString().Trim();
                        var code = row[0].ToString().Trim().Substring(row[0].ToString().Trim().Length - 7);
                        var name = row[2].ToString().Trim();

                        var catalogs = DataContext.DepotCatalogLoad(固定资产库Id).Select(o => o.Id).Join(DataContext.DepotObjectCatalog, o => o, o => o.CatalogId, (x, y) => y).Join(DataContext.DepotObject, o => o.ObjectId, o => o.Id, (x, y) => new ToImport { DOC = x, DO = y }).ToList();

                        Guid 物资Id;

                        if (catalogs.Count(o => o.DO.FixedCard == fullCode && o.DOC.CatalogId == 二级分类Id && o.DO.State < State.停用) == 0)
                        {
                            物资Id = DataContext.GlobalId();
                            var l = new List<Guid>();
                            l.Add(一级分类Id);
                            l.Add(二级分类Id);
                            DataContext.DepotObjectAddX(物资Id, l, Depot.Id, name, row[14].ToString().Contains("是"), false, true, row[0].ToString(), row[1].ToString(), row[12].ToString(), "", "", row[11].ToString().Trim(), 0, 0, "", "", "", "", "", 100, row[15].ToString());
                        }
                        else
                        {
                            物资Id = catalogs.First(o => o.DO.FixedCard == code && o.DOC.CatalogId == 二级分类Id && o.DO.State < State.停用).DO.Id;
                        }
                        if (DataContext.DepotIn.Count(o => o.ObjectId == 物资Id && o.Note == code) == 0)
                        {
                            var responsible = row[3].ToString().Trim();
                            var user = DataContext.DepotUserLoad(Depot.CampusId).FirstOrDefault(o => o.Name == responsible && o.State < 2);
                            var responsibleId = user == null ? (Guid?)null : user.Id;
                            decimal amount = 0.00M;
                            try
                            {
                                amount = decimal.Parse(row[6].ToString().Trim());
                            }
                            catch
                            {
                            }
                            decimal price = 0.00M;
                            try
                            {
                                price = decimal.Parse(row[7].ToString().Trim().Replace(" ", "").Replace(",", "").Replace(",", ""));
                            }
                            catch
                            {
                            }
                            var @in = new InMemoryIn { Age = "", Place = row[13].ToString().Trim(), Amount = amount, CatalogId = 二级分类Id, Money = price, Note = code, ObjectId = 物资Id, PriceSet = decimal.Divide(price, amount), Time = DateTime.Today, ResponsibleId = responsibleId };
                            var list = new List<InMemoryIn>();
                            list.Add(@in);
                            DateTime ______t = DateTime.Today;
                            try
                            {
                                ______t = DateTime.Parse(row[10].ToString());
                            }
                            catch
                            { }
                            DataContext.DepotActIn(固定资产库Id, 固定资产库购置单Id, ______t, DepotUser.Id, list);
                        }
                    }
                    catch
                    { }
                }

                var ord = DataContext.DepotInRecord.Single(o => o.Id == 固定资产库购置单Id);
                var s = DataContext.DepotInXRecord.Where(o => o.OrderId == 固定资产库购置单Id).Sum(o => o.Total);
                var oo = DataContext.DepotOrder.Single(o => o.Id == 固定资产库购置单Id);
                oo.ToPay = s;
                oo.Paid = s;
                DataContext.SaveChanges();

            }
        }
        finally
        {
            grid.DataSource = null;
            grid.DataBind();
            Response.Redirect("../DepotAction/Object?DepotId={0}".Formatted(Depot.Id), false);
        }
    }
예제 #3
0
 public void LoadDefaults(InMemoryIn @in)
 {
     catalog.DataSource = DataContext.DepotCatalogTreeLoad(Depot.Id).ToList().Where(o => o.Code != "*Homory:Null*").ToList(); ;
     catalog.DataBind();
     people.Items.Clear();
     people.Items.Insert(0, new Telerik.Web.UI.RadComboBoxItem { Text = "", Value = "", Selected = true });
     people.DataSource = DataContext.DepotUserLoad(Depot.CampusId).ToList();
     people.DataBind();
     place.Text = @in.Place;
     amount.Value = (double?)@in.Amount;
     amount.NumberFormat.DecimalDigits = Depot.Featured(DepotType.小数数量库) ? 2 : 0;
     priceSet.Value = (double?)@in.PriceSet;
     money.Value = (double?)@in.Money;
     note.Text = @in.Note;
     if (@in.CatalogId.HasValue && @in.CatalogId.Value != Guid.Empty)
     {
         var catalogId = @in.CatalogId.Value;
         var node = catalog.EmbeddedTree.FindNodeByValue(catalogId.ToString());
         node.Selected = true;
         node.ExpandParentNodes();
         catalog.SelectedValue = catalogId.ToString();
         var source = DataContext.DepotObjectLoad(Depot.Id, @in.CatalogId).OrderByDescending(o => o.AutoId).ToList();
         //if (Depot.Featured(DepotType.固定资产库))
         //{
         //    source = source.Where(o => o.DepotIn.Count == 0).ToList();
         //}
         obj.DataSource = source;
         obj.DataBind();
         if (@in.ObjectId.HasValue && @in.ObjectId.Value != Guid.Empty)
         {
             var oid = @in.ObjectId.Value;
             var so = DataContext.DepotObject.Single(o => o.Id == oid);
             unit.Text = so.Unit;
             age.Text = so.Age;
             brand.Text = so.Brand;
             specification.Text = so.Specification;
             stored.Text = so.Amount.ToAmount(Depot.Featured(DepotType.小数数量库));
             obj.SelectedIndex = obj.FindItemIndexByValue(@in.ObjectId.ToString());
         }
     }
     else
     {
         if (catalog.EmbeddedTree.Nodes.Count > 0)
         {
             var node = catalog.EmbeddedTree.Nodes[0];
             node.Selected = true;
             node.ExpandParentNodes();
             catalog.SelectedValue = node.Value;
             var source = DataContext.DepotObjectLoad(Depot.Id, Guid.Parse(node.Value), true);
             obj.DataSource = source.ToList();
             obj.DataBind();
         }
     }
     if (@in.ResponsibleId.HasValue)
     {
         var item = people.FindItemByValue(@in.ResponsibleId.Value.ToString());
         if (item != null)
         {
             item.Selected = true;
         }
     }
     if (!"ObjectId".Query().None())
     {
         catalog.Enabled = false;
         obj.Enabled = false;
     }
 }