示例#1
0
        public AffairForm(MainForm mainForm, NoteTable editedTable, Mode mode) :
            base(mainForm, editedTable, mode)
        {
            InitializeComponent();

            Text = GetFormText();
            submitButton.Text  = GetSubmitButtonText();
            datePicker.Visible = false;

            Affair affair = _editedNote as Affair;

            if (affair != null)
            {
                nameTextBox.Text            = affair.Name;
                descriptionRichTextBox.Text = affair.Description;
                setDateCheckBox.Checked     = affair.IsDateSet;
                datePicker.Value            = affair.Date;
                stateComboBox.SelectedIndex = (int)affair.CurrentState;
                commentRichTextBox.Text     = affair.Comment;
            }

            KeyDown += delegate(object o, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Enter && e.Modifiers == Keys.Control)
                {
                    submitButton.PerformClick();
                }
            };
        }
示例#2
0
        public async Task <IActionResult> Edit(Affair affair)
        {
            db.Affairs.Update(affair);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
示例#3
0
        public IActionResult CreateAffair(Affair newAffair)     // processes the form object from CreateWedding.cshtml
        {
            int?userId = HttpContext.Session.GetInt32("userId");

            if (userId == null)
            {
                return(RedirectToAction("Index"));
            }
            if (ModelState.IsValid)
            {
                User user = dbContext.Users.FirstOrDefault(u => u.UserId == userId);
                newAffair.Creator = user;
                dbContext.Affairs.Add(newAffair);
                user.CreatedAffairs.Add(newAffair);
                dbContext.SaveChanges();

                ViewBag.UserId = userId;
                int affairId = newAffair.AffairId;

                return(RedirectToAction("Details", new { affairId = affairId }));
            }
            else
            {
                if (newAffair.AffairDate.Year == 1)
                {
                    if (ModelState.ContainsKey("AffairDate") == true)
                    {
                        ModelState["AffairDate"].Errors.Clear();
                    }
                    ModelState.AddModelError("AffairDate", "Date is Invalid");
                }

                return(View("CreateAffair"));
            }
        }
示例#4
0
        public IActionResult Details(int affairId)
        {
            int? userId = HttpContext.Session.GetInt32("userId");
            User user   = dbContext.Users.FirstOrDefault(u => u.UserId == userId);

            if (userId == null)
            {
                return(RedirectToAction("Index"));
            }

            Affair OneAffair = dbContext.Affairs.FirstOrDefault(w => w.AffairId == affairId);
            User   creator   = OneAffair.Creator;

            List <User> usersThatReserved = dbContext.Users
                                            .Include(u => u.Affairs)
                                            .ThenInclude(v => v.Affair)
                                            .Where(w => w.Affairs.Any(wed => wed.AffairId == affairId))
                                            .ToList();

            ViewBag.usersThatReserved = usersThatReserved;
            ViewBag.User      = user;
            ViewBag.FirstName = creator;
            ViewBag.UserID    = userId;

            return(View(OneAffair));
        }
示例#5
0
        public void Repository_CalledRemove_RemovedCorrect()
        {
            // Arrange
            var id = Guid.NewGuid();

            var expectedAffair = new Affair {
                Id = id
            };

            _mockDbSet.Setup(mock => mock.Find(expectedAffair.Id)).Returns(expectedAffair);

            // Act

            var foundRegion = _affairRepository.GetById(id);

            _affairRepository.Remove(foundRegion);

            // Assert
            _mockDbSet.Verify(
                dbSet => dbSet.Find(
                    expectedAffair.Id
                    ), Times.Once());

            _mockDbSet.Verify(
                dbSet => dbSet.Remove(
                    expectedAffair
                    ), Times.Once());
        }
示例#6
0
        private static List <Note> ReadAffairs(SQLiteDataReader reader)
        {
            try
            {
                List <Note> notes = new List <Note>();

                while (reader.Read())
                {
                    Affair affair = new Affair();

                    affair.Id           = reader.GetInt32(0);
                    affair.Name         = reader.GetString(1);
                    affair.CurrentState = (Note.State)reader.GetInt32(2);
                    affair.Comment      = reader.GetString(3);
                    affair.Description  = reader.GetString(4);
                    affair.IsDateSet    = reader.GetBoolean(5);
                    affair.SetDate(reader.GetString(6));

                    notes.Add(affair);
                }

                return(notes);
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("Can not read affairs:{0}{1}",
                                        Environment.NewLine, ex.ToString()));
                return(new List <Note>());
            }
        }
示例#7
0
        private static bool InsertAffairs(List <Note> notes)
        {
            bool inserted = false;

            try
            {
                using (SQLiteConnection connection = Database.CreateConnection())
                {
                    connection.Open();
                    _affairsInsertCommand.Connection = connection;

                    if (connection.State == System.Data.ConnectionState.Open)
                    {
                        using (SQLiteTransaction transaction = connection.BeginTransaction())
                        {
                            foreach (Note note in notes)
                            {
                                Affair affair = note as Affair;
                                if (affair == null)
                                {
                                    Log.Error("Try to insert incorrect note");
                                    continue;
                                }

                                _affairsInsertCommand.Parameters[0].Value = affair.Name;
                                _affairsInsertCommand.Parameters[1].Value = (int)affair.CurrentState;
                                _affairsInsertCommand.Parameters[2].Value = affair.Comment;
                                _affairsInsertCommand.Parameters[3].Value = affair.Description;
                                _affairsInsertCommand.Parameters[4].Value = affair.IsDateSet;
                                _affairsInsertCommand.Parameters[5].Value = affair.GetDate();

                                _affairsInsertCommand.Prepare();
                                _affairsInsertCommand.ExecuteNonQuery();

                                affair.Id = (int)connection.LastInsertRowId;

                                inserted = true;
                            }

                            transaction.Commit();
                        }
                    }

                    connection.Close();
                    _affairsInsertCommand.Connection = null;
                }
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("Can not execute command: {0}{1}{2}{3}",
                                        Environment.NewLine, (_affairsInsertCommand != null) ? _affairsInsertCommand.CommandText : "",
                                        Environment.NewLine, ex.ToString()));

                return(false);
            }

            return(inserted);
        }
示例#8
0
        private void setData()
        {
            writing = (Writing)Session["UpdateWritingObject"];
            client  = (Client)Session["UpdateClientObject"];
            affair  = (Affair)Session["UpdateAffairObject"];

            protocolID = Session["UpdateProtocolID"].ToString();
            writingID  = int.Parse(Session["UpdateWritingID"].ToString());
            rbt        = Session["RBT"].ToString();

            TextBoxAct.Text        = writing.EventWriting;
            TextBoxAddressFac.Text = writing.BillingAddress;
            TextBoxAffair.Text     = affair.AffairName;
            TextBoxClient.Text     = client.ClientName;
            TextBoxIdFac.Text      = writing.BillingNumber;

            DateTime t = (DateTime)Session["UpdateDate"];

            CalendarDate.TodaysDate   = t;
            TextBoxEmailFac.Text      = writing.BillingEmail;
            TextBoxParts.Text         = writing.Parts;
            TextBoxWritingNumber.Text = writing.WritingNumber;

            string facNotary = Session["UpdateFacNotary"].ToString();

            string[] var = facNotary.Split('$');


            TextBoxNotaryFac.Text = var[1];
            loadCoNotary();


            List <string> names = new List <string>();

            foreach (GridViewRow r in GridViewCoNotary.Rows)
            {
                names.Add(r.Cells[2].Text);
            }

            List <int> list = bll.getAllCoNorariesToUpdate(writing.WritingID, names); //Names va bien
            int        i    = 0;

            foreach (GridViewRow row in GridViewCoNotary.Rows)
            {
                try
                {
                    if (row.RowType == DataControlRowType.DataRow)
                    {
                        ((TextBox)row.FindControl("TextBoxCoNotaryAdd")).Text = list[i] + "";
                    }
                    i++;
                } catch (Exception e) {
                }
            }
        }
示例#9
0
        public async Task <IActionResult> ConfirmDelete(int?id)
        {
            if (id != null)
            {
                Affair affair = await db.Affairs.FirstOrDefaultAsync(p => p.Id == id);

                if (affair != null)
                {
                    return(View(affair));
                }
            }
            return(NotFound());
        }
示例#10
0
        public IActionResult Delete(int affairId)
        {
            if (HttpContext.Session.GetInt32("userId") == null)
            {
                return(RedirectToAction("Index"));
            }

            Affair AffairToDelete = dbContext.Affairs.FirstOrDefault(w => w.AffairId == affairId);

            dbContext.Affairs.Remove(AffairToDelete);
            dbContext.SaveChanges();

            return(RedirectToAction("Dashboard"));
        }
示例#11
0
        public IActionResult Dashboard()
        {
            if (HttpContext.Session.GetInt32("userId") == null)
            {
                // return RedirectToAction("Index");
                return(View("Index"));
            }

            List <Affair> AllAffairs = dbContext.Affairs
                                       .Include(w => w.ReserveSpot)
                                       .ThenInclude(r => r.User)
                                       .Include(affair => affair.Creator)
                                       .ToList();

            List <int> AffairsToDelete = new List <int>();
            DateTime   CurrentTime     = DateTime.Now;

            foreach (var affair in AllAffairs)
            {
                if (affair.AffairDate < CurrentTime)
                {
                    AffairsToDelete.Add(affair.AffairId);
                }
            }
            if (AffairsToDelete.Count > 0)
            {
                foreach (var affair in AffairsToDelete)
                {
                    Affair AffairToDelete = dbContext.Affairs.FirstOrDefault(aff => aff.AffairId == affair);
                    dbContext.Affairs.Remove(AffairToDelete);
                    dbContext.SaveChanges();
                }
            }

            int userId = (int)HttpContext.Session.GetInt32("userId");

            ViewBag.UserId = userId;
            ViewBag.User   = dbContext.Users.FirstOrDefault(u => u.UserId == userId);

            int count = dbContext.Users
                        .Include(u => u.Affairs)
                        .ThenInclude(s => s.Affair)
                        .Where(e => e.Affairs.Any(user => user.UserId == userId))
                        .Count();

            ViewBag.Count = count;

            return(View("Dashboard", AllAffairs));
        }
示例#12
0
        public override void UpdateNote(Note note)
        {
            Affair affair = note as Affair;

            if (affair == null)
            {
                return;
            }

            CurrentRow.Cells[(int)Index.Name].Value        = affair.Name;
            CurrentRow.Cells[(int)Index.Description].Value = affair.Description;
            CurrentRow.Cells[(int)Index.IsDateSet].Value   = affair.IsDateSet;
            CurrentRow.Cells[(int)Index.Date].Value        = affair.IsDateSet ? affair.GetDate().Replace(' ', '.') : "";
            CurrentRow.Cells[(int)Index.State].Value       = States[(int)affair.CurrentState];
            CurrentRow.Cells[(int)Index.Comment].Value     = affair.Comment;
        }
示例#13
0
        public async Task <IActionResult> Delete(int?id)
        {
            if (id != null)
            {
                Affair affair = await db.Affairs.FirstOrDefaultAsync(p => p.Id == id);

                if (affair != null)
                {
                    db.Affairs.Remove(affair);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
            }
            return(NotFound());
        }
示例#14
0
        public IActionResult New(Affair affair, AffairDetail affairDetail, List <AffairEmployeeDetail> affairEmployeeDetail,
                                 List <AffairVehicleDetail> affairVehicleDetail)
        {
            string customerSignName = affairDetail.SignatureDate.ToShortDateString() + affairDetail.CustomerInfo + ".svg";
            string customerBase64   = affairDetail.CustomerSignaturePath.Replace("data:image/svg+xml;base64,", "");

            _converter.ConvertFile(customerSignName, customerBase64);
            affairDetail.CustomerSignaturePath = customerSignName;
            string employeeSignName = affairDetail.SignatureDate.ToShortDateString() + affairDetail.EmployeeId + ".svg";
            string employeeBase64   = affairDetail.SignaturePath.Replace("data:image/svg+xml;base64,", "");

            _converter.ConvertFile(employeeSignName, employeeBase64);
            affairDetail.SignaturePath = employeeSignName;

            return(RedirectToAction(nameof(Index)));
        }
示例#15
0
        private void submitButton_Click(object sender, EventArgs e)
        {
            DateTime d = datePicker.Value;

            Affair affair = (_editedNote != null && _editedNote is Affair) ? _editedNote as Affair : new Affair();

            affair.Name         = nameTextBox.Text;
            affair.Description  = descriptionRichTextBox.Text;
            affair.IsDateSet    = setDateCheckBox.Checked;
            affair.Date         = datePicker.Value;
            affair.CurrentState = (Note.State)stateComboBox.SelectedIndex;
            affair.Comment      = commentRichTextBox.Text;

            SubmitNote(affair);

            Close();
        }
示例#16
0
        public IActionResult Leave(int affairId)
        {
            int userId = (int)HttpContext.Session.GetInt32("userId");

            if (HttpContext.Session.GetInt32("userId") == null)
            {
                return(RedirectToAction("Index"));
            }

            Affair AffairToReserve = dbContext.Affairs.FirstOrDefault(w => w.AffairId == affairId);
            User   user            = dbContext.Users.FirstOrDefault(u => u.UserId == userId);

            UserAffair UserAffairToDelete = dbContext.UsersAffairs.FirstOrDefault(uw => uw.AffairId == affairId && uw.UserId == userId);

            dbContext.UsersAffairs.Remove(UserAffairToDelete);
            dbContext.SaveChanges();

            return(RedirectToAction("Dashboard"));
        }
示例#17
0
        public override bool AddNote(Note note)
        {
            if (note is Affair)
            {
                Affair affair = note as Affair;

                Rows.Add(
                    affair.Id.ToString(),
                    affair.Name,
                    affair.Description,
                    affair.IsDateSet,
                    affair.IsDateSet ? affair.GetDate().Replace(' ', '.') : "",
                    States[(int)affair.CurrentState],
                    affair.Comment
                    );

                return(true);
            }

            return(false);
        }
示例#18
0
        private static bool UpdateAffair(Note note)
        {
            Affair affair = note as Affair;

            if (affair == null || affair.Id < 0)
            {
                Log.Error("Try to save incorrect affair note");
                return(false);
            }

            _affairsUpdateCommand.Parameters[0].Value = affair.Id;
            _affairsUpdateCommand.Parameters[1].Value = affair.Name;
            _affairsUpdateCommand.Parameters[2].Value = (int)affair.CurrentState;
            _affairsUpdateCommand.Parameters[3].Value = affair.Comment;
            _affairsUpdateCommand.Parameters[4].Value = affair.Description;
            _affairsUpdateCommand.Parameters[5].Value = affair.IsDateSet;
            _affairsUpdateCommand.Parameters[6].Value = affair.GetDate();

            _affairsUpdateCommand.Prepare();

            return(ExecuteNonQuery(_affairsUpdateCommand) == 1);
        }
示例#19
0
        public override Note GetNoteFromSelectedRow()
        {
            if (CurrentRow == null)
            {
                return(null);
            }

            Affair affair = new Affair();

            affair.Id          = CurrentRow.Cells[(int)Index.Id].Value.ToString().ToIntOrException();
            affair.Name        = CurrentRow.Cells[(int)Index.Name].Value.ToString();
            affair.Description = CurrentRow.Cells[(int)Index.Description].Value.ToString();
            affair.IsDateSet   = (bool)CurrentRow.Cells[(int)Index.IsDateSet].Value;
            if (affair.IsDateSet)
            {
                affair.SetDate(CurrentRow.Cells[(int)Index.Date].Value.ToString().Replace('.', ' '));
            }
            affair.CurrentState = CurrentRow.Cells[(int)Index.State].Value.ToString().ToNoteState();
            affair.Comment      = CurrentRow.Cells[(int)Index.Comment].Value.ToString();

            return(affair);
        }
示例#20
0
        protected void Session_Start(object sender, EventArgs e)
        {
            Session["Login"]             = "******";
            Session["NotaryID"]          = "Por Defecto";
            Session["ProtocolID"]        = "Por Defecto";
            Session["Varload"]           = "Por Defecto";
            Session["WritingIDConotary"] = "Por Defecto";
            Session["DoWriting"]         = "Por Defecto";
            Session["UpdateWritingID"]   = "Por Defecto";
            Session["RBT"] = "Por Defecto";

            Session["export"] = "datatable";

            Session["UpdateWritingToAlert"] = "Por Defecto";

            Session["UpdateMonth"] = "Por Defecto";


            Session["ExportYear"] = "Por Defecto";
            Session["ExportType"] = "Por Defecto";

            Session["UpdateProtocolID"] = "Por Defecto";
            Session["UpdateFacNotary"]  = "Por Defecto";


            Session["UpdateRegisterID"] = "Por Defecto";

            Session["Counter"] = new int();
            Session["limit"]   = new DateTime();


            Session["UpdateDate"] = new DateTime();


            Session["UpdateWritingObject"] = new Writing();
            Session["UpdateClientObject"]  = new Client();
            Session["UpdateAffairObject"]  = new Affair();
        }
示例#21
0
        public IActionResult Join(int affairId)
        {
            if (HttpContext.Session.GetInt32("userId") == null)
            {
                return(RedirectToAction("Index"));
            }

            Affair AffairToJoin = dbContext.Affairs.FirstOrDefault(w => w.AffairId == affairId);
            int    userId       = (int)HttpContext.Session.GetInt32("userId");
            User   user         = dbContext.Users.FirstOrDefault(u => u.UserId == userId);

            UserAffair newUserAffair = new UserAffair
            {
                UserId   = userId,
                AffairId = affairId,
                User     = user,
                Affair   = AffairToJoin,
            };

            dbContext.UsersAffairs.Add(newUserAffair);
            dbContext.SaveChanges();

            return(RedirectToAction("Dashboard"));
        }
示例#22
0
        public Result <stockapply> Update(stockapply sto, List <stockapplydetails> stockapplydetails)
        {
            Result <stockapply> result = null;

            try
            {
                var entity = this._StockapplyDAL.GetModel(s => s.Appid == sto.Appid);
                if (entity == null)
                {
                    throw new Exception($"{sto.Appid} 单号不存在");
                }
                if (!string.IsNullOrEmpty(entity.Extend0))
                {
                    throw new Exception("请购单状态不可以更改");
                }

                entity.Apptype  = sto.Apptype;
                entity.Appcircs = sto.Appcircs;


                Affair.Whether <int, stockapply>(sto, (s) =>
                {
                    int i = 1;

                    //修改采后编号
                    stockapplydetails.ForEach(d => {
                        d.Safetyone        = "测试修改";
                        d.Safetytwo        = "测试修改";
                        d.Appid            = sto.Appid;
                        d.TockapplyDetails = sto.Appid + i.ToString("00");
                        i++;
                    });

                    _StockapplyDAL.Update(entity.Appid, stockapplydetails);
                    int count = _StockapplyDAL.SaveChanges();

                    return(count);
                });

                result = new Result <stockapply>()
                {
                    errorInfo = "修改采购请购单成功",
                    errorNo   = 0,
                    results   = new ModelData <stockapply>()
                    {
                        data = sto
                    }
                };
            }
            catch (Exception ex)
            {
                result = new Result <stockapply>()
                {
                    errorInfo = ex.Message,
                    errorNo   = -5,
                    results   = null
                };
            }


            return(result);
        }
示例#23
0
        public Result <stockapply> Add(stockapply sto, List <stockapplydetails> stockapplydetails)
        {
            //模拟数据
            sto.Appcircs          = 3;
            sto.Appdept           = "";
            sto.Appperson         = "";
            sto.Enables           = 0;
            sto.Appdeptid         = "";
            sto.Apppersonid       = "1";
            sto.Appauditing       = "未复核";
            sto.Appauditingperson = "1";
            sto.Appmaker          = "1";
            sto.Stockapplyname    = "";
            sto.Safetyone         = "";
            sto.Safetytwo         = "";


            Result <stockapply> result = null;

            try
            {
                Affair.Whether <int, stockapply>(sto, (s) =>
                {
                    int i = 1;

                    //修改采后编号
                    stockapplydetails.ForEach(d => {
                        d.Safetyone        = "";
                        d.Safetytwo        = "";
                        d.Appid            = sto.Appid;
                        d.TockapplyDetails = sto.Appid + i.ToString("00");
                        i++;
                    });

                    _StockapplyDAL.Add(sto, stockapplydetails);
                    int count   = _StockapplyDAL.SaveChanges();
                    int DbCount = 1 + stockapplydetails.Count;
                    if (count != DbCount)
                    {
                        throw new Exception("请购单 和 请购详细新增条数不正确");
                    }

                    return(count);
                });

                result = new Result <stockapply>()
                {
                    errorInfo = "新增采购成功",
                    errorNo   = 0,
                    results   = new ModelData <stockapply>()
                    {
                        data = sto
                    }
                };
            }
            catch (Exception ex)
            {
                result = new Result <stockapply>()
                {
                    errorInfo = ex.Message,
                    errorNo   = -5,
                    results   = null
                };
            }


            return(result);
        }
示例#24
0
 public void Add(Affair affair)
 {
     _affairDal.Add(affair);
 }
示例#25
0
 public void Delete(Affair affair)
 {
     _affairDal.Delete(affair);
 }
示例#26
0
 public void Update(Affair affair)
 {
     _affairDal.Update(affair);
 }
示例#27
0
        protected void GridViewMonthsSearch_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "showCo-Notariado")
            {
                /*Button Update*/
                int crow;
                crow = Convert.ToInt32(e.CommandArgument.ToString());

                string writingID = GridViewMonthsSearch.Rows[crow].Cells[2].Text;

                int id = int.Parse(writingID);

                /* GridViewMonths.DataSource = null;
                 * GridViewMonths.DataBind();*/
                //GridViewMonths.Visible = false;

                GridView1.DataSource = bll.showCo_NotaryWritingByIDWithOutCero(id);
                GridView1.DataBind();
                Label2.Text        = "Co-Notariado";
                Session["Varload"] = 1;
            }

            if (e.CommandName == "UpdateWriting")
            {
                int crow;
                crow = Convert.ToInt32(e.CommandArgument.ToString());


                string writingID     = GridViewMonthsSearch.Rows[crow].Cells[2].Text;
                string writingNumber = GridViewMonthsSearch.Rows[crow].Cells[3].Text;
                string act           = GridViewMonthsSearch.Rows[crow].Cells[4].Text;
                string affair        = GridViewMonthsSearch.Rows[crow].Cells[5].Text;
                string client        = GridViewMonthsSearch.Rows[crow].Cells[6].Text;

                Session["UpdateFacNotary"] = GridViewMonthsSearch.Rows[crow].Cells[8].Text;
                string parts      = GridViewMonthsSearch.Rows[crow].Cells[9].Text;
                string iDFac      = GridViewMonthsSearch.Rows[crow].Cells[10].Text;
                string addressFac = GridViewMonthsSearch.Rows[crow].Cells[11].Text;
                string emailFac   = GridViewMonthsSearch.Rows[crow].Cells[12].Text;
                string date       = GridViewMonthsSearch.Rows[crow].Cells[13].Text;

                string[] var = date.Split(' ');

                string[] var2  = var[0].Split('/');
                int      month = int.Parse(var2[1]);
                int      year  = int.Parse(var2[2]);
                int      day   = int.Parse(var2[0]);

                DateTime date1 = new DateTime(year, month, day);


                Session["UpdateDate"]  = date1;
                Session["UpdateMonth"] = month + "";

                Client c = new Client();
                c.ClientName = client;
                c.ClientID   = bll.checkClients(client);

                Affair a = new Affair();
                a.AffairName = affair;
                a.AffairID   = bll.checkAffair(affair);

                Writing writing = new Writing();
                writing.WritingID      = int.Parse(writingID);
                writing.WritingNumber  = writingNumber;
                writing.EventWriting   = act;
                writing.Parts          = parts;
                writing.BillingNumber  = iDFac;
                writing.BillingEmail   = emailFac;
                writing.BillingAddress = addressFac;
                writing.DateWriting    = date1;


                int protocolID = bll.getProtocolByMonthAndYear(notary.NotaryID, LabelMonth.Text, int.Parse(DateTime.Now.ToString("yyyy")));



                Session["UpdateWritingObject"] = writing;
                Session["UpdateClientObject"]  = c;
                Session["UpdateAffairObject"]  = a;

                Session["NotaryID"]         = notary.NotaryID;
                Session["UpdateProtocolID"] = protocolID + "";
                Session["RBT"]             = LabelRBT.Text;
                Session["UpdateWritingID"] = writingID;
                Session["Varload"]         = "0";
                // alert(protocolID + " " + writingID);
                Response.Redirect("UpdateWriting.aspx");
            }
        }
示例#28
0
        /// <summary>
        /// 新增采购请购单
        /// </summary>
        /// <param name="sto">采购订单</param>
        /// <param name="stockorderdetails">采购订单详细</param>
        /// <returns></returns>
        public Result <stockorder> Add(stockorder sto, List <stockorderdetails> stockorderdetails, int changeOrderType)
        {
            var result = new Result <stockorder>()
            {
                errorNo = 0, errorInfo = "新增采购订单成功", results = new ModelData <stockorder>()
                {
                    data = sto
                }
            };
            int id = 1;

            try
            {
                //修改新增固定值
                sto.Checkstate = 2;


                switch (changeOrderType)
                {
                case 0:     //普通新增采购订单
                    Affair.Whether <int, Result <stockorder> >(result, (obj) =>
                    {
                        var stoder = this._StockorderDAL.GetModel(s => s.Stoid == sto.Stoid);
                        if (stoder != null)
                        {
                            throw new Exception("单据号码 {sto.Stoid} 已经存在");
                        }

                        //新增 采购订单
                        this._StockorderDAL.Add(sto);
                        foreach (var item in stockorderdetails)
                        {
                            item.Sodlineid = sto.Stoid + id++.ToString("00");
                            item.Sodid     = sto.Stoid;
                            //新增采购订单详细
                            this._StockorderdetailsDAL.Add(item);
                        }
                        return(this.DAL.SaveChanges());
                    });
                    break;

                case 1:     //转单采购请购单的
                    Affair.Whether <int, Result <stockorder> >(result, (obj) =>
                    {
                        var stoder = this._StockorderDAL.GetModel(s => s.Stoid == sto.Stoid);
                        if (stoder != null)
                        {
                            throw new Exception("单据号码 {sto.Stoid} 已经存在");
                        }

                        //新增 采购订单
                        this._StockorderDAL.Add(sto);

                        var appid      = stockorderdetails[0].Sodorigin;
                        var stockapply = this._StockapplyDAL.GetModel(s => s.Appid.Equals(appid));
                        if (stockapply == null)
                        {
                            throw new Exception($"转入的请购单:{appid} 不存在 ");
                        }

                        //获取请购详细
                        var stockapplyderdetails = this._StockapplydetailsDAL.ListModels(s => s.Appid == stockapply.Appid).ToList();
                        foreach (var item in stockapplyderdetails)
                        {
                            var orderderdetails = stockorderdetails.FirstOrDefault(s => s.Extend0 == item.TockapplyDetails);
                            if (orderderdetails == null)
                            {
                                throw new Exception($"请购单中:{appid}  请购列表物料 {item.TockapplyDetails} 物料名称{item.Apdmateridlid} 缺少 ");
                            }

                            //大于请购单 直接未采购数量变成0
                            if (orderderdetails.Sodamount > item.Apdnotnum)
                            {
                                item.Apdnotnum = 0;
                            }
                            else
                            {
                                //修改未采购数量
                                item.Apdnotnum = item.Apdnotnum - orderderdetails.Sodamount;
                            }

                            orderderdetails.Sodlineid = sto.Stoid + id++.ToString("00");
                            orderderdetails.Sodid     = sto.Stoid;
                            //新增采购订单详细
                            this._StockorderdetailsDAL.Add(orderderdetails);
                        }

                        //判断是否全部采购完成
                        var count = stockapplyderdetails.Count(s => s.Apdnotnum <= 0);
                        if (count == stockapplyderdetails.Count)
                        {
                            //修改采购请购单
                            stockapply.Appcircs = 1;
                            stockapply.Extend0  = "不可修改";
                        }
                        return(this._StockapplyDAL.SaveChanges());
                    });
                    break;
                }
                return(result);
            }
            catch (Exception ex)
            {
                return(new Result <stockorder>()
                {
                    errorNo = -788,
                    errorInfo = ex.Message,
                    results = null
                });
            }
        }