Example #1
0
        public ResponseBase Insert(ReadPercentKCSInventoryModel obj)
        {
            var result = new ResponseBase();

            try
            {
                db = new PMSEntities();
                P_ReadPercent_KCSInventory newObj;
                newObj = new P_ReadPercent_KCSInventory();
                Parse.CopyObject(obj, ref newObj);
                newObj.IsDeleted = false;

                if (obj.Childs != null && obj.Childs.Count > 0)
                {
                    newObj.P_ReadPercent_KCSInventory_De = new List <P_ReadPercent_KCSInventory_De>();
                    P_ReadPercent_KCSInventory_De subItem;
                    foreach (var itemObj in obj.Childs)
                    {
                        subItem = new P_ReadPercent_KCSInventory_De();
                        Parse.CopyObject(itemObj, ref subItem);
                        subItem.IsDeleted = false;
                        subItem.P_ReadPercent_KCSInventory = newObj;
                        newObj.P_ReadPercent_KCSInventory_De.Add(subItem);
                    }
                }
                db.P_ReadPercent_KCSInventory.Add(newObj);
                db.SaveChanges();
                result.IsSuccess = true;
                result.Messages.Add(new Message()
                {
                    Title = "Thông Báo", msg = "Lưu thành công."
                });
            }
            catch (Exception ex)
            {
            }
            return(result);
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(cbtile.Text))
            {
                ResponseBase rs;
                var          obj = new ReadPercentKCSInventoryModel()
                {
                    Id   = Id,
                    Name = cbtile.Text
                };
                var listReadPercent = new List <P_ReadPercent_KCSInventory_De>();
                if (dgTyLe.Rows.Count > 0)
                {
                    P_ReadPercent_KCSInventory_De rp;
                    for (int i = 0; i < dgTyLe.Rows.Count - 1; i++)
                    {
                        rp = new P_ReadPercent_KCSInventory_De();
                        DataGridViewRow row = dgTyLe.Rows[i];
                        if (row != null)
                        {
                            int percentFrom = 0;
                            if (row.Cells["dgPercentFrom"].Value != null)
                            {
                                int.TryParse(row.Cells["dgPercentFrom"].Value.ToString(), out percentFrom);
                            }
                            rp.From = percentFrom;

                            int percentTo = 0;
                            if (row.Cells["dgPercentTo"].Value != null)
                            {
                                int.TryParse(row.Cells["dgPercentTo"].Value.ToString(), out percentTo);
                            }
                            rp.To = percentTo;

                            int countRepeat = 0;
                            if (row.Cells["dgCountRepeat"].Value != null)
                            {
                                int.TryParse(row.Cells["dgCountRepeat"].Value.ToString(), out countRepeat);
                            }
                            rp.RepeatTimes = countRepeat;

                            string sound = string.Empty;
                            if (row.Cells["tsound"].Value != null)
                            {
                                sound = row.Cells["tsound"].Value.ToString();
                            }
                            rp.SoundPath = sound;
                            listReadPercent.Add(rp);
                        }
                    }
                    obj.Childs.AddRange(listReadPercent);
                }
                if (Id == 0)
                {
                    rs = BLLReadPercent_KCSInventory.Instance.Insert(obj);
                }
                else
                {
                    //   result = readpercentDAO.SuaThongTinOBJ(idReadPercent, listReadPercent);
                    rs = BLLReadPercent_KCSInventory.Instance.Update(Id, cbtile.Text, listReadPercent);
                }
                if (rs.IsSuccess)
                {
                    ProcessButton(4);
                    dgTyLe.Enabled = false;
                    loadPhanCongTyLe();
                    loadDSTyLe();
                    Id = 0;
                    MessageBox.Show("Lưu thông tin thành công");
                }
            }
            else
            {
                MessageBox.Show("Tên tỷ lệ không được để trống", "Lỗi thao tác", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }