Ejemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateChildren())
            {
                return;
            }

            String CustomerPID = (String)customerTableAdapter.InsertQuery(
                tbxPID.Text,
                Convert.ToByte(cbxPrename.SelectedValue),
                tbxfName.Text,
                tbxlName.Text,
                cbxCompany.SelectedValue == null ? new Int32?() : Convert.ToInt32(cbxCompany.SelectedValue),
                tbxAddress.Text,
                tbxStreed.Text,
                tbxPhone.Text,
                tbxMobile.Text,
                cbxCityID.SelectedValue == null ? new Int32?() : Convert.ToInt32(cbxCityID.SelectedValue),
                cbxDistrictID.SelectedValue == null ? new Int32?() : Convert.ToInt32(cbxDistrictID.SelectedValue),
                cbxProvinceID.SelectedValue == null ? new Int32?() : Convert.ToInt32(cbxProvinceID.SelectedValue),
                cbxPostCode.SelectedValue == null ? new Int32?() : Convert.ToInt32(cbxPostCode.SelectedValue));

            if (CustomerPID != null)
            {
                UserLogTableAdapter logTableAdapter = new UserLogTableAdapter();
                logTableAdapter.Insert(TypeUtil.Customer, CustomerPID, MainForm.User.UserID, TypeUtil.EVENT_CREATE, DateTime.Now);

                DialogResult = DialogUtil.AddSuccess();
            }
            else
            {
                DialogResult = DialogUtil.AddError();
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateChildren())
            {
                return;
            }

            if (Option)
            {
                OptionByID        = Convert.ToInt32(cbxBy.SelectedValue);
                OptionStockID     = Convert.ToInt32(cbxStock.SelectedValue);
                OptionUnit        = Convert.ToDouble(tbxUnit.Text);
                OptionDate        = this.dtpDate.Value;
                this.DialogResult = System.Windows.Forms.DialogResult.Yes;
            }
            else
            {
                var Msg         = new StringBuilder();
                var CurrentUnit = this.stockTableAdapter.QueryCurrentUnit(Convert.ToInt32(cbxStock.SelectedValue));
                if (CurrentUnit < Convert.ToDouble(tbxUnit.Text))
                {
                    Msg.Append(String.Format("{0} จำนวนปัจจุบัน:{1} จำนวนที่ต้องการ:{2}\n", stockTableAdapter.GetDataByPK(Convert.ToInt32(cbxStock.SelectedValue))[0].Name, CurrentUnit, Convert.ToDouble(tbxUnit.Text)));
                }

                if (Msg.Length != 0)
                {
                    MessageBox.Show(String.Format("พัสดุไม่พอ \n{0}\n กรุณาลองใหม่อีกครั้ง", Msg), "ข้อผิดผลาด", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    int VaccineID = (int)this.vaccineTableAdapter.InsertQuery(
                        Convert.ToInt32(cbxBy.SelectedValue),
                        cbxCow.SelectedValue.ToString(),
                        Convert.ToInt32(cbxStock.SelectedValue),
                        Convert.ToDouble(tbxUnit.Text),
                        dtpDate.Value);


                    if (VaccineID > 0)
                    {
                        var log = new UserLogTableAdapter();
                        log.Insert(TypeUtil.Vaccine, VaccineID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_CREATE, DateTime.Now);

                        this.stockTableAdapter.UpdateRemoveUnit(Convert.ToDouble(tbxUnit.Text), Convert.ToInt32(cbxStock.SelectedValue));
                        this.DialogResult = DialogUtil.AddSuccess();
                    }
                    else
                    {
                        this.DialogResult = DialogUtil.AddError();
                    }
                }
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (OrderOutID > 0)
            {
                this.Validate();
                this.deadViewBindingSource.EndEdit();
                this.fKCowOrderOut1BindingSource.EndEdit();
                Int32 result = this.deadViewTableAdapter.Update(this.farmManageDataSet.DeadView);

                if (result == 1)
                {
                    this.DialogResult = DialogUtil.SaveSuccess();
                }
                else
                {
                    this.DialogResult = DialogUtil.SaveError();
                }
            }
            else
            {
                OrderOutID = (int)this.deadViewTableAdapter.InsertQuery(
                    (byte)2,
                    Convert.ToInt32(this.cbxBy.SelectedValue),
                    this.dtpDate.Value,
                    this.tbxDescription.Text);

                if (OrderOutID > 0)
                {
                    var log = new UserLogTableAdapter();
                    log.Insert(TypeUtil.OrderOut, OrderOutID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_CREATE, DateTime.Now);

                    foreach (DataGridViewRow row in this.dgvCowAdd.Rows)
                    {
                        Int32  tCorralID = Convert.ToInt32(row.Cells["colCorral"].Value);
                        String tCowNO    = row.Cells["colCowNO"].Value.ToString();


                        int result = this.cowTableAdapter.UpdateCowOrderOut(OrderOutID, new Double?(), tCowNO);
                        if (result == 1)
                        {
                            log.Insert(TypeUtil.Cow, tCowNO, MainForm.User.UserID, TypeUtil.EVENT_DEAD, DateTime.Now);

                            this.corralTableAdapter.UpdateRemoveCurrent(1, tCorralID);
                        }
                    }

                    this.DialogResult = DialogUtil.AddSuccess();
                }
                else
                {
                    this.DialogResult = DialogUtil.AddError();
                }
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (AddStockID == 0)
            {
                if (dgvAddList.Rows.Count == 0)
                {
                    MessageBox.Show("ไม่มีรายการที่เพิ่มอย่างสมบูรณ์ กรุณาเพิ่มหรือป้อนข้อมูลให้ครบ");
                    return;
                }
                for (var i = 0; i < dgvAddList.Rows.Count - 1; i++)
                {
                    if (dgvAddList.Rows[i].Cells[0].Value == null || Convert.ToDouble(dgvAddList.Rows[i].Cells[1].Value) == 0 || Convert.ToDouble(dgvAddList.Rows[i].Cells[2].Value) == 0)
                    {
                        MessageBox.Show("ข้อมูลไม่ครบ กรุณาลองใหม่อีกครั้ง");
                        return;
                    }
                }
                int StockAddID = (int)stockAddTableAdapter.InsertQuery(
                    Convert.ToInt32(cbxBy.SelectedValue),
                    dtpDate.Value,
                    Convert.ToDouble(tbxTotal.Text));

                if (StockAddID > 0)
                {
                    var log = new UserLogTableAdapter();
                    log.Insert(TypeUtil.StockAdd, AddStockID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_CREATE, DateTime.Now);


                    for (var i = 0; i < dgvAddList.Rows.Count; i++)
                    {
                        var stockAddListID = (int)stockAddListTableAdapter.InsertQuery(
                            StockAddID,
                            Convert.ToInt32(dgvAddList.Rows[i].Cells[0].Value),
                            Convert.ToDouble(dgvAddList.Rows[i].Cells[1].Value),
                            Convert.ToDouble(dgvAddList.Rows[i].Cells[2].Value),
                            Convert.ToDouble(dgvAddList.Rows[i].Cells[3].Value),
                            dgvAddList.Rows[i].Cells[4].Value == null ? string.Empty : dgvAddList.Rows[i].Cells[4].Value.ToString());

                        if (stockAddListID > 0)
                        {
                            log.Insert(TypeUtil.StockAddList, stockAddListID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_CREATE, DateTime.Now);

                            stockTableAdapter.UpdateAddUnit(Convert.ToDouble(dgvAddList.Rows[i].Cells[1].Value), Convert.ToInt32(dgvAddList.Rows[i].Cells[0].Value));
                        }
                    }

                    DialogResult = DialogUtil.AddSuccess();
                }
                else
                {
                    DialogResult = DialogUtil.AddError();
                }
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!this.ValidateChildren())
            {
                return;
            }

            if (CorralID > 0)
            {
                this.Validate();
                this.corralBindingSource.EndEdit();
                var ResultId = this.corralTableAdapter.Update(farmManageDataSet.Corral);
                if (ResultId == 1)
                {
                    UserLogTableAdapter logTableAdapter = new UserLogTableAdapter();
                    logTableAdapter.Insert(TypeUtil.Corral, CorralID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_MODIFY, DateTime.Now);

                    DialogUtil.SaveSuccess();
                    this.DialogResult = DialogResult.Yes;
                }
                else
                {
                    DialogUtil.SaveError();
                    this.DialogResult = DialogResult.No;
                }
            }
            else
            {
                CorralID = (int)this.corralTableAdapter.InsertQuery(tbxName.Text.Trim(), Convert.ToInt32(tbxMax.Text), Convert.ToInt32(tbxCurrent.Text), tbxDescription.Text.Trim());
                if (CorralID > 0)
                {
                    UserLogTableAdapter logTableAdapter = new UserLogTableAdapter();
                    logTableAdapter.Insert(TypeUtil.Corral, CorralID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_MODIFY, DateTime.Now);

                    DialogUtil.AddSuccess();
                    this.DialogResult = DialogResult.Yes;
                }
                else
                {
                    DialogUtil.AddError();
                    this.DialogResult = DialogResult.No;
                }
            }
        }
Ejemplo n.º 6
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!this.ValidateChildren())
            {
                return;
            }

            if (StockID != 0)
            {
                this.Validate();
                this.stockBindingSource.EndEdit();
                if (1 == stockTableAdapter.Update(farmManageDataSet.Stock))
                {
                    var log = new UserLogTableAdapter();
                    log.Insert(TypeUtil.Stock, StockID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_CREATE, DateTime.Now);


                    DialogResult = DialogUtil.SaveSuccess();
                }
                else
                {
                    DialogResult = DialogUtil.SaveError();
                }
            }
            else
            {
                StockID = (int)stockTableAdapter.InsertQuery(tbxSuppliesName.Text, Convert.ToDouble(tbxUnit.Text), Convert.ToByte(cbxSuppliesType.SelectedValue), tbxDescription.Text);

                if (StockID > 0)
                {
                    var log = new UserLogTableAdapter();
                    log.Insert(TypeUtil.Stock, StockID.ToString(), MainForm.User.UserID, 0, DateTime.Now);

                    DialogResult = DialogUtil.AddSuccess();
                }
                else
                {
                    DialogResult = DialogUtil.AddError();
                }
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!this.ValidateChildren())
            {
                return;
            }


            if (GeneID != 0)
            {
                this.geneBindingSource.EndEdit();
                if (1 == this.geneTableAdapter.Update(this.farmManageDataSet.Gene))
                {
                    UserLogTableAdapter logTableAdapter = new UserLogTableAdapter();
                    logTableAdapter.Insert(TypeUtil.Gene, GeneID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_MODIFY, DateTime.Now);

                    this.DialogResult = DialogUtil.SaveSuccess();
                }
                else
                {
                    this.DialogResult = DialogUtil.SaveError();
                }
            }
            else
            {
                GeneID = (int)this.geneTableAdapter.InsertQuery(this.tbxName.Text.Trim(), this.tbxNatural.Text.Trim());
                if (GeneID > 0)
                {
                    UserLogTableAdapter logTableAdapter = new UserLogTableAdapter();
                    logTableAdapter.Insert(TypeUtil.Gene, GeneID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_CREATE, DateTime.Now);

                    this.DialogResult = DialogUtil.AddSuccess();
                }
                else
                {
                    this.DialogResult = DialogUtil.AddError();
                }
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!this.ValidateChildren())
            {
                return;
            }

            CompanyTableAdapter companyTableAdapter = new CompanyTableAdapter();

            CompanyID = (int)companyTableAdapter.InsertQuery(this.tbxName.Text.Trim());
            if (CompanyID > 0)
            {
                UserLogTableAdapter logTableAdapter = new UserLogTableAdapter();
                logTableAdapter.Insert(TypeUtil.Gene, CompanyID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_CREATE, DateTime.Now);

                this.DialogResult = DialogUtil.AddSuccess();
            }
            else
            {
                this.DialogResult = DialogUtil.AddError();
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateChildren())
            {
                return;
            }


            foreach (DataGridViewRow row in this.dgvAdd.Rows)
            {
                if (row.Cells[0].Value == null || row.Cells[1].Value == null)
                {
                    MessageBox.Show("ป้อนข้อมูลไม่ครบ", "ข้อผิดผลาด", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            if (RecipesID == 0)
            {
                RecipesID = (int)this.recipesTableAdapter.InsertQuery(tbxName.Text, tbxDescription.Text);
                if (RecipesID > 0)
                {
                    var log = new UserLogTableAdapter();
                    log.Insert(TypeUtil.Recipes, RecipesID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_CREATE, DateTime.Now);


                    RecipesID = recipesTableAdapter.GetMaxID().Value;
                    foreach (DataGridViewRow row in this.dgvAdd.Rows)
                    {
                        Int32  StockID = Convert.ToInt32(row.Cells[0].Value);
                        Double Unit    = Convert.ToDouble(row.Cells[1].Value);
                        this.recipesListTableAdapter.Insert(RecipesID, StockID, Unit);
                    }

                    this.DialogResult = DialogUtil.AddSuccess();
                }
                else
                {
                    this.DialogResult = DialogUtil.AddError();
                }
            }
            else
            {
                this.Validate();
                this.recipesBindingSource.EndEdit();
                this.fKrecipeslistrecipesBindingSource.EndEdit();
                this.recipesTableAdapter.Update(farmManageDataSet.Recipes);
                this.recipesListTableAdapter.Update(farmManageDataSet.RecipesList);

                foreach (DataGridViewRow row in this.dgvAdd.Rows)
                {
                    Int32  StockID = Convert.ToInt32(row.Cells[0].Value);
                    Double Unit    = Convert.ToDouble(row.Cells[1].Value);
                    this.recipesListTableAdapter.Insert(RecipesID, StockID, Unit);
                }

                var log = new UserLogTableAdapter();
                log.Insert(TypeUtil.Recipes, RecipesID.ToString(), MainForm.User.UserID, 1, DateTime.Now);


                //if (result == 1)
                //{

                //    this.recipesListTableAdapter.Update(farmManageDataSet.RecipesList);


                //    foreach (DataGridViewRow row in this.dgvAdd.Rows)
                //    {
                //        Int32 StockID = Convert.ToInt32(row.Cells[0].Value);
                //        Double Unit = Convert.ToDouble(row.Cells[1].Value);
                //        this.recipesListTableAdapter.Insert(RecipesID, StockID, Unit);
                //    }

                DialogUtil.SaveSuccess();
                this.DialogResult = DialogResult.Yes;
                //}
                //else
                //{
                //    DialogUtil.SaveError();
                //    this.DialogResult = DialogResult.No;
                //}
            }
        }
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            if (Convert.ToDouble(tbxPercen.Text) == 0D)
            {
                MessageBox.Show("จำเป็นต้องเลือกอัตราคำนวน มากกว่า 0", "ข้อผิดผลาด", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }



            int ByID = Convert.ToInt32(cbxBy.SelectedValue);

            RecipesID = Convert.ToInt32(cbxRecipse.SelectedValue);
            if (RecipesID == 0)
            {
                MessageBox.Show("คุณยังไม่ได้เลือกสูตรอาหาร กรุณาเลือกสูตรอาหารก่อน", "ข้อผิดผลาด", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            var RecipesListRows = new RecipesListTableAdapter().GetDataByRecipesID(RecipesID);


            var msg = new StringBuilder();

            foreach (FarmManageDataSet.RecipesListRow row in RecipesListRows.Rows)
            {
                var unit      = (row.Unit * Double.Parse(tbxPercen.Text)) / 100;
                var StockRows = stockTableAdapter.GetDataByPK(row.StockID);
                if (StockRows.Count == 0)
                {
                    MessageBox.Show("ไม่พบพัสดุที่ต้องการจะหัก หรือพัสดุนั้นถูกลบออกจากระบบแล้วกรุนาตรวจสอบใหม่อีกครั้ง <br/>ID:" + row.StockID, "ข้อผิดผลาด", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (unit > StockRows[0].Unit)
                {
                    msg.Append(String.Format("พัสดุชื่อ {0} มีจำนวนไม่พอที่หัก จำนวนปัจจุบัน:{1} จำนวนที่ต้องการหัก:{2}<br>", StockRows[0].Name, StockRows[0].Unit, unit));
                }
            }
            if (msg.Length != 0)
            {
                MessageBox.Show(msg.ToString(), "ข้อผิดผลาด", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var RecipesHistoryID = (int)this.recipesHistoryTableAdapter.InsertQuery(
                Convert.ToInt32(cbxBy.SelectedValue),
                RecipesID,
                dtpDate.Value,
                Convert.ToInt32(tbxPercen.Text));

            if (RecipesHistoryID > 0)
            {
                var log = new UserLogTableAdapter();
                log.Insert(TypeUtil.RecipesHistory, RecipesHistoryID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_CREATE, DateTime.Now);

                foreach (FarmManageDataSet.RecipesListRow row in RecipesListRows.Rows)
                {
                    var Unit = (row.Unit * Double.Parse(tbxPercen.Text)) / 100;
                    int RecipesListHistoryID = (int)recipesListHistoryTableAdapter.InsertQuery(RecipesHistoryID, row.StockID, Unit);
                    if (RecipesListHistoryID > 0)
                    {
                        log.Insert(TypeUtil.RecipesListHistory, RecipesListHistoryID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_CREATE, DateTime.Now);

                        int StockRemoveID = (int)this.stockRemoveTableAdapter.InsertQuery(
                            ByID,
                            dtpDate.Value,
                            3,
                            RecipesHistoryID.ToString());

                        if (StockRemoveID > 0)
                        {
                            log.Insert(TypeUtil.StockRemove, StockRemoveID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_CREATE, DateTime.Now);

                            var StockRemoveListID = (int)new StockRemoveListTableAdapter().InsertQuery(StockRemoveID, row.StockID, Unit, null);
                            if (StockRemoveListID > 0)
                            {
                                this.stockTableAdapter.UpdateRemoveUnit(Unit, row.StockID);
                                log.Insert(TypeUtil.StockRemoveList, StockRemoveListID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_CREATE, DateTime.Now);
                            }
                        }
                    }
                }
                DialogResult = DialogUtil.AddSuccess();
            }
            else
            {
                DialogResult = DialogUtil.AddError();
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateChildren())
            {
                return;
            }


            var Stocks = new Dictionary <Int32, Double>();

            foreach (DataGridViewRow row in dgvAdd.Rows)
            {
                var StockID = Convert.ToInt32(row.Cells["StockID"].Value);
                var Unit    = Convert.ToDouble(row.Cells["Unit"].Value);
                if (Stocks.ContainsKey(StockID))
                {
                    Stocks[StockID] += Unit;
                }
                else
                {
                    Stocks.Add(StockID, Unit);
                }
            }

            var Msg = new StringBuilder();

            foreach (KeyValuePair <Int32, Double> Stock in Stocks)
            {
                var CurrentUnit = this.stockTableAdapter.QueryCurrentUnit(Stock.Key);
                if (CurrentUnit < Stock.Value)
                {
                    Msg.Append(String.Format("{0} จำนวนปัจจุบัน:{1} จำนวนที่ต้องการ:{2}\n", stockTableAdapter.GetDataByPK(Stock.Key)[0].Name, CurrentUnit, Stock.Value));
                }
            }

            if (Msg.Length != 0)
            {
                MessageBox.Show(String.Format("พัสดุไม่พอ \n{0}\n กรุณาลองใหม่อีกครั้ง", Msg), "ข้อผิดผลาด", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (DiseaseHistoryID == 0)
            {
                DiseaseHistoryID = (int)this.diseaseHistoryTableAdapter.InsertQuery(
                    Convert.ToInt32(this.cbxBy.SelectedValue),
                    CowNO,
                    this.dtpDate.Value,
                    this.tbxSymptom.Text,
                    this.tbxTreatment.Text);

                if (DiseaseHistoryID > 0)
                {
                    var log = new UserLogTableAdapter();
                    log.Insert(TypeUtil.DiseaseHistory, DiseaseHistoryID.ToString(), MainForm.User.UserID, 0, DateTime.Now);


                    var StockRemoveID     = 0;
                    var stockRemoveResult = 0;
                    if (dgvAdd.Rows.Count > 0)
                    {
                        var stockRemoveTableAdapter = new StockRemoveTableAdapter();
                        StockRemoveID = (int)stockRemoveTableAdapter.InsertQuery(
                            Convert.ToInt32(dgvAdd.Rows[0].Cells["ByID"].Value),
                            (DateTime)dgvAdd.Rows[0].Cells["Date"].Value,
                            2,
                            CowNO);

                        userLogTableAdapter.Insert(TypeUtil.StockRemove, StockRemoveID.ToString(), MainForm.User.UserID, 0, DateTime.Now);
                    }

                    var stockRemoveListTableAdapter = new StockRemoveListTableAdapter();
                    foreach (DataGridViewRow row in dgvAdd.Rows)
                    {
                        int DiseaseMedicine = (int)diseaseMedicineTableAdapter.InsertQuery(
                            Convert.ToInt32(row.Cells["ByID"].Value),
                            DiseaseHistoryID,
                            Convert.ToInt32(row.Cells["StockID"].Value),
                            Convert.ToDouble(row.Cells["Unit"].Value),
                            (DateTime)row.Cells["Date"].Value);
                        if (DiseaseMedicine > 0)
                        {
                            log.Insert(TypeUtil.DiseaseMedicine, DiseaseMedicine.ToString(), MainForm.User.UserID, 0, DateTime.Now);

                            this.stockTableAdapter.UpdateRemoveUnit(Convert.ToDouble(row.Cells["Unit"].Value), Convert.ToInt32(row.Cells["StockID"].Value));
                            if (stockRemoveResult == 1)
                            {
                                stockRemoveListTableAdapter.Insert(StockRemoveID, Convert.ToInt32(row.Cells["StockID"].Value), Convert.ToDouble(row.Cells["Unit"].Value), null);
                            }
                        }
                    }
                    DialogResult = DialogUtil.AddSuccess();
                }
                else
                {
                    DialogResult = DialogUtil.AddError();
                }
            }
            else
            {
                var StockRemoveID = 0;
                if (dgvAdd.Rows.Count > 0)
                {
                    var stockRemoveTableAdapter = new StockRemoveTableAdapter();
                    StockRemoveID = (int)stockRemoveTableAdapter.InsertQuery(
                        Convert.ToInt32(dgvAdd.Rows[0].Cells["ByID"].Value),
                        (DateTime)dgvAdd.Rows[0].Cells["Date"].Value,
                        2,
                        CowNO);

                    userLogTableAdapter.Insert(TypeUtil.StockRemove, StockRemoveID.ToString(), MainForm.User.UserID, 0, DateTime.Now);
                }

                var stockRemoveListTableAdapter = new StockRemoveListTableAdapter();
                foreach (DataGridViewRow row in dgvAdd.Rows)
                {
                    int DiseaseMedicine = (int)diseaseMedicineTableAdapter.InsertQuery(
                        Convert.ToInt32(row.Cells["ByID"].Value),
                        DiseaseHistoryID,
                        Convert.ToInt32(row.Cells["StockID"].Value),
                        Convert.ToDouble(row.Cells["Unit"].Value),
                        (DateTime)row.Cells["Date"].Value);
                    if (DiseaseMedicine < 0)
                    {
                        stockTableAdapter.UpdateRemoveUnit(Convert.ToDouble(row.Cells["Unit"].Value), Convert.ToInt32(row.Cells["StockID"].Value));
                        if (StockRemoveID > 0)
                        {
                            stockRemoveListTableAdapter.Insert(StockRemoveID, Convert.ToInt32(row.Cells["StockID"].Value), Convert.ToDouble(row.Cells["Unit"].Value), null);
                        }
                    }
                }

                var log = new UserLogTableAdapter();
                log.Insert(TypeUtil.DiseaseHistory, DiseaseHistoryID.ToString(), MainForm.User.UserID, 1, DateTime.Now);

                DialogResult = DialogUtil.SaveSuccess();
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (OrderInID > 0)
            {
                this.Validate();
                this.bornViewBindingSource.EndEdit();
                this.fKCowOrderIn1BindingSource.EndEdit();
                Int32 result = this.bornViewTableAdapter.Update(this.farmManageDataSet.BornView);

                if (result == 1)
                {
                    this.DialogResult = DialogUtil.SaveSuccess();
                }
                else
                {
                    this.DialogResult = DialogUtil.SaveError();
                }
            }
            else
            {
                OrderInID = (int)this.bornViewTableAdapter.InsertQuery(
                    (byte?)2,
                    Convert.ToInt32(this.cbxBy.SelectedValue),
                    this.dtpDate.Value,
                    this.tbxDescription.Text);

                if (OrderInID > 0)
                {
                    var log = new UserLogTableAdapter();
                    log.Insert(TypeUtil.OrderIn, OrderInID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_CREATE, DateTime.Now);


                    foreach (DataGridViewRow row in this.dgvCowAdd.Rows)
                    {
                        Int32  tCorralID = Convert.ToInt32(row.Cells["colCorral"].Value);
                        Int32  tGeneID   = Convert.ToInt32(row.Cells["colGene"].Value);
                        Byte   tSexlID   = Convert.ToByte(row.Cells["colSex"].Value);
                        String tDesc     = row.Cells["colDescription"].Value.ToString();
                        String CowNO     = String.Format("{0:000}-{1:000}", OrderInID, Convert.ToInt32(row.Cells["colID"].Value));


                        CowNO = (String)this.cowTableAdapter.InsertQuery(
                            CowNO,
                            tCorralID,
                            tGeneID,
                            tSexlID,
                            tDesc,
                            OrderInID,
                            0.0,
                            new Int32?(),
                            new Double?());

                        if (CowNO != null)
                        {
                            log.Insert(TypeUtil.Cow, CowNO, MainForm.User.UserID, TypeUtil.EVENT_BORN, DateTime.Now);
                            this.corralTableAdapter.UpdateAddCurrent(1, tCorralID);
                        }
                    }

                    this.DialogResult = DialogUtil.AddSuccess();
                }
                else
                {
                    this.DialogResult = DialogUtil.AddError();
                }
            }
        }