private bool SaveExchangeSpares(ServiceStatus status, Exchangepartheader exchH, Serviceheader serH, DataTable spareList, long totalFee)
    {
        WarrantyContentErrorCode err = WarrantyContentErrorCode.OK;
        _exchSaved = false;

        // check for any exchange spares exist
        // ret true if no one to save
        if ((exchH == null) || (spareList == null) || (spareList.Rows.Count < 1)) return true;

        // save header
        for (int i = 0; i < 5; i++) // try 5 time to ensure
        {
            err = AddExchange.SaveExchHeader(status, UserHelper.AreaCode, CurrentDealer, exchH, serH, totalFee);
            if (err == WarrantyContentErrorCode.OK) break;
        }
        if (err != WarrantyContentErrorCode.OK) { AddError(err); return false; }

        // save detail
        err = AddExchange.SaveExchDetails(spareList, exchH);
        if (err != WarrantyContentErrorCode.OK) { AddError(err); return false; }

        _exchSaved = true;
        return true;
    }
    private void ShowServiceSheet(bool readOnly, Serviceheader serH)
    {
        _finish = readOnly;
        readOnlyForm = readOnly;
        AddExchange1.readOnlyMode = readOnly;

        if (serH != null)
        {
            //_exchangeHeader = RepairListDataSource.GetExchangeHeaderFromServiceSheet(serH.Id);

            #region header section
            // warranty info
            // WarrantyInfo warrInfo = ServiceTools.GetWarrantyInfo(serH.Enginenumber);

            _sVehileColor = serH.Colorcode;
            _sVehicleDealer = serH.Dealercode;
            _sVehicleType = serH.Itemtype;
            _feeAmount = serH.Feeamount.ToString();

            txtSheetNo.Text = serH.Servicesheetnumber;
            txtEngineNo.Text = serH.Enginenumber;

            txtErrorStatus.Text = serH.Damaged;
            txtRepair.Text = serH.Repairresult;

            viewmodeDealer = serH.Dealercode;
            if (ListContainsValue(ddlDealer.Items, viewmodeDealer)) ddlDealer.SelectedValue = viewmodeDealer;
            else ddlDealer.Items.Clear();
            GetBranchs();

            btnCheck_Click(null, null); // donot clear
            EnableButtonAfterCheck(true, true);

            // service type
            bool maint = false, rep = false, warr = false;
            switch ((ServiceType)serH.Servicetype)
            {
                case ServiceType.Repair: rep = true; break;
                case ServiceType.Warranty: warr = true; break;
                case ServiceType.Maintain: maint = true; break;
                case ServiceType.MaintainAndRepair: maint = true; rep = true; break;
                case ServiceType.MaintainAndWarranty: maint = true; warr = true; break;
                case ServiceType.WarrantyAndRepair: warr = true; rep = true; break;
                case ServiceType.RepairAndMaintainAndWarranty: maint = true; rep = true; warr = true; break;
            }
            chblSerList.Items[0].Selected = maint; chblSerList.Items[1].Selected = rep; chblSerList.Items[2].Selected = warr;
            #endregion

            gvSpareList.DataSourceTable.Rows.Clear();

            #region repair section
            _feeAmount = serH.Feeamount.ToString();

            // service detail: spares
            RepairListDataSource ds = new RepairListDataSource();
            ArrayList serDs = ds.GetServiceDetails(serH.Id);
            for (int i = 0; i < serDs.Count; i++)
            {
                Servicedetail serD = (Servicedetail)serDs[i];
                DataRow row = gvSpareList.DataSourceTable.NewRow();
                Warrantycondition spareInfo = WarrantyContent.GetWarrantyCondition(serD.Partcode);

                row["SpareNo"] = i + 1;
                row["SpareNumber"] = serD.Partcode;
                row["Quantity"] = serD.Partqty;
                row["SpareCost"] = serD.Unitprice;
                row["IsExchangeSpare"] = string.Empty;
                row["ItemId"] = serD.Id;

                if (spareInfo != null)
                {
                    row["SpareNameEn"] = spareInfo.Partnameen;
                    row["SpareNameVn"] = spareInfo.Partnamevn;
                    row["SpareName"] = (Thread.CurrentThread.CurrentCulture.Name == "vi-VN") ? spareInfo.Partnamevn : spareInfo.Partnameen;
                }
                else
                {
                    row["SpareNameEn"] = serD.Partname;
                    row["SpareNameVn"] = serD.Partname;
                    row["SpareName"] = serD.Partname;
                }

                CalculateAmount(row, null);
                gvSpareList.DataSourceTable.Rows.Add(row);
            }
            #endregion

            #region exchangeSection
            if (ds == null) ds = new RepairListDataSource();
            Exchangepartheader exch = ds.GetExchangeHeader(serH.Id);
            _exchangeHeader = exch;
            if (exch != null)
            {
                AddExchange1.ExchangeHeader = _exchangeHeader;
                AddExchange1.InitUC();
                AddExchange1.SpareList.Rows.Clear();

                ArrayList exchDs = ds.GetExchangeDetails(exch.Id);
                AddExchange1.RawSpareList = AddExchange.SpareListOnServiceSchema;

                for (int i = 0; i < exchDs.Count; i++)
                {
                    Exchangepartdetail exchD = (Exchangepartdetail)exchDs[i];
                    Warrantycondition spareInfo = WarrantyContent.GetWarrantyCondition(exchD.Partcodem);

                    #region Display on SRS
                    DataRow row = gvSpareList.DataSourceTable.NewRow();
                    row["SpareNo"] = i + 1;
                    row["SpareNumber"] = exchD.Partcodem;
                    row["Quantity"] = exchD.Partqtym;
                    row["SpareCost"] = exchD.Unitpricem;
                    row["ExchangeNumber"] = exch.Vouchernumber;
                    row["IsExchangeSpare"] = "true";
                    row["ItemId"] = exchD.Id;
                    if (spareInfo != null)
                    {
                        row["SpareNameEn"] = spareInfo.Partnameen;
                        row["SpareNameVn"] = spareInfo.Partnamevn;
                        row["SpareName"] = (Thread.CurrentThread.CurrentCulture.Name == "vi-VN") ? spareInfo.Partnamevn : spareInfo.Partnameen;
                    }
                    else
                    {
                        row["SpareNameEn"] = Message.DataLost;
                        row["SpareNameVn"] = Message.DataLost;
                        row["SpareName"] = Message.DataLost;
                    }

                    //_feeAmount = exch.Feeamount.ToString();
                    //CalculateAmount(row, null);
                    gvSpareList.DataSourceTable.Rows.InsertAt(row, 0);
                    #endregion

                    #region display on PCV
                    row = AddExchange1.RawSpareList.NewRow();

                    row["ItemId"] = exchD.Id;
                    row["SpareNo"] = i + 1;
                    row["SpareNumber"] = exchD.Partcodem;
                    row["Quantity"] = exchD.Partqtym;
                    row["BrokenCode"] = exchD.Broken.Brokencode;
                    row["SerialNumber"] = exchD.Serialnumber;

                    AddExchange1.AddNewItem(row);
                    AddExchange1.RawSpareList.Rows.Add(row);
                    #endregion
                }
            }
            #endregion

            CalculateTotalAmount();
            gvSpareList.DataBind();
            CheckFinish();

            // cust info n' buy date
            _custInfo = serH.Customer;
            ShowCustInfo();
            txtRepairDate.Text = (serH.Servicedate > DateTime.MinValue) ? serH.Servicedate.ToShortDateString() : "";
        }
    }
Beispiel #3
0
 public static WarrantyContentErrorCode SaveExchHeader(Exchangepartheader exchH, Serviceheader serH)
 {
     return SaveExchHeader((ServiceStatus)exchH.Status, null, null, exchH, serH, -1);
 }
Beispiel #4
0
        public static WarrantyContentErrorCode SaveExchHeader(ServiceStatus status, string area, string dealer, Exchangepartheader exchH, Serviceheader serH, long totalFee)
        {
            if (exchH == null) return WarrantyContentErrorCode.SaveExchHeaderFailed;

            IDao<Exchangepartheader, long> dao = DaoFactory.GetDao<Exchangepartheader, long>();
            //Exchangepartheader exchH = dao.GetById(eH.Id, true);
            //if (exchH == null) exchH = eH;

            try
            {
                if (serH != null) exchH.Serviceheader = serH;
                exchH.Customer = serH.Customer;
                exchH.Enginenumber = serH.Enginenumber;
                exchH.Framenumber = serH.Framenumber;
                if (!string.IsNullOrEmpty(area)) exchH.Areacode = area;
                if (!string.IsNullOrEmpty(dealer)) exchH.Dealercode = dealer;
                exchH.Status = (status != ServiceStatus.Temp) ? (int)ExchangeVoucherStatus.New : (int)ExchangeVoucherStatus.Temp;
                exchH.Vouchernumber = GenExchangeNumber(status == ServiceStatus.Temp, exchH.Dealercode);
                if (totalFee >= 0)
                {
                    exchH.Feeamount = totalFee;
                }
                exchH.Proposefeeamount = exchH.Feeamount;
                dao.SaveOrUpdateCopy(exchH);
            }
            catch { return WarrantyContentErrorCode.SaveExchHeaderFailed; }
            //exchH.Vouchernumber = exchH.Vouchernumber;

            return WarrantyContentErrorCode.OK;
        }
        public static Serviceheader SaveSerHeader(long sheetId, ServiceStatus status, string dealer, string branch, string enNum, string plateNum, string frameNum, string model, string color, string err, string solution, string exchangeNum, int serType, Customer cust, long km, long fee, long total, DateTime serDate, DateTime buyDate, out WarrantyContentErrorCode errCode)
        {
            errCode = WarrantyContentErrorCode.SaveHeaderFailed;

            if (string.IsNullOrEmpty(dealer) || string.IsNullOrEmpty(branch)) return null;

            Serviceheader serH = null;
            if (
                ((!string.IsNullOrEmpty(err.Trim()))
                && (cust != null)
                && (!string.IsNullOrEmpty(model))
                && (!string.IsNullOrEmpty(color)))
                ||
                (status < 0)
                )
            {
                IDao<Serviceheader, long> dao = DaoFactory.GetDao<Serviceheader, long>();

                serH = dao.GetById(sheetId, false); //true -> false
                if (serH == null)
                {
                    serH = new Serviceheader();
                }

                serH.Branchcode = branch;
                serH.Customer = cust;
                serH.Colorcode = color;
                serH.Damaged = err.Trim();
                serH.Dealercode = dealer;
                serH.Enginenumber = enNum.Trim().ToUpper();
                serH.Feeamount = fee;
                serH.Framenumber = frameNum;
                serH.Itemtype = model;
                serH.Kmcount = km;
                serH.Numberplate = plateNum.Trim().ToUpper();
                serH.Purchasedate = buyDate;
                serH.Repairresult = solution.Trim();
                serH.Servicedate = serDate;
                serH.Servicesheetnumber = GenSheetNumber(status == ServiceStatus.Temp, dealer);
                serH.Servicetype = serType;
                serH.Totalamount = total;
                serH.Status = (int)status;
                serH.Createby = UserHelper.Username;

                try { dao.SaveOrUpdate(serH); }
                catch { serH = null; }
            }

            errCode = WarrantyContentErrorCode.OK;
            return serH;
        }
Beispiel #6
0
 public static WarrantyContentErrorCode SaveExchHeader(string area, string dealer, Exchangepartheader exchH, Serviceheader serH, long totalFee)
 {
     return SaveExchHeader(ServiceStatus.Done, area, dealer, exchH, serH, totalFee);
 }
        public static Serviceheader SaveSerHeader(Serviceheader serH, out WarrantyContentErrorCode errCode)
        {
            errCode = WarrantyContentErrorCode.SaveHeaderFailed;

            if (string.IsNullOrEmpty(serH.Dealercode) || string.IsNullOrEmpty(serH.Branchcode)) return null;
            if (
                ((!string.IsNullOrEmpty(serH.Damaged.Trim()))
                && (serH.Customer != null)
                && (!string.IsNullOrEmpty(serH.Itemtype))
                && (!string.IsNullOrEmpty(serH.Colorcode)))
                ||
                (serH.Status < 0)
               )
            {
                IDao<Serviceheader, long> dao = DaoFactory.GetDao<Serviceheader, long>();
                serH.Servicesheetnumber = GenSheetNumber(serH.Status == (int)ServiceStatus.Temp, serH.Dealercode);
                serH.Createby = UserHelper.Username;
                try
                {
                    serH = dao.SaveOrUpdateCopy(serH);
                    errCode = WarrantyContentErrorCode.OK;
                }
                catch { serH = null; }
            }

            return serH;
        }
 public static WarrantyContentErrorCode SaveSerDetails(IList<SRSItem> serDetail, Serviceheader serH)
 {
     IDao<Servicedetail, long> dao = DaoFactory.GetDao<Servicedetail, long>();
     try
     {
         foreach (SRSItem item in serDetail)
         {
             if ((item.State == ServiceItemState.Transient) || item.HasModified || (item.Serviceheader == null) || (item.Serviceheader.Id != serH.Id))
             {
                 Servicedetail sd = item.Base();
                 if (item.State == ServiceItemState.Deleted)
                     dao.Delete(sd.Id);
                 else
                 {
                     var i = dao.SaveOrUpdateCopy(sd);
                     if (sd.Id == 0) sd.Id = i.Id;
                 }
             }
         }
     }
     catch { return WarrantyContentErrorCode.SaveDetailFailed; }
     return WarrantyContentErrorCode.OK;
 }
        public static WarrantyContentErrorCode SaveSerDetails(DataTable serDetail, Serviceheader serH)
        {
            int quantity;
            long price;
            IDao<Servicedetail, long> dao = DaoFactory.GetDao<Servicedetail, long>();

            foreach (DataRow row in serDetail.Rows)
            {
                if (string.IsNullOrEmpty(row["IsExchangeSpare"].ToString()))
                {
                    int.TryParse(row["Quantity"].ToString(), out quantity);
                    long.TryParse(row["SpareCost"].ToString(), out price);
                    if (SaveSerDetail(row["ItemId"].ToString(), row["SpareNumber"].ToString(), row["SpareName"].ToString(), quantity, price, serH, dao) != WarrantyContentErrorCode.OK) return WarrantyContentErrorCode.SaveDetailFailed;
                }
            }
            return WarrantyContentErrorCode.OK;
        }
        public static WarrantyContentErrorCode SaveSerDetail(string itemId, string partCode, string partName, int quantity, long price, Serviceheader serH, IDao<Servicedetail, long> dao)
        {
            long id;
            long.TryParse(itemId, out id);

            Servicedetail serD = dao.GetById(id, false); //true -> false
            if (serD == null)
            {
                serD = new Servicedetail();
            }

            serD.Partcode = partCode.Trim().ToUpper();
            serD.Partqty = quantity;
            serD.Serviceheader = serH;
            serD.Unitprice = price;
            serD.Partname = partName;
            try
            {
                dao.SaveOrUpdate(serD);
            }
            catch { return WarrantyContentErrorCode.SaveDetailFailed; }
            return WarrantyContentErrorCode.OK;
        }
 public static WarrantyContentErrorCode SaveSerDetail(string partCode, string partName, int quantity, long price, Serviceheader serH)
 {
     IDao<Servicedetail, long> dao = DaoFactory.GetDao<Servicedetail, long>();
     return SaveSerDetail(string.Empty, partCode, partName, quantity, price, serH, dao);
 }